Tag¶
- class exporter.tag.Tag(gdocs, dataset_id)[source]¶
A tag for inserting content into a template.
- Parameters:
gdocs (Gdocs) – a Google API client
dataset_id (int) – the dataset’s ID
- argument_validators: Dict[str, Callable[[str], bool]] = {}¶
A mapping of argument names to validation functions.
- argument_converters: Dict[str, Callable[[str], Any]] = {}¶
A mapping of argument names to conversion functions.
- set_argument(name, value)[source]¶
Set an argument.
The argument’s name is checked against declared arguments, and its value is checked with the declared validator, if any. Its value is converted with the declared converter, if any.
- Parameters:
- Raises:
TagArgumentError – if the name is unrecognized or the value is invalid
- Return type:
None
- finalize_arguments()[source]¶
Set unused arguments to default values.
- Raises:
TagArgumentError – if a value is invalid
- Return type:
None
- validate_and_render(data)[source]¶
Check for missing arguments, and call and return
render()
.- Raises:
MissingArgumentError – if arguments are missing
- Parameters:
- Return type:
- class exporter.tag.LeafTag(gdocs, dataset_id)[source]¶
A leaf tag renders itself, using the data (“context”) provided by a template tag.
- Parameters:
gdocs (Gdocs)
dataset_id (int)
- class exporter.tag.TemplateTag(gdocs, dataset_id)[source]¶
A template tag renders a template, stored as a document in Google Docs. The template can contain sub-tags.
- Parameters:
gdocs (Gdocs) – a Google API client
dataset_id (int) – the dataset’s ID
- get_tags_mapping(texts)[source]¶
Extract and instantiate the tags in the template.
Also return the names of any checks that cannot be computed. The corresponding tags are replaced with
error template tags
.- Parameters:
texts (List[Element]) – the text nodes from the template that contain tags
- Raises:
TagSyntaxError – if a sub-tag is malformed
UnknownTagError – if a sub-tag’s name is unrecognized
TagArgumentError – if a sub-tag’s argument is invalid
- Return type:
- render(data)[source]¶
Read the template’s content, extract its sub-tags, recursively call the sub-tags’
validate_and_render()
method, and merge the results into the content.- Parameters:
data (Dict[str, Any]) – the data (“context”) provided by another template tag
- Raises:
MissingArgumentError – if a leaf tag’s argument is missing
ValueError – if a leaf tag’s
render()
method has an invalid return valueTagError – if a template tag or its sub-tags caused an error
- Return type:
- class exporter.tag.TagExpression(name, arguments)[source]¶
A representation of the tag as expressed in the template.
- classmethod parse(string)[source]¶
Parse the string as a tag.
- Parameters:
string (str) – the full tag, starting with
{%
- Raises:
TagSyntaxError – if the tag is malformed
- Return type:
- exporter.tag.template(_name, _default_template, _tags)[source]¶
Build a
TemplateTag
by decorating aget_context()
implementation.
- exporter.tag.argument(name, default=None, required=False, choices=None, type=None, nonzero=False)[source]¶
Add an argument to the tag.
- exporter.tag.generate_error_template_tag(message)[source]¶
Build a
TemplateTag
for the error template and set the errormessage
.- Parameters:
message (str)
- Return type: