DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:jsongendoc

JSON Generate Document Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Integrate "Generate new document" JSON based functionality into json plugin.

Last updated on
2023-10-26
Provides
Syntax, Action
Repository
Source
Requires
json

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Install also JSON plugin.

Description

JSON Generate Document Plugin is based on JSON plugin. It adds a form with a button to the page. User can select the JSON data and enter the name for the new document. When user presses the button, new text based document is generated, which is based on specified template. Patterns @ … @ inside template are replaced by corresponding JSON data. Also sections from template are hidden or displayed according to condition calculated from JSON data.

Newly created document can the be saved as a Dokuwiki page to the server, or it can be downloaded via browser to the client machine. It is possible to generate and download any text based document, for example txt, html, svg, cvs, …

Here is a Dokuwiki JSON Demo Server with JSON database integrated into DokuWiki. Also source code of this plugin contains demo. You can copy the contents of the demo files into your Dokuwiki and experiment with them.

Support

For issues or just questions use Issues on Gitlab. Please don't email directly.

Template

Template is basically a dokuwiki page, which may have some @ … @ patterns, which will be replaced by JSON data. There are three types of pattern:

Pattern Description
@ … @ Standard patterns from Namespace Templates.
@%$-start( filter )% dokuwiki_section %$end%@ If filter (see JSON Data Plugin) is evaluated to true, then dokuwiki_section will be added to the document, otherwise it will be removed.
@%$ path %@ Variable on path is type of string, number or boolean. Extract data.
Variable on path is type of array. Extract json.
Variable on path is undefined. Extract null.

Usage

Syntax is similar as in JSON Data Plugin:
<jsongendoc attributes > inline_json </jsongendoc>

It is parsed with same parser as <json> elements, so rules for attributes and inline_json are the same. It loads JSON data the same way, from src attribute and from inline_json. It only has some extra attributes, additional render and additional action.

This syntax generates a form with the following fields:

  • Select box - Select box is generated from JSON data, if it contains array of similar data objects.
  • Inpit field - User enters a name for the new document into the input field.
  • Button - After user presses a button, a command is sent to the server. If there are no errors, then new Document is generated from template and JSON data. Document is either stored to the server or offered for download. Server returns information about success or failure, which are displayed below the form.

Attribute 'mime'

If this attribute is omitted or it is empty string, then newly generated file will be stored to the server as a new Dokuwiki page. Otherwise it must contain Mime type of the Document, which will be downloaded. For example: text/plain, text/html, text/csv, image/svg+xml, application/json, application/xml, etc.

Attribute 'namespace'

It specifies the namespace (location) for the template and for the new document(if mime is undefined). If it is not specified, then current location is used. If a docname or template attribute contains full file path, then namespace attribute is ignored.

Attribute 'template'

It specifies the template file. If template is not specified, then Namespace Template is used.

Attribute 'docname'

If specified, then it will be shown in Inpit field as default for the new document name. If value has some hashes at the end, they will be replaced with auto incrementing number. For example docname=my_doc_#### will set the value of Input field to something like 'my_doc_0022'.

Attribute 'select'

This attribute is optional. It specifies the options inside the Select box. JSON data must be an array with similar data objects.

'select' attribute contains a comma separated list of key: path pairs, where key is number in sequence and path is a path to variable from array element. Those key/path pairs specifies the name of the option for each array element inside the Select box. Example: select='0:name, 1:type, template:path.to.template'.

If this attribute is not specified, then Select box is not shown. Complete JSON data are passed to the template.

plugin/jsongendoc.txt · Last modified: 2023-10-31 20:53 by 89.143.166.90

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki