hgbook
changeset 911:f06879de9b01
Develop per-chapter templates and adapt the element creation script to deal with them.
author | dukebody <dukebody@gmail.com> |
---|---|
date | Tue Oct 27 00:10:56 2009 +0100 (2009-10-27) |
parents | 5d10677c3dbd |
children | 67af12ba4e26 |
files | plastex-theme/default-layout.html web/hgbook/comments/models.py web/hgbook/converter.py |
line diff
1.1 --- a/plastex-theme/default-layout.html Mon Oct 26 21:50:49 2009 +0100 1.2 +++ b/plastex-theme/default-layout.html Tue Oct 27 00:10:56 2009 +0100 1.3 @@ -1,10 +1,25 @@ 1.4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.5 -<html> 1.6 +<html tal:define="links self/links" 1.7 + xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 1.8 <head> 1.9 - <title tal:content="self/title">Book Title</title> 1.10 + 1.11 <meta name="generator" content="plasTeX" /> 1.12 <meta http-equiv="content-type" 1.13 - tal:attributes="content string:text/html; charset=${config/files/output-encoding}" /> 1.14 + tal:attributes="content string:text/html;; charset=${config/files/output-encoding}" /> 1.15 + 1.16 + <title tal:condition="python:path('self/level') > -10" 1.17 + tal:content="stripped string:${links/document/title}: ${self/title}"> 1.18 + Book title 1.19 + </title> 1.20 + <link tal:condition="links/next" 1.21 + rel="next" 1.22 + tal:attributes="href links/next/url; title links/next/title/textContent" /> 1.23 + <link tal:condition="links/prev" 1.24 + rel="prev" 1.25 + tal:attributes="href links/prev/url; title links/prev/title/textContent" /> 1.26 + <link tal:condition="links/up" 1.27 + rel="up" 1.28 + tal:attributes="href links/up/url; title links/up/title/textContent" /> 1.29 1.30 <link rel="stylesheet" href="styles/styles.css"/> 1.31 <link rel="stylesheet" href="/support/styles/styles.css"/> 1.32 @@ -22,19 +37,80 @@ 1.33 <body> 1.34 1.35 <div class="navheader"><h2 class="booktitle"> 1.36 - <tal:booktitle replace="self/title" /> 1.37 + <tal:booktitle replace="links/document/title" /> 1.38 <div class="authors">by 1.39 - <tal:author tal:content="self/author"> 1.40 + <tal:author tal:content="links/document/attributes/author"> 1.41 Author 1.42 </tal:author> 1.43 </div> 1.44 </h2> 1.45 </div> 1.46 1.47 - <div class="chapter" id="{% doc_id %}"> 1.48 + <div class="navheader" metal:define-macro="navigation"> 1.49 + <table width="100%"> 1.50 + <tr> 1.51 + <td width="40%" align="left"> 1.52 + <a tal:condition="links/prev" 1.53 + tal:attributes="href links/prev/url; 1.54 + title stripped:links/prev/title" 1.55 + accesskey="p">Prev</a> </td> 1.56 + <td width="20%" align="center"> 1.57 + <a tal:condition="links/up" 1.58 + tal:attributes="href links/up/url">Up</a> 1.59 + </td> 1.60 + <td width="40%" align="right"> 1.61 + <a tal:condition="links/next" 1.62 + tal:attributes="href links/next/url; 1.63 + title stripped:links/next/title" 1.64 + accesskey="n">Next</a> 1.65 + </td> 1.66 + </tr> 1.67 + <tr> 1.68 + <td width="40%" align="left"> 1.69 + <span tal:condition="links/prev" 1.70 + tal:replace="stripped:links/prev/title">Prev</span> 1.71 + </td> 1.72 + <td width="20%" align="center"> </td> 1.73 + <td width="40%" align="right"> 1.74 + <span tal:condition="links/next" 1.75 + tal:replace="stripped:links/next/title">Next</span> 1.76 + </td> 1.77 + </tr> 1.78 + </table> 1.79 + </div> 1.80 + 1.81 + <div class="chapter" 1.82 + tal:attributes="id string:${links/document/title}: ${self/title}"> 1.83 1.84 <div class="file_contents" tal:content="self">File contents.</div> 1.85 1.86 + <div tal:condition="self/tableofcontents" 1.87 + tal:attributes="class 1.88 + string:contents 1.89 + ${self/nodeName}-contents"> 1.90 + <ul> 1.91 + <li tal:repeat="section self/tableofcontents"><a href="." tal:attributes="href section/url" tal:content="section/fullTocEntry">Aliquam est. Aliquam fringilla pede</a> 1.92 + <ul tal:condition="section/tableofcontents"> 1.93 + <li tal:repeat="subsection section/tableofcontents"><a href="." tal:attributes="href subsection/url" tal:content="subsection/fullTocEntry"></a> 1.94 + <ul tal:condition="subsection/tableofcontents"> 1.95 + <li tal:repeat="subsubsection subsection/tableofcontents"><a href="." tal:attributes="href subsubsection/url" tal:content="subsubsection/fullTocEntry"></a> 1.96 + <ul tal:condition="subsubsection/tableofcontents"> 1.97 + <li tal:repeat="paragraph subsubsection/tableofcontents"><a href="." tal:attributes="href paragraph/url" tal:content="paragraph/fullTocEntry"></a> 1.98 + <ul tal:condition="paragraph/tableofcontents"> 1.99 + <li tal:repeat="subparagraph paragraph/tableofcontents"><a href="." tal:attributes="href subparagraph/url" tal:content="subparagraph/fullTocEntry"></a></li> 1.100 + </ul> 1.101 + </li> 1.102 + </ul> 1.103 + </li> 1.104 + </ul> 1.105 + </li> 1.106 + </ul> 1.107 + </li> 1.108 + <li tal:replace="nothing"><a href=".">Maecenas id purus</a></li> 1.109 + </ul> 1.110 + </div> 1.111 + 1.112 + 1.113 <div id="footnotes" tal:condition="self/footnotes"> 1.114 <p><b>Footnotes</b></p> 1.115 <ol> 1.116 @@ -56,6 +132,8 @@ 1.117 href="http://mattahan.deviantart.com/">Mattahan</a>.</p> 1.118 </div> 1.119 1.120 + <div class="navfooter" 1.121 + metal:use-macro="template/macros/navigation" /> 1.122 </body> 1.123 1.124 <script language="javascript" src="icons/imgadjust.js"
2.1 --- a/web/hgbook/comments/models.py Mon Oct 26 21:50:49 2009 +0100 2.2 +++ b/web/hgbook/comments/models.py Tue Oct 27 00:10:56 2009 +0100 2.3 @@ -6,7 +6,7 @@ 2.4 class Element(models.Model): 2.5 id = models.CharField('ID attribute', max_length=64, editable=False, 2.6 primary_key=True) 2.7 - chapter = models.CharField('Chapter ID', max_length=64, editable=False, 2.8 + chapter = models.CharField('Chapter ID', max_length=100, editable=False, 2.9 db_index=True) 2.10 title = models.CharField('Section title', max_length=256, editable=False) 2.11
3.1 --- a/web/hgbook/converter.py Mon Oct 26 21:50:49 2009 +0100 3.2 +++ b/web/hgbook/converter.py Tue Oct 27 00:10:56 2009 +0100 3.3 @@ -14,8 +14,8 @@ 3.4 from comments.models import Element 3.5 3.6 doc_id = 'MMSC' 3.7 -sel = CSSSelector('p, pre, h1, table.equation') 3.8 -body = CSSSelector('body') 3.9 +sel = CSSSelector('div.chapter p, pre, h1, table.equation') 3.10 +chapter_sel = CSSSelector('div.chapter') 3.11 3.12 try: 3.13 filename = args[0] 3.14 @@ -25,7 +25,11 @@ 3.15 tree = etree.parse(filename, html.HTMLParser(remove_blank_text=True)) 3.16 root = tree.getroot() 3.17 3.18 -body(root)[0].set('id', doc_id) 3.19 +chapter = chapter_sel(root)[0] 3.20 +chapter_title = chapter.get('id').split(':')[1] 3.21 +chapter_hash = md5.new(chapter.get('id').encode('utf8')).hexdigest() 3.22 + 3.23 +chapter.set('id', chapter_hash) 3.24 3.25 for element in sel(root): 3.26 hsh_source = element.text or element.get('alt') or etree.tostring(element) 3.27 @@ -33,13 +37,13 @@ 3.28 if hsh_source: 3.29 hsh_source_encoded = hsh_source.encode('utf8') 3.30 hsh = md5.new(hsh_source_encoded).hexdigest() 3.31 - element.set('id', '%s-%s' % (doc_id, hsh)) 3.32 + element.set('id', '%s-%s' % (chapter_hash, hsh)) 3.33 3.34 # create the commentable element in the DB 3.35 e = Element() 3.36 - e.id = '%s-%s' % (doc_id, hsh) 3.37 - e.chapter = doc_id 3.38 - e.title = hsh 3.39 + e.id = '%s-%s' % (chapter_hash, hsh) 3.40 + e.chapter = chapter_hash 3.41 + e.title = chapter_title 3.42 e.save() 3.43 3.44