|
From: chombee <ch...@la...> - 2010-01-20 02:19:00
|
I've been thinking about this tumblelog plugin some more. I wanted to
add markdown support to it and did so in the copy that I'm running. I
just assumed that the top-level object of each YAML entry is a
dictionary and that each of the values in the dictionary is a string
that should be treated as markdown text (apart from the value of
'template_name' which is used to choose the entry's template). This
actually works fine for me but the assumptions really restrict the
flexibility of YAML, and it feels like a hack.
I think a better way of doing it might be to use PyYAML's ability to
load instances of user Python classes directly from YAML documents. For
each type of post you would add a class to the tumblelog.py file:
Link(yaml.YAMLObject), Quote(yaml.YAMLObject), etc. The content of an
entry would then look like this:
!Link
url: http://www.whatever.com
name: Whatever
desc: >
blah blah blah blah fkdlf fds f
ffds f fblah fd ff sd fds f fds.
tags: ['whatever','blah']
PyYAML knows to load a Link object from that YAML document. The Link
class can do what it wants with the fields, e.g. treating the `desc`
field as markdown text (or transforming it in any other way, for that
matter), the `tags` field as a list, etc. And the link class knows the
name of its template, you don't have to explicitly give `template_name`
in every new post that you create. Other classes can handle their own
fields in their own ways, and they can do whatever processing is
necessary with them, so much power is gained.
Each of these entry classes then has an entrydata() method that returns
a dict with `template_name` and whatever other fields that type of entry
has. So the entryparser plugin would load the yaml file with PyYAML,
call the entrydata() method of the resulting object to get a dictionary,
and return the dictionary to pyblosxom.
The only disadvantage seems to be that if the user wants to invent a new
type of post they now need to add a new class to tumblelog.py, as well
as adding a new template to each each of their flavours as before.
Well, so far the simpler and more limited version of the plugin works
for me, so I'll probably stick with it.
On Tue, Jan 05, 2010 at 09:01:31PM +0000, chombee wrote:
> This is a very simple plugin to make your PyBlosxom blog 'tumblelog'
> capable. It's an entry parser plugin that lets you write entries in
> YAML, and additionally lets those entries specify which story template
> they should be rendered with, so that you can have many different story
> templates in your flavour and entries of different types can have
> different YAML structures and different templates, so they ultimately
> get rendered differently by PyBlosxom even though they appear together
> on the same page. I keep trying to come up with a good way of explaining
> but not really succeeding, it's very simple really. It's explained
> better on the web page:
>
> http://github.com/seanh/PyBlosxom-tumblelog
>
> This is a very simple tumblelog plugin. In the future I'll probably want
> to add markdown support to it, and maybe have it figure out the template
> to use for a post depending on the post's category rather than having
> each post specify its template.
>
> Thanks to Will for tips on how to implement it.
>
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> pyblosxom-users mailing list
> pyb...@li...
> https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
|