Client-side XSLT renderer prototype.
authorLukasz Rekucki <lrekucki@gmail.com>
Mon, 2 Nov 2009 22:54:12 +0000 (23:54 +0100)
committerLukasz Rekucki <lrekucki@gmail.com>
Mon, 2 Nov 2009 22:54:12 +0000 (23:54 +0100)
apps/api/handlers/library_handlers.py
apps/explorer/views.py [changed mode: 0644->0755]
platforma/static/js/views/html.js
platforma/static/xsl/wl2html_client.xsl [new file with mode: 0755]
platforma/templates/base.html [changed mode: 0644->0755]
platforma/templates/renderer.html [new file with mode: 0755]
platforma/urls.py [changed mode: 0644->0755]

index f97ff6c..27ff47d 100755 (executable)
@@ -21,7 +21,7 @@ import librarian.html
 import difflib
 from librarian import dcparser, parser
 
-from wlrepo import *
+import wlrepo
 from api.models import PullRequest
 from explorer.models import GalleryForDocument
 
@@ -157,7 +157,7 @@ class LibraryHandler(BaseHandler):
                     import traceback
                     # rollback branch creation
                     lib._rollback()
-                    raise LibraryException(traceback.format_exc())
+                    raise wlrepo.LibraryException(traceback.format_exc())
 
                 url = reverse('document_view', args=[doc.id])
 
@@ -169,12 +169,12 @@ class LibraryHandler(BaseHandler):
                     url = url )            
             finally:
                 lock.release()
-        except LibraryException, e:
+        except wlrepo.LibraryException, e:
             import traceback
             return response.InternalError().django_response({
                 "reason": traceback.format_exc()
             })
