Commits

Anonymous committed bcbe2e8

Add md2html() function and use it in templates instead of _html.

Comments (0)

Files changed (18)

     markdown
     PyYaml
 
-As of this writing, it takes my computer about eight seconds to load,
-and check the data and render the templates.
+As of this writing, it takes my computer about fifteen seconds to load,
+and check the data and render the templates (excluding documentation nodes.)
 
-The JSON file is, as of this writing, less than 500K, meaning that, at
+The JSON file is, as of this writing, less than 600K, meaning that, at
 broadband speeds it only takes a couple of seconds to download, making
 it feasible to implement a client-side query engine for Chrysoberyl
 in Javascript.  The size of this file could also be reduced, possibly

src/chrysoberyl/feed.py

         n = {}
         n.update(node)
         n['key'] = key
+        # Note, these are now done differently from how md2html()
+        # is done in the templates elsewhere
         for field_name in ('summary', 'description', 'commentary'):
             field = markdown_field(data, node, field_name,
                                    prefix='http://catseye.tc/node/')

src/chrysoberyl/renderer.py

 from jinja2.exceptions import TemplateNotFound
 import markdown
 
-from chrysoberyl.transformer import filekey, pathname2url
+from chrysoberyl.transformer import filekey, pathname2url, markdown_contents
 
 
 class Loader(BaseLoader):
             return fun
 
         @expose
+        def md2html(field_contents, prefix=None, fixed=False):
+            if fixed:
+                md = '\n'.join(
+                    ['    ' + l for l in field_contents.split('\n')]
+                )
+                return markdown.markdown(md)
+            else:
+                return markdown_contents(field_contents, prefix=prefix)
+
+        @expose
         def base_key(key=key):
             """Returns the 'base' part of the key, that is, with the medium,
             ('(HTML5)', etc), removed.

src/chrysoberyl/transformer.py

     return s
 
 
-def markdown_field(data, node, field, prefix=None):
-    """Convert a field containing markdown and Chrysoberyl
+def markdown_contents(contents, prefix=None):
+    """Convert the contents of a field containing markdown and Chrysoberyl
     cross-references (indicated with [[double brackets]]) into HTML.
 
     """
         return '<a href="%s">%s</a>' % (
             pathname2url(filekey(thing), prefix=prefix), link_text
         )
+    html = markdown.markdown(contents)
+    html = re.sub(r'\[\[(.*?)\]\]', linker, html)
+    return html
+
+
+def markdown_field(data, node, field, prefix=None):
     if field in node:
-        html = markdown.markdown(node[field])
-        html = re.sub(r'\[\[(.*?)\]\]', linker, html)
-        return html
+        return markdown_contents(node[field], prefix=prefix)
     else:
         return None
 
         for field in node.keys():
             new_fields[field.replace('-', '_')] = node[field]
         node.update(new_fields)
-        for field in ('summary', 'description', 'commentary'):
-            node[field + '_html'] = markdown_field(data, node, field)
-        node['blurb_html'] = markdown_field(data, node, 'blurb', prefix='node/')
-        for sample_key in ('sample', 'sample_input', 'sample_output'):
-            if sample_key in node:
-                sample_md = '\n'.join(
-                    ['    ' + l for l in node[sample_key].split('\n')]
-                )
-                node['%s_html' % sample_key] = markdown.markdown(sample_md)
 
     print "%d nodes converted." % count
 

