diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 31337cdbf..c75ea2d3d 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -263,7 +263,7 @@ Add Path Format Functions and Fields ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Beets supports *function calls* in its path format syntax (see -:doc:`/reference/pathformat`. Beets includes a few built-in functions, but +:doc:`/reference/pathformat`). Beets includes a few built-in functions, but plugins can add new functions using the ``template_func`` decorator. To use it, decorate a function with ``MyPlugin.template_func("name")`` where ``name`` is the name of the function as it should appear in template strings. @@ -288,13 +288,16 @@ Plugins can also add template *fields*, which are computed values referenced as parameter, ``item``, with ``MyPlugin.template_field("name")``. Here's an example that adds a ``$disc_and_track`` field:: - @MyPlugin.template_value('disc_and_track') + @MyPlugin.template_field('disc_and_track') def _tmpl_disc_and_track(item): - """Expand to the disc number and track number if both are - sepcified. If there's no disc number, then just exapnds to the - track number. + """Expand to the disc number and track number if this is a + multi-disc release. Otherwise, just exapnds to the track + number. """ - if item.disc: + if item.disctotal > 1: return u'%02i.%02i' % (item.disc, item.track) else: return u'%02i' % (item.track) + +With this plugin enabled, templates can reference ``$disc_and_track`` as they +can any standard metadata field. diff --git a/docs/reference/pathformat.rst b/docs/reference/pathformat.rst index c10dcdebf..0fd05f127 100644 --- a/docs/reference/pathformat.rst +++ b/docs/reference/pathformat.rst @@ -100,7 +100,8 @@ Available Values Here's a (comprehensive?) list of the different values available to path formats. (I will try to keep it up to date, but I might forget. The current list -can be found definitively `in the source`_.) +can be found definitively `in the source`_.) Note that plugins can add new (or +replace existing) template values (see :ref:`writing-plugins`). .. _in the source: http://code.google.com/p/beets/source/browse/beets/library.py#36