Commits

Israel Saeta Pérez committed f06879d

Develop per-chapter templates and adapt the element creation script to deal with them.

  • Participants
  • Parent commits 5d10677

Comments (0)

Files changed (3)

plastex-theme/default-layout.html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
+<html tal:define="links self/links" 
+      xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
-    <title tal:content="self/title">Book Title</title>
+
     <meta name="generator" content="plasTeX" />
     <meta http-equiv="content-type"
-          tal:attributes="content string:text/html; charset=${config/files/output-encoding}" />
+          tal:attributes="content string:text/html;; charset=${config/files/output-encoding}" />
+
+    <title tal:condition="python:path('self/level') &gt; -10"
+           tal:content="stripped string:${links/document/title}: ${self/title}">
+      Book title
+    </title>
+    <link tal:condition="links/next" 
+          rel="next" 
+          tal:attributes="href links/next/url; title links/next/title/textContent" />
+    <link tal:condition="links/prev" 
+          rel="prev" 
+          tal:attributes="href links/prev/url; title links/prev/title/textContent" />
+    <link tal:condition="links/up" 
+          rel="up" 
+          tal:attributes="href links/up/url; title links/up/title/textContent" />
 
     <link rel="stylesheet" href="styles/styles.css"/>
     <link rel="stylesheet" href="/support/styles/styles.css"/>
   <body>
 
     <div class="navheader"><h2 class="booktitle">
-        <tal:booktitle replace="self/title" />
+        <tal:booktitle replace="links/document/title" />
         <div class="authors">by 
-          <tal:author tal:content="self/author">
+          <tal:author tal:content="links/document/attributes/author">
             Author
           </tal:author>
         </div>
       </h2>
     </div>
 
-    <div class="chapter" id="{% doc_id %}">
+    <div class="navheader" metal:define-macro="navigation">
+      <table width="100%">
+        <tr>
+          <td width="40%" align="left">
+            <a tal:condition="links/prev"
+               tal:attributes="href links/prev/url;
+                               title stripped:links/prev/title"
+               accesskey="p">Prev</a> </td>
+          <td width="20%" align="center"> 
+            <a tal:condition="links/up"
+               tal:attributes="href links/up/url">Up</a>
+          </td>
+          <td width="40%" align="right"> 
+            <a tal:condition="links/next"
+               tal:attributes="href links/next/url;
+                               title stripped:links/next/title"
+               accesskey="n">Next</a>
+          </td>
+        </tr>
+        <tr>
+          <td width="40%" align="left">
+            <span tal:condition="links/prev"
+               tal:replace="stripped:links/prev/title">Prev</span>
+          </td>
+          <td width="20%" align="center"> </td>
+          <td width="40%" align="right"> 
+            <span tal:condition="links/next"
+               tal:replace="stripped:links/next/title">Next</span>
+          </td>
+        </tr>
+      </table>
+    </div>
+
+    <div class="chapter" 
+         tal:attributes="id string:${links/document/title}: ${self/title}">
       
       <div class="file_contents" tal:content="self">File contents.</div>
       
+      <div tal:condition="self/tableofcontents" 
+           tal:attributes="class
+                           string:contents
+                           ${self/nodeName}-contents">
+        <ul>
+          <li tal:repeat="section self/tableofcontents"><a href="." tal:attributes="href section/url" tal:content="section/fullTocEntry">Aliquam est. Aliquam fringilla pede</a>
+            <ul tal:condition="section/tableofcontents">
+              <li tal:repeat="subsection section/tableofcontents"><a href="." tal:attributes="href subsection/url" tal:content="subsection/fullTocEntry"></a>
+                <ul tal:condition="subsection/tableofcontents">
+                  <li tal:repeat="subsubsection subsection/tableofcontents"><a href="." tal:attributes="href subsubsection/url" tal:content="subsubsection/fullTocEntry"></a>
+                    <ul tal:condition="subsubsection/tableofcontents">
+                      <li tal:repeat="paragraph subsubsection/tableofcontents"><a href="." tal:attributes="href paragraph/url" tal:content="paragraph/fullTocEntry"></a>
+                        <ul tal:condition="paragraph/tableofcontents">
+                          <li tal:repeat="subparagraph paragraph/tableofcontents"><a href="." tal:attributes="href subparagraph/url" tal:content="subparagraph/fullTocEntry"></a></li>
+                        </ul>
+                      </li>
+                    </ul>
+                  </li>
+                </ul>
+              </li>
+            </ul>
+          </li>
+          <li tal:replace="nothing"><a href=".">Maecenas id purus</a></li>
+        </ul>
+      </div>
+
+
       <div id="footnotes" tal:condition="self/footnotes">
         <p><b>Footnotes</b></p>
         <ol>
 	  href="http://mattahan.deviantart.com/">Mattahan</a>.</p>
       </div>
 
+      <div class="navfooter"
+	   metal:use-macro="template/macros/navigation" />
   </body>
 
   <script language="javascript" src="icons/imgadjust.js"

web/hgbook/comments/models.py

 class Element(models.Model):
     id = models.CharField('ID attribute', max_length=64, editable=False,
                           primary_key=True)
-    chapter = models.CharField('Chapter ID', max_length=64, editable=False,
+    chapter = models.CharField('Chapter ID', max_length=100, editable=False,
                                db_index=True)
     title = models.CharField('Section title', max_length=256, editable=False)
 

web/hgbook/converter.py

 from comments.models import Element
 
 doc_id = 'MMSC'
-sel = CSSSelector('p, pre, h1, table.equation')
-body = CSSSelector('body')
+sel = CSSSelector('div.chapter p, pre, h1, table.equation')
+chapter_sel = CSSSelector('div.chapter')
 
 try:
     filename = args[0]
 tree = etree.parse(filename, html.HTMLParser(remove_blank_text=True))
 root = tree.getroot()
 
-body(root)[0].set('id', doc_id)
+chapter = chapter_sel(root)[0]
+chapter_title = chapter.get('id').split(':')[1]
+chapter_hash = md5.new(chapter.get('id').encode('utf8')).hexdigest()
+
+chapter.set('id', chapter_hash)
 
 for element in sel(root):
     hsh_source = element.text or element.get('alt') or etree.tostring(element)
     if hsh_source:
         hsh_source_encoded = hsh_source.encode('utf8')
         hsh = md5.new(hsh_source_encoded).hexdigest()
-        element.set('id', '%s-%s' % (doc_id, hsh))
+        element.set('id', '%s-%s' % (chapter_hash, hsh))
     
         # create the commentable element in the DB
         e = Element()
-        e.id = '%s-%s' % (doc_id, hsh)
-        e.chapter = doc_id
-        e.title = hsh
+        e.id = '%s-%s' % (chapter_hash, hsh)
+        e.chapter = chapter_hash
+        e.title = chapter_title
         e.save()