pyinclude plugin (showing off variables-with-arguments)

Note: This is an old post in a blog with a lot of posts. The world has changed, technologies have changed, and I've changed. It's likely this is out of date and not representative. Let me know if you think this is something that needs updating.

I checked in some changes I made last night which affect how variables get expanded and what kinds of things we can do with metadata variables. Now, we can expand the following variable things:

$foo

This is a regular variable with nothing fancy that we could handle before.

$foo::bar

This is variable bar in the scoping foo. Variables can now be grouped in categories. Categories can be functionally oriented (utils, calendar, date, file, communication, ...) or plugin oriented (pycalendar, pyarchives, ...) or whatever.

$foo::bar("arg1", "arg2", "arg3")

This is variable bar in the scoping foo... but it's actually a function call passing in three arguments all of type string. The arguments are evaluated as Python code, can be of any type, and any quantity. We only pass in the arguments if the value of the variable (in this case $foo::bar) is a function. This allows plugins to take in configuration information from other places other than config.py. For instance, this is really useful for a fileinclude kind of plugin where you might want to include different files at different points in your templates.... More about that later.

So now the following examples are all valid variables:

  • $foo

  • $foo::bar

  • $foo::bar(1, 2, 3)

  • $foo::bar::bar2({"arg1": 1, "arg2": 2})

  • $foo("arg1", 1, {"foo": "bar"})

In typical fashion (and at Wari's behest), I wrote a quick plugin which uses this. It allows you to include files in your head and foot templates. I use this to include my .project file so people can see it on my web-site as well as finger me on my server and I only have to update it in one place.

Code is here.

Want to comment? Send an email to willkg at bluesock dot org. Include the url for the blog entry in your comment so I have some context as to what you're talking about.