templates/Article.html

 
 {# kind of an abuse of mainstage.  oh well #}
 {% block mainstage %}
-  {% if summary_html %}
-    {{ summary_html }}
+  {% if summary %}
+    {{ md2html(summary) }}
   {% endif %}
 {% endblock %}
 

templates/Automaton.html

 
 {% block properties %}
 
-{% if sample_html %}
+{% if sample %}
   <h2>Sample Configuration</h2>
-  <div class="sample">{{ sample_html }}</div>
-  {% if sample_input_html %}
+  <div class="sample">{{ md2html(sample, fixed=true) }}</div>
+  {% if sample_input %}
     <p>Input:</p>
-    <div class="sample">{{ sample_input_html }}</div>
+    <div class="sample">{{ md2html(sample_input, fixed=true) }}</div>
   {% endif %}
-  {% if sample_output_html %}
+  {% if sample_output %}
     <p>Output:</p>
-    <div class="sample">{{ sample_output_html }}</div>
+    <div class="sample">{{ md2html(sample_output, fixed=true) }}</div>
   {% endif %}
   {% if sample_credit %}
     <p>This sample was written by {{ link(sample_credit) }}</p>

templates/Chris Pressey's Lingography.html

 
   <div class="row-fluid">
     <div class="span8">
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
       
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
 
       {% if related('implementation_of', key=thing) %}
     </div>
 
     <div class="span4">
-      {% if data[thing].sample_html %}
-        <div class="sample">{{ data[thing].sample_html }}</div>
+      {% if data[thing].sample %}
+        <div class="sample">{{ md2html(data[thing].sample, fixed=true) }}</div>
       {% endif %}
-      {% if data[thing].sample_input_html %}
+      {% if data[thing].sample_input %}
         <p>Input:</p>
-        <div class="sample">{{ data[thing].sample_input_html }}</div>
+        <div class="sample">{{ md2html(data[thing].sample_input, fixed=true) }}</div>
       {% endif %}
-      {% if data[thing].sample_output_html %}
+      {% if data[thing].sample_output %}
         <p>Output:</p>
-        <div class="sample">{{ data[thing].sample_output_html }}</div>
+        <div class="sample">{{ md2html(data[thing].sample_output, fixed=true) }}</div>
       {% endif %}
       {% if data[thing].sample_credit %}
         <p>This sample was written by {{ link(data[thing].sample_credit) }}</p>
           ({{ data[thing].inception_date }})
         {% endif %}
       </p>
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
     </li>
   {%- endif -%}

templates/Collection.html

         {%- if data[thing].controls -%}, {{ data[thing].controls }}{% endif -%}
       )
       </p>
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
     </li>
   {% endfor %}
           include_author in data[thing].authors %}
       <li>
         <p>{{ link(thing) }}</p>
-        {% if data[thing].description_html %}
-          {{ data[thing].description_html }}
+        {% if data[thing].description %}
+          {{ md2html(data[thing].description) }}
         {% endif %}
-        {% if data[thing].commentary_html %}
-          {{ data[thing].commentary_html }}
+        {% if data[thing].commentary %}
+          {{ md2html(data[thing].commentary) }}
         {% endif %}
       </li>
     {% endif %}

templates/Games by Chris Pressey.html

       {% if data[thing].images %}
         <div class="row-fluid">
           <div class="span8">
-            {{ data[thing].description_html }}
+            {{ md2html(data[thing].description) }}
           </div>
           <div class="span4">
             {% for image in data[thing].images %}
             {% endfor %}
           </div>
         </div>
-      {% elif data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% elif data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
 
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
 
       {# screenshot #}
         {% endif %}
         ({{ data[thing].inception_date }})
       </p>
-      {% if data[gamekey].description_html %}
-        {{ data[gamekey].description_html }}
+      {% if data[gamekey].description %}
+        {{ md2html(data[gamekey].description) }}
       {% endif %}
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
     </li>
   {%- endif -%}

templates/Implementation.html

         {% endif %}
       {% endif -%}
     </p>
-    {% if description_html %}
-      {{ description_html }}
+    {% if description %}
+      {{ md2html(description) }}
     {% endif %}
   </section>
 {% endblock description %}

templates/LoUIE.html

         data[thing].development_stage in ['idea'] -%}
     <li>
       <p>{{ link(thing) }} ({{ data[thing].inception_date }})</p>
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
     </li>
   {%- endif -%}

templates/Programming Language Family.html

 
 {% block properties %}
 
-{% if sample_html %}
+{% if sample %}
   <h2>Sample Program</h2>
-  <div class="sample">{{ sample_html }}</div>
-  {% if sample_input_html %}
+  <div class="sample">{{ md2html(sample, fixed=true) }}</div>
+  {% if sample_input %}
     <p>Input:</p>
-    <div class="sample">{{ sample_input_html }}</div>
+    <div class="sample">{{ md2html(sample_input, fixed=true) }}</div>
   {% endif %}
-  {% if sample_output_html %}
+  {% if sample_output %}
     <p>Output:</p>
-    <div class="sample">{{ sample_output_html }}</div>
+    <div class="sample">{{ md2html(sample_output, fixed=true) }}</div>
   {% endif %}
   {% if sample_credit %}
     <p>This sample was written by {{ link(sample_credit) }}</p>

templates/Programming Language.html

 
 {% block properties %}
 
-{% if sample_html %}
+{% if sample %}
   <h2>Sample Program</h2>
-  <div class="sample">{{ sample_html }}</div>
-  {% if sample_input_html %}
+  <div class="sample">{{ md2html(sample, fixed=true) }}</div>
+  {% if sample_input %}
     <p>Input:</p>
-    <div class="sample">{{ sample_input_html }}</div>
+    <div class="sample">{{ md2html(sample_input, fixed=true) }}</div>
   {% endif %}
-  {% if sample_output_html %}
+  {% if sample_output %}
     <p>Output:</p>
-    <div class="sample">{{ sample_output_html }}</div>
+    <div class="sample">{{ md2html(sample_output, fixed=true) }}</div>
   {% endif %}
   {% if sample_credit %}
     <p>This sample was written by {{ link(sample_credit) }}</p>

templates/Tools by Chris Pressey.html

       {%- endfor -%}
       )</p>
 
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
 
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
 
       {% if data[thing].online_implementations %}

templates/What is this I don't even.html

           {% endif %}
         {% endfor %}
       </p>
-      {% if data[thing].description_html %}
-        {{ data[thing].description_html }}
+      {% if data[thing].description %}
+        {{ md2html(data[thing].description) }}
       {% endif %}
-      {% if data[thing].commentary_html %}
-        {{ data[thing].commentary_html }}
+      {% if data[thing].commentary %}
+        {{ md2html(data[thing].commentary) }}
       {% endif %}
     </li>
   {%- endif -%}
           <a class="button" href="{{ data[impl].links[0] }}">Listen (mp3)</a>
         {% endif %}
       </p>
-      {% if data[impl].description_html %}
-        {{ data[impl].description_html }}
+      {% if data[impl].description %}
+        {{ md2html(data[impl].description) }}
       {% endif %}
-      {% if data[impl].commentary_html %}
-        {{ data[impl].commentary_html }}
+      {% if data[impl].commentary %}
+        {{ md2html(data[impl].commentary) }}
       {% endif %}
     </li>
   {%- endif -%}

templates/base.html

         <div class="row-fluid">
           <div class="span8">
             <section id="description">
-              {{ description_html }}
+              {{ md2html(description) }}
             </section>
           </div>
           <div class="span4">
         </div>
       {%- elif description -%}
         <section id="description">
-          {{ description_html }}
+          {{ md2html(description) }}
         </section>
       {%- endif -%}
     {%- endblock description -%}
       {%- if commentary -%}
         <section id="commentary">
           <h2>Commentary</h2>
-          {{ commentary_html }}
+          {{ md2html(commentary) }}
         </section>
       {%- endif -%}
     {%- endblock commentary -%}

templates/type.html

       This is a list of {{ plural(key)|lower }} with entries in {{ link('Chrysoberyl') }}.
     </p>
     {%- if description -%}
-      {{- description_html -}}
+      {{- md2html(description) -}}
     {%- endif -%}
   </section>
 {% endblock description %}

templates/type_Online Installation.html

 {% endblock extra_head %}
 
 {% block description %}
-  {{ description_html }}
+  {{ md2html(description) }}
 {% endblock %}
 
 {% block content %}
 {% for thing in related('type')|sort -%}
   <h3>{{ link(thing) }}</h3>
   <p><i>{{ data[thing].medium }}</i> in the <i>{{ data[thing].exhibit }}</i></p>
-  {% if data[thing].description_html %}
-    {{ data[thing].description_html }}
+  {% if data[thing].description %}
+    {{ md2html(data[thing].description) }}
   {% endif %}
-  {% if data[thing].commentary_html %}
-    {{ data[thing].commentary_html }}
+  {% if data[thing].commentary %}
+    {{ md2html(data[thing].commentary) }}
   {% endif %}
 {% endfor %}