<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Janes&#039; Code Weblog &#187; djolt</title>
	<atom:link href="http://code.davidjanes.com/blog/category/djolt/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.davidjanes.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 11 Apr 2010 12:32:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Djolt-obj: Django-like templates for Objective-C</title>
		<link>http://code.davidjanes.com/blog/2010/04/09/djolt-obj-django-like-templates-for-objective-c/</link>
		<comments>http://code.davidjanes.com/blog/2010/04/09/djolt-obj-django-like-templates-for-objective-c/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 12:51:26 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[code fragments]]></category>
		<category><![CDATA[djolt]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=670</guid>
		<description><![CDATA[My company, Discover Anywhere Mobile, has open sourced a software component that many iPhone developers may be interested in: Djolt (Django-like Templates) for Objective C. The objective of this project is to be able to take NSObjects &#8211; particularly NSDictionary, NSArray, NSString and NSNumber &#8211; and be able to feed them to a text template, [...]]]></description>
			<content:encoded><![CDATA[<p>My company, <a href="http://www.discoveranywheremobile.com/">Discover Anywhere Mobile</a>, has open sourced a software component that many iPhone developers may be interested in: <a href="http://code.google.com/p/djolt/">Djolt (Django-like Templates) for Objective C</a>. The objective of this project is to be able to take NSObjects &#8211; particularly NSDictionary, NSArray, NSString and NSNumber &#8211; and be able to feed them to a text template, <a href="http://docs.djangoproject.com/en/dev/topics/templates/">Django style</a>, and get text output. This will be fantastic for working with APIs that deliver data via JSON or XML.</p>
<p>It&#8217;s dependent on <a rel="nofollow" href="http://regexkit.sourceforge.net/">RegexKit</a> library for now, though if the iPhone OS 4 NSRegularExpression is powerful enough we may transition to that.</p>
<p>The code is being tested against the Django template test cases, with the goal of having as complete as possible (given different language idioms) compatibility. We only cover a small subset of Django yet &#8211; the stuff we need &#8211; <strong>but if you&#8217;re interested in working on the project, please by all means join in</strong>.</p>
<h4>Code</h4>
<pre>NSDictionary* d = [[NSData dataWithContentsOfFile:@"test.json"] yajl_JSON];

DjoltTemplate* t = [[DjoltTemplate alloc] initWithTemplateFile:@"test.djolt"];
NSString* r = [t render:d];
</pre>
<h4>test.json</h4>
<pre>{
 "title" : "Test 1",
 "items" : [
  {
   "href" : "http://www.example.com/1",
   "title" : "Example 1"
  },
  {
   "href" : "http://www.example.com/2",
   "title" : "Example 2 &amp; Example \"2.5\""
  },
  {
   "href" : "http://www.example.com/3",
   "title" : "Example 3"
  }
 ]
}</pre>
<h4>test.djolt</h4>
<pre>&lt;html&gt;
&lt;head&gt;{{ title }}&lt;/head&gt;
&lt;body&gt;
{% if fred or items or bleck %}
&lt;ul&gt;
{% for itemd in items %}
&lt;li&gt;&lt;a href='{{ itemd.href }}'&gt;{{ itemd.title|safe }}&lt;/a&gt; ({{ forloop.counter }})&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
{% endif %}
&lt;p&gt;
{{ nothing|default:"something" }}
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>Output</h4>
<pre>&lt;html&gt;
&lt;head&gt;Test 1&lt;/head&gt;
&lt;body&gt;

&lt;ul&gt;

&lt;li&gt;&lt;a href='http://www.example.com/1'&gt;Example 1&lt;/a&gt; (1)&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.example.com/2'&gt;Example 2 &amp; Example "2.5"&lt;/a&gt; (2)&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.example.com/3'&gt;Example 3&lt;/a&gt; (3)&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;
something
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2010/04/09/djolt-obj-django-like-templates-for-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pipe Cleaner</title>
		<link>http://code.davidjanes.com/blog/2008/12/18/pipe-cleaner/</link>
		<comments>http://code.davidjanes.com/blog/2008/12/18/pipe-cleaner/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 23:38:21 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[demo]]></category>
		<category><![CDATA[djolt]]></category>
		<category><![CDATA[dqt]]></category>
		<category><![CDATA[html / javascript]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[jd]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[pipe cleaner]]></category>
		<category><![CDATA[pybm]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=372</guid>
		<description><![CDATA[I&#8217;ve been working (in my decreasing available spare time) on a project to pull together into a project called &#8220;Pipe Cleaner&#8221; all the various concepts I&#8217;ve been mentioning on this blog: Web Object Records (WORK) for API Access and object manipulation, Djolt for generating text from templates, Data/Query/Transform/Template (DQT) for transforming data and JD for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working (in my decreasing available spare time) on a project to pull together into a project called &#8220;Pipe Cleaner&#8221; all the various concepts I&#8217;ve been mentioning on this blog: <a href="http://code.davidjanes.com/blog/category/work/">Web Object Records (WORK</a>) for API Access and object manipulation, <a href="http://code.davidjanes.com/blog/category/djolt/">Djolt</a> for generating text from templates, <a href="http://code.davidjanes.com/blog/category/dqt/">Data/Query/Transform/Template</a> (DQT) for transforming data and <a href="http://code.davidjanes.com/blog/category/jd/">JD</a> for scripting these elements together. The pieces came together this morning enough to put a demo together and here it is &#8211; <a href="http://code.davidjanes.com/examples/2008-12-18/gmaps3/">the Toronto Fires Pt II Demo</a>.</p>
<p>How, you may ask, does this differ from <a href="http://code.davidjanes.com/blog/2008/11/22/toronto-fires/">the original Toronto Fires Demo</a>? The answer is how it is put together, which we describe here.</p>
<h4>Index.dj</h4>
<p>This is the Djolt template that generates the output. The data fed to this template is generate by the JD script, described in the next section.</p>
<pre>&lt;html&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" type="text/css" href="css.css" /&gt;
    {{ gmaps.js|safe }}
&lt;/head&gt;
&lt;body&gt;
&lt;div id="content_wrapper"&gt;
    &lt;div id="map_wrapper"&gt;
        {{ gmaps.html|safe }}
    &lt;/div&gt;
    &lt;div id="text_wrapper"&gt;
{% for incident in incidents %}
    &lt;div id="{{ incident.IncidentNumber }}"&gt;
        {{ incident.body_sb|safe }}
    &lt;/div&gt;
{% endfor %}
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Quite simple &#8230; as you can see, most of the data is being pulled in from elsewhere. The elsewhere is provided by the script described in the next section.</p>
<h4>Index.jd</h4>
<p>This is the script that pull all the pieces together. Note that I&#8217;m not 100% happy with the way the data is imported, I would like the geocoding to become part of this data flow too. In the next release perhaps.</p>
<p>First we pull in the &#8220;fire&#8221; module that we wrote in the previous Map examples. This is doing exactly what you think: importing a Python module. We may have to increase the security or restrict this to working with an API for general purpose use.</p>
<pre>import module:"fire";</pre>
<p>Next we define two headers &#8211; one that is going to appear in the Google Maps popup, the next that is going to appear in the sidebar. They need to be different as they refer to themselves. Note that the sidebar header &#8220;breaks&#8221; the encapsulation of Google Maps &#8211; this seems to be unavoidable. The <code>to:"fitem.head.map"</code> and <code>to:"fitem.head.sb"</code> are manipulating a WORK dictionary to store values.</p>
<p>Note also here that we&#8217;ve extended JD to accept Python multiline strings &#8211; this was unavoidable if JD was to be useful to me.</p>
<pre>set to:"fitem.head.map" value:"""
&lt;h3&gt;
&lt;a href="#{{ IncidentNumber }}"&gt;{{ AlarmLevel}}: {{ IncidentType }} on {{ RawStreet }}
&lt;/h3&gt;
""";

set to:"fitem.head.sb" value:"""
&lt;h3&gt;
{% if latitude and longitude %}
&lt;a href="javascript:js_maps.map.panTo(new GLatLng({{ latitude }}, {{ longitude }}))"&gt;*
{% endif %}
&lt;a href="#{{ IncidentNumber }}"&gt;{{ AlarmLevel}}: {{ IncidentType }} on {{ RawStreet }}
&lt;/h3&gt;
""";</pre>
<p>The next block defines the text of the body used to describe a fire incident. It follows much the same pattern as the previous block.</p>
<pre>set to:"fitem.body" value:"""
&lt;p&gt;
Alarm Level: {{ AlarmLevel }}
&lt;br /&gt;
Incident Type: {{ IncidentType }}
&lt;br /&gt;
City: {{ City }}
&lt;br /&gt;
Street: {{ Street }} ({{ CrossStreet }})
&lt;br /&gt;
Units: {{ Units }}
&lt;/p&gt;
""";</pre>
<p>This is a map: it is translating the values in <code>fire.GetGeocodeIncidents</code> into a new format and storing that in <code>incidents</code>. The format that we were are storing it in is understood by the Google Maps generating module.</p>
<p>We may rename this translate, as the word map is somewhat overloaded.</p>
<pre>map from:"fire.GetGeocodedIncidents" to:"incidents" map:{
    "latitude" : "{{ latitude }}",
    "longitude" : "{{ longitude }}",
    "title" : "{{ AlarmLevel}}: {{ IncidentType }} on {{ RawStreet }}",
    "uri" : "{{ HOME_URI }}#{{ IncidentNumber }}",
    "body" : "{{ *fitem.head.map|safe }}{{ *fitem.body|safe }}",
    "body_sb" : "{{ *fitem.head.sb|safe }}{{ *fitem.body|safe }}",
    "IncidentNumber" : "{{ IncidentNumber }}"
};</pre>
<p>Next we set up the &#8220;meta&#8221; (see <a href="http://code.davidjanes.com/blog/2008/11/11/work-web-object-records/">WORK meta description</a> if you&#8217;re not following along) for the maps. The <code>render_value:true</code> declaration makes PC interpret the templates in strings). We then call our Google Maps generating code (which are actually more Pipe Cleaners) and that gets fed to the Djolt template we first showed you. Clear? Maybe not, we&#8217;ll have more examples coming&#8230;</p>
<pre>set to:"map_meta" render_value:true value:{
    "id" : "maps",
    "latitude" : 43.67,
    "longitude" : -79.38,
    "uzoom" : -13,
    "gzoom" : 13,
    "api_key" : "{{ cfg.gmaps.api_key|otherwise:'...mykey...' }}",
    "html" : {
        "width" : "1024px",
        "height" : "800px"
    }
};

load template:"gmaps.js" items:"incidents" meta:"map_meta";
load template:"gmaps.html" items:"incidents" meta:"map_meta";</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/12/18/pipe-cleaner/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A brief survey of Yahoo Pipes as a DQT</title>
		<link>http://code.davidjanes.com/blog/2008/12/11/brief-survey-of-yahoo-pipes/</link>
		<comments>http://code.davidjanes.com/blog/2008/12/11/brief-survey-of-yahoo-pipes/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 12:19:55 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[demo]]></category>
		<category><![CDATA[djolt]]></category>
		<category><![CDATA[dqt]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[semantic web]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=325</guid>
		<description><![CDATA[Yahoo Pipes is a visual editor of mashups, allowing you to take data from sources on the net, transform them in various interesting ways and output the result as Atom, RSS or JSON. The primary downside Pipes of course is that you&#8217;re totally dependent on Yahoo for the infrastructure: it runs at Yahoo pulling feeds [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.davidjanes.com/examples/2008-12-13/pipes.png" alt="MacFUSE" style="border: 0 0 10px 10px; float: right;" /><a href="http://pipes.yahoo.com/">Yahoo Pipes</a> is a visual editor of mashups, allowing you to take data from sources on the net, transform them in various interesting ways and output the result as Atom, RSS or JSON. The primary downside Pipes of course is that you&#8217;re totally dependent on Yahoo for the infrastructure: it runs at Yahoo pulling feeds that have to be accessable through the public Internet.</p>
<p>It&#8217;s easy to use Pipes: just <a href="http://pipes.yahoo.com/pipes/docs?doc=overview">go to this page</a> and start working with the sample example Pipe. You&#8217;ll need a Yahoo login ID, but most of us have that anyway. I&#8217;ve created an example that uses Yahoo Pipes to feed a Djolt template <a href="http://code.davidjanes.com/examples/2008-12-11/dqt2/">which you can see here</a>.</p>
<p>We can analyze Pipes in the terms of <a href="http://code.davidjanes.com/blog/2008/12/09/introducing-dqt-dataquerytransformtemplate/">the DQT paradigm we&#8217;ve outlined in the previous post</a>.</p>
<h4>Data Sources and Queries</h4>
<p>Sources and Queries are merged (quite logically) in the Pipes interface. <a href="http://pipes.yahoo.com/pipes/docs?doc=sources">You can read in depth documentation here</a>.</p>
<ul>
<li>Fetch CSV</li>
<li>Feed Autodiscovery &#8211; outputs syndication feeds found on a page (<a href="http://pipes.yahoo.com/pipes/pipe.info?_id=jAZaeHvH3RGDaUk__w6H4A">RSS feeds on a CBC page</a>)</li>
<li>Fetch Feed</li>
<li>Fetch Page &#8211; will read a page and parse the contents with a reg</li>
<li>Fetch Site Feed &#8211; this is the logical combination of Fetch Feed and Fetch Autodiscovery</li>
<li>Flickr &#8211; find images by tag near a location (<a href="http://pipes.yahoo.com/pipes/pipe.info?_id=oPG38nvH3RG0QpVRrbQIDg">photos of cats in Toronto</a>)</li>
<li>Google Base &#8211; look up information in Google Base</li>
<li>Item Builder &#8211; a way of building new items from existing items</li>
<li>Yahoo Local</li>
<li>Yahoo Search</li>
</ul>
<h4>Transforms</h4>
<p>The <a href="http://pipes.yahoo.com/pipes/docs?doc=operators">operator documentation can be read here</a>.</p>
<ul>
<li>Count</li>
<li>Filter</li>
<li>Location Extractor &#8211; a geocoder that magically looks for locations</li>
<li>Loop</li>
<li>Regex</li>
<li>Rename</li>
<li>Reverse</li>
<li>Sort</li>
<li>Split</li>
<li>Sub-element &#8211; pulls a particular sub-element of an item and makes that the item. This is very much like WORK path manipulation</li>
<li>Tail</li>
<li>Truncate</li>
<li>Union</li>
<li>Unique</li>
<li>Web Service</li>
</ul>
<p>Plus a number of specialized data services, for dealing with elements such as dates.</p>
<h4>Templates</h4>
<p>Pipes does not provide an arbitrary Djolt-like template producing HTML. Instead, they provide a number of pre-made code templates that output well known data types, including RSS, JSON and Atom (and some stranger choices, like PHP).</p>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/12/11/brief-survey-of-yahoo-pipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding backwards for simplicity</title>
		<link>http://code.davidjanes.com/blog/2008/12/08/coding-backwards-for-simplicity/</link>
		<comments>http://code.davidjanes.com/blog/2008/12/08/coding-backwards-for-simplicity/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 21:58:57 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[djolt]]></category>
		<category><![CDATA[dqt]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[pybm]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=311</guid>
		<description><![CDATA[I haven&#8217;t been posting as much as I like here for the last three weeks, not because of lack of ideas but because I haven&#8217;t been able to consolidate what I&#8217;ve been working on into a coherent thought. I&#8217;m trying to come up with a overreaching conceptual arch that covers WORK, Djolt and the various [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been posting as much as I like here for the last three weeks, not because of lack of ideas but because I haven&#8217;t been able to consolidate what I&#8217;ve been working on into a coherent thought. I&#8217;m trying to come up with a overreaching conceptual arch that covers <a href="http://code.davidjanes.com/blog/category/work/">WORK</a>, <a href="http://code.davidjanes.com/blog/category/djolt/">Djolt</a> and the various API interfaces I&#8217;ve been coded. Tentatively and horribly, I&#8217;m calling this Data/Query/Transform/Template right now though I&#8217;m expecting this to change.</p>
<p>The first demo of this &#8230; without further explanation &#8230; <strong><a href="http://code.davidjanes.com/examples/2008-12-08/dqtt1/">can be seen here</a></strong>. More details about what this is actually demonstrating (besides formatting this blog) will be forthcoming.</p>
<p>What I want to draw attention to in this post is <em>how</em> I coded this. What I&#8217;ve been doing for the last several weeks is <em>coding backwards</em>: I start with what I want the final code to look like and then figure out all the libraries, little languages and so forth that would be needed to code that. After several false starts, my conceptual logjam broke about a week ago and code started radically simplifying.</p>
<p>The ideal code, in my mind, is almost entirely static declarations: no loops, no if statements, no while statements, no goto-type statements (god help us). We simply specify how the parts are connected, and hope that we can abstract the complexity into the libraries that make this all happen. The code that you see below is actually post all my conceptualizing: I just wanted to write some code and since I had almost all the parts together it fell together quite nicely:</p>
<pre>import bm_wsgi
import bm_io

import djolt
import api_feed

from bm_log import Log

class Application(bm_wsgi.SimpleWrapper):
    def __init__(self, *av, **ad):
        bm_wsgi.SimpleWrapper.__init__(self, *av, **ad)

    def CustomizeSetup(self):
        self.html_template_src = bm_io.readfile("index.dj")
        self.html_template = djolt.Template(self.html_template_src)

        self.context = djolt.Context()
        self.context["paramd"] = {
            "feed" : "http://feeds.feedburner.com/DavidJanesCode",
            "template" : """\
&lt;ul&gt;
{% for item in data.items %}
	&lt;li&gt;&lt;a href="{{ item.link }}"&gt;{{ item.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
""",
        }
        self.context.Push()
        self.context["paramd"] = self.paramd
        self.context["data"] = api_feed.RSS20(self.context.as_string("paramd.feed"))

    def CustomizeContent(self):
        yield   self.html_template.Render(self.context)

if __name__ == '__main__':
    Application.RunCGI()</pre>
<p>There&#8217;s almost nothing there! In particular, note:</p>
<ul>
<li><code>bm_wsgi.SimpleWrapper</code> handles all the WSGI interface work, including determining when to output HTML headers, error trapping, and Unicode to UTF-8 encoding</li>
<li>the most complicated part of the application is setting up the <code>Context</code>. In particular, note that self.paramd is automatically populated by the <code>QUERY_STRING</code> passed to the application, and the double setting we do here allows us to have default values.</li>
<li>If you want to see the HTML template that drives the application <a href="http://code.davidjanes.com/examples/2008-12-08/dqtt1/index.dj">it is here</a>. Note two variations from Django templates: the <code>{% asis %}</code> block which doesn&#8217;t intrepret it&#8217;s content as Djolt code and the <code>{{ *paramd.template|safe }}</code> variable which<em> <a href="http://code.davidjanes.com/blog/2008/12/04/djolt-indirection/">interprets the variable&#8217;s contents as a template</a></em>.</li>
<li>Methods called <code>Customize</code>-something are my convention for framework functions, i.e. methods that will be called for us rather than methods we call.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/12/08/coding-backwards-for-simplicity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Djolt Indirection</title>
		<link>http://code.davidjanes.com/blog/2008/12/04/djolt-indirection/</link>
		<comments>http://code.davidjanes.com/blog/2008/12/04/djolt-indirection/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 11:05:28 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[demo]]></category>
		<category><![CDATA[djolt]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=289</guid>
		<description><![CDATA[I&#8217;ve been working through a sticky problem with Djolt, trying to implement my Toronto Fires example in as few lines as possible. As part of this, I&#8217;ve come up with the idea of adding indirection to Djolt templates:
import djolt

d = {
    "a" : "It says: {{ b }}",
    "b" [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working through a sticky problem with Djolt, trying to implement my Toronto Fires example in as few lines as possible. As part of this, I&#8217;ve come up with the idea of adding indirection to Djolt templates:</p>
<pre>import djolt

d = {
    "a" : "It says: {{ b }}",
    "b" : "Hello, World"
}

t = djolt.Template("""
a: {{ a }}
b: {{ b }}
*a: {{ *a }}
""")

print t.Render(d)
""")

print t.Render(d)</pre>
<p>Which yields:</p>
<pre>a: It says: {{ b }}
b: Hello, World
*a: It says: Hello, World
</pre>
<p>This is significantly updated from the original version I posted here an hour ago. The indirection now makes the variable read as a template. This is a much more powerful concept.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/12/04/djolt-indirection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Djolt &#8211; Django-like Templates</title>
		<link>http://code.davidjanes.com/blog/2008/11/28/djolt-django-like-templates/</link>
		<comments>http://code.davidjanes.com/blog/2008/11/28/djolt-django-like-templates/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 21:34:39 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[djolt]]></category>
		<category><![CDATA[pybm]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=277</guid>
		<description><![CDATA[Djolt is a reimplementation of Django&#8217;s template language in Python. Why do this?

I like the Django template language
I wanted something that small and independent of Django
I wanted something that will work with WORK paths (this was the real deal breaker for using Django)
I wanted something that I could take and reimplement in Javascript and maybe [...]]]></description>
			<content:encoded><![CDATA[<p>Djolt is a reimplementation of <a href="http://docs.djangoproject.com/en/dev/topics/templates/">Django&#8217;s template language</a> in Python. Why do this?</p>
<ul>
<li>I like the Django template language</li>
<li>I wanted something that small and independent of Django</li>
<li>I wanted something that will work with <a href="http://code.davidjanes.com/blog/2008/11/21/work-paths/">WORK paths</a> (this was the real deal breaker for using Django)</li>
<li>I wanted something that I could take and reimplement in Javascript and maybe Java too</li>
<li>Some template engines, <a href="http://www.cheetahtemplate.org/">Cheetah</a> for example, are far too heavy for the kind of light-weight applications I have in mind; <em>note that I&#8217;ve had great success with Cheetah in the past </em></li>
<li>Some template engines, <a href="http://www.python.org/doc/2.6/library/string.html#format-string-syntax">such as that in Python 2.6</a>, are for too underfeatured</li>
</ul>
<p>However, if you&#8217;re really looking for the whole Django template experience and don&#8217;t want to use Djolt, just <a href="http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/">start here</a>.</p>
<h4>How do I get it?</h4>
<p>Djolt is packaged as part of the <a href="http://code.google.com/p/pybm/">pybm</a> library.</p>
<h4>How do I use it?</h4>
<pre>import djolt

t = djolt.Template("""
&lt;ul&gt;
{% for name in names %}
&lt;li&gt;{{ name }}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
""")
print t.Render({
    "names" : [ "Johnny", "Jack", "Ray", "Mary &amp; Sam", ]
})</pre>
<p>Which gives the results:</p>
<pre>&lt;ul&gt;
&lt;li&gt;Johnny&lt;/li&gt;
&lt;li&gt;Jack&lt;/li&gt;
&lt;li&gt;Ray&lt;/li&gt;
&lt;li&gt;Mary &amp;amp; Sam&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Note the &#8220;autoescaping&#8221; of the <code>&amp;</code> character.</p>
<h4>What tags does it define?</h4>
<ul>
<li>autoescape/endautoescape</li>
<li>if/else/endif</li>
<li>equal/endequal</li>
<li>for/endfor</li>
<li>notequal/notendequal</li>
</ul>
<p>It does not implement blocks.</p>
<h4>What filters does it define?</h4>
<ul>
<li>add</li>
<li>cut</li>
<li>default (see otherwise below)</li>
<li>default_if_none</li>
<li>divisibleby</li>
<li>first</li>
<li>join</li>
<li>last</li>
<li>length</li>
<li>length_is</li>
<li>linebreaks</li>
<li>lower</li>
<li>pluralize</li>
<li>random</li>
<li>safe (respecting all the Django autoescape rules)</li>
<li>slug</li>
<li>upper</li>
</ul>
<p>Unimplemented filters are due to laziness and will be done &#8220;on demand&#8221;. We also introduce a few new filters:</p>
<ul>
<li> jslug &#8211; like slug, but more Javascript friendly</li>
<li> otherwise &#8211; like default, except the empty string/empty values trigger the filter also</li>
</ul>
<h4>Are their differences between Djolt and Django templates?</h4>
<ul>
<li>Djolt tags suck up whitespace if they&#8217;re on a line by themselves</li>
<li>If Djolt cannot resolve a variable, it resolves to the appropriate &#8220;empty&#8221; value (as opposed to failing). This is keeping in line with <a href="http://code.davidjanes.com/blog/category/work/">WORK</a> philosophy</li>
</ul>
<p>Beyond that you should be able to use most Django template examples (that don&#8217;t use block/implements) as-is.</p>
<h4>Is it extensible?</h4>
<p>Yes. You can add your own tags and filters by following the examples in code (<code>djolt_nodes.py</code> and <code>djolt_filters.py</code> respectively).</p>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/11/28/djolt-django-like-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Toronto Fires</title>
		<link>http://code.davidjanes.com/blog/2008/11/22/toronto-fires/</link>
		<comments>http://code.davidjanes.com/blog/2008/11/22/toronto-fires/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 21:19:58 +0000</pubDate>
		<dc:creator>David Janes</dc:creator>
				<category><![CDATA[demo]]></category>
		<category><![CDATA[djolt]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://code.davidjanes.com/blog/?p=249</guid>
		<description><![CDATA[Here&#8217;s a little mashup I&#8217;ve been putting together for the last few days: Toronto Fires.
It&#8217;s taking the data listed here on the City of Toronto&#8217;s Fire Services &#8220;Active Accidents&#8221;, scraping it (by pretending HTML is XHTML and treating it as WORK objects), geocoding it (using our WORK Google API) and mapping it (using this information).
This [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little mashup I&#8217;ve been putting together for the last few days: <a href="http://code.davidjanes.com/examples/2008-11-22/fires/">Toronto Fires</a>.</p>
<p>It&#8217;s taking the data listed here on the <a href="http://www.toronto.ca/fire/cadinfo/livecad.htm">City of Toronto&#8217;s Fire Services &#8220;Active Accidents&#8221;</a>, scraping it (by pretending HTML is XHTML and treating it as <a href="http://code.davidjanes.com/blog/2008/11/11/work-web-object-records/">WORK</a> objects), geocoding it (using our <a href="http://code.davidjanes.com/blog/2008/11/18/work-api-teaser-iii-google-api/">WORK Google API</a>) and mapping it (using <a href="http://code.davidjanes.com/blog/category/maps/">this information</a>).</p>
<p>This is very much a work in progress, but here&#8217;s a few more things that are involved:</p>
<ul>
<li>we read <code>body.table.tr.td[1].table.tr[1].td.table.tr</code> as a list to get the rows in the table</li>
<li>we map those rows into the Geocoder use a new magic technology we&#8217;ll be explaining in the next few days: <a href="http://www.djangoproject.com/">Djolt</a> &#8211; <a href="http://www.djangoproject.com/">Django</a>-like <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/">templates</a></li>
<li>the output program is just one big Djolt template</li>
</ul>
<p>I&#8217;m not quite satisfied with how the current page is constructed: I want the final result to be much more simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.davidjanes.com/blog/2008/11/22/toronto-fires/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
