splitbrain / dokuwiki-plugin-bureaucracy

Create forms and generate pages or emails from them
http://www.dokuwiki.org/plugin:bureaucracy
GNU General Public License v2.0
43 stars 47 forks source link

feature: add dokuwiki functions to template parser #227

Closed solewniczak closed 5 years ago

solewniczak commented 6 years ago

this commit adds an additional syntax to bureaucracy template parser that introduces simple functions calls:

@function_name(arg)@

the functions are parsed after the fields replacements. this will work:

@function(@@some_field@@)@

currently four functions are supported:

only functions with one argument are possible now

i've found this useful when using bureaucracy together with struct's "Page" field. My use cases:

  1. Use the page title in template replacement:

@p_get_first_heading(@@schema.page@@)

  1. In template action as new page name:

action template tpl:template1 "somens:@noNS(@@schema.page@@)@"

solewniczak commented 5 years ago

What do you think about it? Do you want to merge it into mainline?

solewniczak commented 5 years ago

I believe this is simple and quite useful feature. I can provide some unit test if desirable. I'll update the documentation as soon as the feature is merged.

splitbrain commented 5 years ago

Yes, unit tests would be helpful. Unfortunately I don't have the time to properly look into all the pull requests here. This plugin could use some clean up and maintenance. I just gave you commit access, feel free to merge and refactor where you see fit. Please try to keep the documentation uptodate with whatever changes you introduce.

ludi113 commented 5 years ago

Hi,

Great to see more people working on the bureaucracy plugin.

This thread reminds me on a use case I am looking for: There are several fields in my form collecting numerical data. I have to send an email with the result of a computation done with the numerical data (at the moment merely additions and multiplications). Would it be possible to add a fifth function to this feature that would be able to perform computations with numerical fields?

Thanks in advance for reading this and sorry if this message disturbs the thread.

Klap-in commented 5 years ago

Hi Szymon,

Are the functions wrapped by a single @ or a double @@?

From the wiki page I get the impression it is double, while the code shows single.

@@curNS(arg)@@@@getNS(arg)@@@@noNS(arg)@@@@p_get_first_heading(arg)@@ Will be replaced with a result of the corresponding dokuwiki function. arg can be both a static value, eg. @curNS(some:test:value)@ or the placeholder of a field, eg. @p_get_first_heading(@@field@@)@.
solewniczak commented 5 years ago

Should be single. I've just fixed it in the documentation.