Pijemont is a system for generating an HTML form and markdown documentation from a JSON dictionary specifying the desired arguments.
The Pijemont constructor is:
Pijemont(container_form, api_dict, name, target, submit_callback, function_name)
container_form
is an empty form Element object on the page that will be populated with the form contentsapi_dict
is either the actual API dictionary or else a url that will provide this dictionary in response to a GET requestname
is any identifier for the form, and should be unique among all Pijemont instances on the pagetarget
is the url to which the form data should be POSTedsubmit_callback
is a function that will be passed the response data of the submit POST requestfunction_name
is the name of the API function from the provided API that should be used to generate the form
So, for example:
<form enctype="multipart/form-data" id="demo"></form>
<script>
new Pijemont(document.getElementById("demo"), "/api", "example_form", "/submit_url", function(data){console.log(data);}, "function_name");
</script>
will make a GET request to /api for the API dictionary, will place it into the empty form object supplied in the first argument.
Of course, one can replace "/api" with an actual dictionary and generate the form that way.
To generate Markdown documentation, simply run:
python2 doc.py http://url_of_api_dict
and this will output Markdown documentation to stdout. Note that this script assumes Python 2.7.
The API dictionary is assumed to have its keys being the names of the various API functions, and values being "type specification" dictionaries, which we will define now.
A type specification in Pijemont is a dictionary, which may look slightly different depending on the type of argument desired. It may contain the following keys:
-
type
: This key is required. Its value is a string that specifies what type of object the argument is. It can be any of those types listed below. -
description
: A string that describes what the argument is. Used for documentation generation and annotating the form. This key is optional. -
optional
: This is eithertrue
orfalse
(default isfalse
), and indicates whether this argument may be omitted -
default
: This is the value that will be used for the argument if it is not supplied (even if it is optional, so having bothoptional: true
and adefault
value is redundant). -
values
: If the type is a container for other types (e.g. a list or dictionary), then this will be a further type specification of the contained values. If the type is a non-container (such as a string or number), then
Some of these keys have type-specific behaviour, which we shall describe in each case when we specify the types below.
values
: May be a specification of conditions that the numbers must satisfy, such asvalues: "(>2 & <3) | <=-1 | (>100 & !=108.6)"
to say that the number must satisfy one of the conditions "between 2 and 3", "at most -1", and "bigger than 100 but not equal to 108.6". All symbols can be replaced with letter versions,gt
for>
, etc, so this condition could equally have been expressed:values: "(gt 2 and lt 3) or lteq -1 or (gt 100 and noteq 108.6)"
.
The form input for this argument will be a numeric input text field.
Corresponds to a string input.
values
: May be absent or may be a list of strings.
If type is str
or string
, then if the values
key is absent,
arbitrary strings are allowed and the corresponding form input will be
a text field. If values
is a list of strings, then the input will
be a select with each of the list items as options.
, the HTML form will be a textfield. If
multiline
, it will be a textarea.
-
values
: Should be omitted. -
default
: A default boolean value,true
orfalse
.
In the HTML form, this will show up as a checkbox.
This corresponds to an list argument where all elements are of a fixed, specified type.
-
values
: Should be a type specifier dictionary describing the type of each list element. -
default
: A list of objects that are valid defaults for the type of the list element. May be omitted.
This will generate the appropriate form for the given type specifier dictionary and will allow the user to add or remove these objects from the list at will.
This corresponds to an dictionary argument with specified keys where each corresponding value has a specified type.
-
values
: Should be a dictionary whose keys are strings and whose values are type specifier dictionaries. -
default
: A dictionary of objects whose keys are a subset of the keys invalues
and whose values are valid default values for the corresponding type specifiers. May be omitted.
This will generate, for each key, the appropriate form for the corresponding type specifier dictionary.
This corresponds to a list argument with a fixed number of values, each of which is of a specified type (and the types for the different values may differ).
-
values
: Should be a dictionary whose keys are increasing integers starting from 0, and whose values are type specifier dictionaries. -
default
: A dictionary of objects whose keys are a subset of the keys invalues
and whose values are valid default values for the corresponding type specifiers. May be omitted.
This will generate, for each key, the appropriate form for the corresponding type specifier dictionary.
This specified multiple named arguments where exactly one of them should be present
values
: Should be a dictionary whose keys are strings and whose values are type specifier dictionaries.default
: A dictionary of objects whose keys are a subset of the keys invalues
and whose values are valid default values for the corresponding type specifiers. May be omitted.
This will generate, for each key, the appropriate form for the corresponding type specifier dictionary, and a radio button allowing the user to select which single one of the inputs they wish to provide.
This corresponds to an input that can be any object and whose value is unchecked
values
: Should be omitteddefault
: May be any object
For any
or stuff
types, this will generate a textarea form
element. For file
types, this will generate a file upload widget in
the HTML form that will send the base64-encoded file contents.