-        except DocumentAlreadyExists:
+        except wlrepo.DocumentAlreadyExists:
             # Document is already there
             return response.EntityConflict().django_response({
                 "reason": "already-exists",
@@ -191,7 +191,7 @@ class BasicDocumentHandler(AnonymousBaseHandler):
     def read(self, request, docid, lib):
         try:    
             doc = lib.document(docid)
-        except RevisionNotFound:
+        except wlrepo.RevisionNotFound:
             return rc.NOT_FOUND
 
         result = {
@@ -250,7 +250,7 @@ class DocumentHandler(BaseHandler):
             
         try:
             doc = lib.document(docid, user, rev=rev)
-        except RevisionMismatch, e:
+        except wlrepo.RevisionMismatch, e:
             # the document exists, but the revision is bad
             return response.EntityNotFound().django_response({
                 'reason': 'revision-mismatch',
@@ -258,7 +258,7 @@ class DocumentHandler(BaseHandler):
                 'docid': docid,
                 'user': user,
             })
-        except RevisionNotFound, e:
+        except wlrepo.RevisionNotFound, e:
             # the user doesn't have this document checked out
             # or some other weird error occured
             # try to do the checkout
@@ -278,7 +278,7 @@ class DocumentHandler(BaseHandler):
                         'docid': docid,
                         'user': user,
                     })
-            except RevisionNotFound, e:
+            except wlrepo.RevisionNotFound, e:
                 return response.EntityNotFound().django_response({
                     'reason': 'document-not-found',
                     'message': e.message,
@@ -341,7 +341,7 @@ class DocumentHTMLHandler(BaseHandler):
                     "with-paths": 'boolean(1)',                    
                 })
                 
-        except (EntryNotFound, RevisionNotFound), e:
+        except (wlrepo.EntryNotFound, wlrepo.RevisionNotFound), e:
             return response.EntityNotFound().django_response({
                 'reason': 'not-found', 'message': e.message})
         except librarian.ValidationError, e:
old mode 100644 (file)
new mode 100755 (executable)
index 2c9b17d..46cdd4e
@@ -116,3 +116,11 @@ def pull_requests(request):
 
     return direct_to_template(request, 'manager/pull_request.html', 
         extra_context = {'objects': objects} )
+
+
+#
+# Testing
+#
+def renderer_test(request):
+    return direct_to_template(request, 'renderer.html', mimetype="text/html",
+        extra_context = {} )
\ No newline at end of file
index e1c7b15..cefd0d2 100755 (executable)
@@ -328,10 +328,8 @@ var HTMLView = View.extend({
             var random = Math.floor(4000000000*Math.random());
             var id = (''+date) + '-' + (''+random);
 
-            var ipoint = document.createRange();
+            var ipoint = document.createRange();            
             
-            
-
             // Firefox alters the later node when inserting, so
             // insert from end
             ipoint.setStart(range.endContainer, range.endOffset);
diff --git a/platforma/static/xsl/wl2html_client.xsl b/platforma/static/xsl/wl2html_client.xsl
new file mode 100755 (executable)
index 0000000..85ff4a3
--- /dev/null
@@ -0,0 +1,591 @@
+<xsl:stylesheet version="1.0"    
+    xmlns="http://www.w3.org/1999/xhtml"    
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+    <!--
+        Dokument ten opisuje jednoznaczne przekształcenie WLML 0.1 -> XHTML.
+    -->        
+    <xsl:output method="html" encoding="utf-8" indent="yes" />
+
+    <xsl:template match="/">
+        <xsl:apply-templates select="chunk|utwor" />
+    </xsl:template>
+
+    <!--
+        Base tag for rendering a fragment of text
+    -->
+    <xsl:template match="chunk">        
+        <xsl:apply-templates select="child::node()">            
+            <xsl:with-param name="mixed" select="true()" />
+        </xsl:apply-templates>        
+    </xsl:template>
+    
+    <!--
+        Base tag for rendering the whole text 
+    -->
+
+    <!-- TODO -->
+
+    
+    
+    <!-- 
+        Przekształcenia poszczególnych elementów zgodnie z:            
+        http://wiki.wolnepodreczniki.pl/Lektury:Sk%C5%82ad/Tagi_sk%C5%82adu
+    -->
+
+    <!-- TAGI MASTERÓW STYLÓW
+    
+        Tagi rozpoczynające i kończące tekst utworu lirycznego o standardowej szerokości łamu:
+    -->
+
+    <xsl:template match="liryka_l">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <!-- 
+        *****************************
+        ELEMENTY POZA TEKSTEM GŁÓWNYM
+        *****************************
+    -->
+
+    <!--
+        Autor składanego utworu
+
+        Element strony tytułowej - lub odpowiadającej jej przestrzeni,
+        np. na stronie internetowej) :
+
+        <autor_utworu> imiona-itd.-autora-składanego-utworu </autor_utworu>
+    -->
+    <xsl:template match="autor_utworu">
+        <xsl:param name="mixed" />
+        <h2 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h2>
+    </xsl:template>
+
+    <!-- 
+        Nazwa składanego utworu
+
+        Element strony tytułowej - lub odpowiadającej jej przestrzeni,
+        np. na stronie internetowej
+
+        <nazwa_utworu> tytuł-składanego-utworu </nazwa_utworu>
+    -->
+    <xsl:template match="nazwa_utworu">
+        <xsl:param name="mixed" />
+        <h1 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h1>
+    </xsl:template>
+
+    <!--
+        Nazwa utworu nadrzędnego, w którego skład wchodzi dany utwór
+        <dzielo_nadrzedne> tytuł-dzieła-nadrzędnego </dzielo_nadrzedne>
+
+         Przykład:
+
+         <utwor>
+         <liryka_l>
+            <autor_utworu>Bruno Jasieński</autor_utworu>
+            <dzielo_nadrzedne>But w butonierce</dzielo_nadrzedne>
+            <nazwa_utworu>Deszcz</nazwa_utworu>
+            ....
+    -->
+    <xsl:template match="dzielo_nadrzedne">
+        <xsl:param name="mixed" />
+        <h2 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h2>
+    </xsl:template>
+
+    <!--
+        Podtytuł, czyli wszystkie dopiski do tytułu
+
+        Element strony tytułowej - lub odpowiadającej jej przestrzeni.
+        <podtytul> podtytuł-składanego-utworu </podtytul>
+
+        Przykład:
+        <utwor>
+            <powiesc>
+            <autor_utworu>Daniel Defoe</autor_utworu>
+            <nazwa_utworu>Robinson Crusoe</nazwa_utworu>
+            <podtytul>Jego życia losy, doświadczenia i przypadki</podtytul>
+            ...
+    -->
+    <xsl:template match="podtytul">
+        <xsl:param name="mixed" />
+        <h3 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h3>
+    </xsl:template>
+
+    <!--
+       Tagi obejmujące tekst noty poprzedzającej tekst główny (styl wieloakapitowy):
+
+        <nota><akap> tekst-noty </akap></nota> (styl wieloakapitowy)
+    -->
+
+    <xsl:template match="nota">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <!--
+        Tagi obejmujące tekst dedykacji (styl wieloakapitowy bądź wielostrofowy):
+        <dedykacja> tekst-dedykacji </dedykacja>
+    -->
+    <xsl:template match="dedykacja">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <!--
+        Tagi obejmujące tekst motta (styl wieloakapitowy bądź wielostrofowy):
+        <motto> tekst-motta </motto>
+    -->
+    <xsl:template match="motto">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="motto_podpis">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+    <!--
+        Tagi obejmujące listę osób poprzedzającą tekst dramatu
+          (zwykle składaną na osobnej stronie; to odmiana stylu listy):
+
+        <lista_osob> osoby </lista_osob>
+    -->
+    <xsl:template match="lista_osob">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="naglowek_listy">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+    <xsl:template match="lista_osoba">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+
+    <!--
+        ***************************
+        TAGI STYLÓW TEKSTU GŁÓWNEGO
+        ***************************
+    -->
+
+    <!--
+      Tagi nagłówka części/księgi:
+      <naglowek_czesc> nagłówek-części-lub-księgi </naglowek_czesc>
+    -->
+    <xsl:template match="naglowek_czesc">
+        <xsl:param name="mixed" />
+        <h2 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h2>
+    </xsl:template>
+
+    <!--
+      Tagi tytułu rozdziału:
+      <naglowek_rozdzial> nr-i/lub-tytuł </naglowek_rozdzial>
+    -->
+    <xsl:template match="naglowek_rozdzial">
+        <xsl:param name="mixed" />
+        <h3 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h3>
+    </xsl:template>
+
+    <!--
+      Tagi tytułu podrozdziału:
+      <naglowek_podrozdzial> nr-i/lub-podtytuł </naglowek_podrozdzial>
+    -->
+    <xsl:template match="naglowek_podrozdzial">
+        <xsl:param name="mixed" />
+        <h4 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h4>
+    </xsl:template>
+
+    <!--
+       Tagi sródtytułu:
+       <srodtytul> śródtytuł </srodtytul>
+
+       Tagi nagłówków aktów:
+       <naglowek_akt> nagłówek-aktu </naglowek_akt>
+    -->
+
+    <xsl:template match="srodtytul">
+        <xsl:param name="mixed" />
+        <h2 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h2>
+    </xsl:template>
+
+    <xsl:template match="naglowek_akt">
+        <xsl:param name="mixed" />
+        <h2 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h2>
+    </xsl:template>
+
+    <!--
+      Tagi nagłówków scen:
+      <naglowek_scena> nagłówek-sceny </naglowek_scena>
+    -->
+
+    <xsl:template match="naglowek_scena">
+        <xsl:param name="mixed" />
+        <h3 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h3>
+    </xsl:template>
+    
+    <xsl:template match="naglowek_osoba">
+        <xsl:param name="mixed" />
+        <h4 class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </h4>
+    </xsl:template>
+
+    <!--
+       ************************
+       Bloki w tekście głównym
+       ************************
+    -->
+    
+    <xsl:template match="dlugi_cytat">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+    
+    <xsl:template match="poezja_cyt">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="kwestia">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="didaskalia">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="wywiad_pyt">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <xsl:template match="wywiad_odp">
+        <xsl:param name="mixed" />
+        <div class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="false()" />
+            </xsl:apply-templates>
+        </div>
+    </xsl:template>
+
+    <!--
+        ***********************************
+        Style akapitowe oraz strofy i wersy
+        ***********************************
+    -->
+
+    <xsl:template match="akap">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+    <xsl:template match="akap_cd">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+    <xsl:template match="akap_dialog">
+        <xsl:param name="mixed" />
+        <p class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </p>
+    </xsl:template>
+
+    <!--
+        ********
+        STROFA
+        ********
+    -->
+    <xsl:template match="strofa">
+        <div class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:choose>
+                <xsl:when test="count(br) > 0">
+                    <xsl:call-template name="verse">
+                        <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::node()" />
+                        <xsl:with-param name="verse-type" select="name(br[1]/preceding-sibling::*[starts-with(name(current()),'wers')])" />
+                    </xsl:call-template>
+                    <xsl:for-each select="br">
+                       <!-- Each BR tag "consumes" text after it -->
+                        <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
+                        <xsl:call-template name="verse">
+                            <xsl:with-param name="verse-content"
+                                select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
+                            <xsl:with-param name="verse-type"
+                                select="name(following-sibling::*[count(preceding-sibling::br) = $lnum+1 and starts-with(name(current()), 'wers')][1])" />
+                        </xsl:call-template>
+                    </xsl:for-each>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:call-template name="verse">
+                        <xsl:with-param name="verse-content" select="child::node()" />
+                        <xsl:with-param name="verse-type" select="name(child::*[starts-with(name(current()),'wers')])" />
+                    </xsl:call-template>
+                </xsl:otherwise>
+            </xsl:choose>
+        </div>
+    </xsl:template>
+
+    <xsl:template name="verse">
+        <xsl:param name="verse-content" />
+        <xsl:param name="verse-type" />
+
+        <xsl:choose>
+            <xsl:when test="$verse-type = ''">
+                <p class="wers" x-node="wers">
+                <xsl:for-each select="$verse-content[name(.) != 'br']">
+                    <xsl:apply-templates select=".">
+                    <xsl:with-param name="mixed" select="true()" />
+                    </xsl:apply-templates>
+                </xsl:for-each>
+                </p>                
+            </xsl:when>
+            <xsl:otherwise>
+                <p class="{$verse-type}" x-node="{$verse-type}">
+                <xsl:for-each select="$verse-content[name(.) != 'br']">
+                <xsl:apply-templates select=".">
+                    <xsl:with-param name="mixed" select="true()" />
+                </xsl:apply-templates>
+                </xsl:for-each>
+                </p>
+            </xsl:otherwise>
+        </xsl:choose>
+        
+        
+    </xsl:template>
+    
+
+    <!--
+        *************
+        STYLE ZNAKOWE
+        *************
+    -->
+
+    <!--
+        Tagi obejmujące tytuł dzieła, np. książki, filmu, piosenki,
+        modlitwy, przedstawienia teatr. itd.:
+
+        <tytul_dziela> tytuł-dzieła </tytul_dziela>
+    -->
+    <xsl:template match="tytul_dziela">
+        <xsl:param name="mixed" />
+        <span class="{name()}" x-editable="true" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </span>
+    </xsl:template>
+
+    <xsl:template match="wyroznienie|slowo_obce|mat|didask_tekst|osoba|wyp_osoba|www">
+        <xsl:param name="mixed" />
+        <em class="{name()}" x-node="{name()}">
+            <xsl:apply-templates select="child::node()">
+                <xsl:with-param name="mixed" select="true()" />
+            </xsl:apply-templates>
+        </em>
+    </xsl:template>
+
+    <!--
+        **********
+        SEPARATORY
+        **********
+    -->
+    <xsl:template match="sekcja_swiatlo">
+        <xsl:param name="mixed" />
+        <br class="{name()}" x-node="{name()}" />
+    </xsl:template>
+
+    <xsl:template match="sekcja_asteryks">
+        <xsl:param name="mixed" />
+        <hr class="{name()}" x-node="{name()}" />
+    </xsl:template>
+
+    <xsl:template match="separator_linia">
+        <xsl:param name="mixed" />
+        <hr class="{name()}" x-node="{name()}" />
+    </xsl:template>
+
+    <xsl:template match="zastepnik_wersu">
+        <xsl:param name="mixed" />
+        <hr class="{name()}" x-node="{name()}" />
+    </xsl:template>
+
+    <!--
+        *************
+           PRZYPISY
+        *************
+    -->
+
+    <!--
+        Przypisy i motywy
+    -->
+    <xsl:template match="pr|pa|pe|pt">       
+        <span class="annotation-inline-box" x-node="{name()}">
+            <a name="anchor-{generate-id(.)}" />
+            <!-- the link to the non-inline version -->
+            <a href="#annotation-{generate-id(.)}" class="annotation"></a>
+            <!-- inline contents -->
+            <span x-annotation-box="true">
+                <xsl:apply-templates select="node()">
+                    <xsl:with-param name="mixed" select="true()" />
+                </xsl:apply-templates>
+            </span>
+        </span>
+
+    </xsl:template>
+
+    <xsl:template match="begin">
+        <xsl:variable name="id" select="substring-after(@id, 'b')" />
+        <span class="theme-begin" x-node="begin" x-theme-class="{$id}" id="{@id}"></span>
+        <xsl:apply-templates select="following-sibling::motyw[@id = concat('m', $id)]" mode="theme-begin" />
+    </xsl:template>
+
+    <xsl:template match="motyw">
+        <span class="theme-ref" x-node="motyw" x-theme-class="{substring-after(@id, 'm')}" id="{@id}">
+            <xsl:value-of select="." />
+        </span>
+    </xsl:template>
+
+
+    <xsl:template match="end">
+        <span class="theme-end" x-node="end" x-theme-class="{substring-after(@id, 'e')}" id="{@id}">
+        </span>
+    </xsl:template>
+
+
+    <!--
+        ****************
+         TEKST WŁAŚCIWY
+        ****************
+    -->
+
+    <xsl:template match="text()">
+        <xsl:param name="mixed" />
+        <xsl:choose>
+            <xsl:when test="normalize-space(.) = ''" />
+            <xsl:when test="not($mixed)">
+                <span x-node="text" class="out-of-flow-text"
+                    x-content="{normalize-space(.)}"></span>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="." />
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template match="*">
+        <div x-node="error" x-content="{name()}" />
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 590825a..50c7bfe
@@ -21,9 +21,8 @@
                </span>
         <div id="message-box">{% block message-box %} {% endblock %}</div>
        </div>
-    <div id="content">{% block maincontent %} {% endblock %}</div>
-
+        <div id="content">{% block maincontent %} {% endblock %}</div>
+        </div>
     {% block extrabody %}{% endblock %}
-       </div>
     </body>
 </html>
diff --git a/platforma/templates/renderer.html b/platforma/templates/renderer.html
new file mode 100755 (executable)
index 0000000..dabf338
--- /dev/null
@@ -0,0 +1,123 @@
+{% extends "base.html" %}\r
+\r
+{% block extrahead %}\r
+<link rel="stylesheet" href="{{STATIC_URL}}css/html.css" type="text/css" charset="utf-8">\r
+{% endblock %}\r
+\r
+{% block maincontent %}\r
+\r
+<p>Source</p>\r
+<textarea id="source" cols="80" rows="10" ></textarea>\r
+\r
+<p>Rendered</p>\r
+<textarea id="dest" cols="80" rows="10" ></textarea>\r
+\r
+<button type="button" id="render">Render</button>\r
+<button type="button" id="unrender">Unrender</button>\r
+\r
+<div style="position: fixed; right: 0px; top: 0px; width: 640px; height: 300px; background: blue;">\r
+<div id="preview" class="htmlview">\r
+</div>\r
+</div>\r
+{% endblock %}\r
+\r
+{% block extrabody %}\r
+<script type="text/javascript">\r
+\r
+    function serializeAttribute(attr, acc) {\r
+        return acc + ' ' + attr.nodeName + '="'+ attr.nodeValue + '"';\r
+    }\r
+\r
+    function serializeElement(element, acc, level)\r
+    {\r
+        var isBlock = false;\r
+\r
+        if(element.nodeName != 'span' && element.nodeName != 'p')\r
+            isBlock = true;\r
+\r
+        if(isBlock) {\r
+            for(var i=0; i < level; i++)\r
+                acc += '  ';\r
+        }\r
+        \r
+        acc += "<" + element.nodeName;\r
+        for(var i=0; i < element.attributes.length; i++)\r
+            acc = serializeAttribute(element.attributes.item(i), acc);\r
+\r
+        if(element.firstChild)\r
+        {\r
+            acc += ">\n";\r
+\r
+            if(element.firstChild)\r
+                acc = serializeNode(element.firstChild, acc, level+1);\r
+\r
+            acc += "\n";\r
+            \r
+            for(var i=0; i < level; i++)\r
+                acc += '  ';\r
+\r
+            acc += "</"+element.nodeName + ">";            \r
+        }\r
+        else {\r
+            acc += " />";\r
+        }\r
+\r
+        if(isBlock) acc += "\n";\r
+        \r
+        return acc;\r
+    }\r
+\r
+\r
+    // step-by-step serializer\r
+    function serializeNode(node, acc, level)\r
+    {\r
+        \r
+\r
+        if(node.nodeType == 11)\r
+            return serializeNode(node.firstChild, acc, level);\r
+\r
+        if(node.nodeType == 1)\r
+            acc = serializeElement(node, acc, level);\r
+        \r
+        else if(node.nodeType == 3)\r
+            acc += node.nodeValue;\r
+\r
+        if(node.nextSibling)\r
+            return serializeNode(node.nextSibling, acc, level);\r
+        else\r
+            return acc;\r
+    }\r
+\r
+    function serializeXML(element) {\r
+        return serializeNode(element, '', 0);\r
+    }\r
+\r
+    // w3c version first\r
+    var xslt = new XSLTProcessor();\r
+\r
+    $.ajax({\r
+        url: "/static/xsl/wl2html_client.xsl",\r
+        dataType: 'xml',\r
+        success: function(data) {\r
+            xslt.importStylesheet(data);\r
+            console.log('XSL loaded successfully');\r
+        },\r
+        async: false\r
+    });\r
+    \r
+    $('#render').click(function() {\r
+        \r
+        var src = '<?xml version="1.0"?><chunk>'+$('#source').val()+'</chunk>';\r
+        src = src.replace(/\/\s+/g, '<br />');\r
+        var doc = (new DOMParser()).parseFromString(src, "text/xml");\r
+        // var string = (new XMLSerializer()).serializeToString(doc);\r
+        // console.log('rendering', string);\r
+        \r
+        var result = xslt.transformToFragment(doc, document);\r
+        var string =  serializeXML(result);\r
+        var dest = $('#dest');\r
+        dest.val( string );\r
+        $('#preview').html(string);\r
+    });    \r
+</script>\r
+{% endblock %}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 786a653..8a56210
@@ -13,6 +13,8 @@ urlpatterns = patterns('',
     url(r'^$', 'explorer.views.file_list', name='file_list'),        
     url(r'^file/upload', 'explorer.views.file_upload', name='file_upload'),
 
+    url(r'^renderer$', 'explorer.views.renderer_test'),
+
     url(r'^management/pull-requests$', 'explorer.views.pull_requests'),
   
     # Editor panels
@@ -25,6 +27,8 @@ urlpatterns = patterns('',
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
     url(r'^admin/(.*)', admin.site.root),
 
+
+
     # Our über-restful api
     url(r'^api/', include('api.urls')),