TemplateBase API¶
These are the public methods of the TemplateBase class.
Attributes¶
snippets
: A dictionary of snippets extracted by reading your previously generated file
Methods¶
create_file()
¶
This method creates a new output file It also creates all the missing directories and extract snippets from the file if it exists.
Parameters:
- `full_path`: The full path of the file to create
- `mod`: The module that is being processed
- `keep_all_snippets`: If true, all snippets read in previous runs will be kept. If false, only the snippets that are in the current file will be kept.
See also: extract_snippets()
endpoint_mk_function()
¶
This method returns the Endpoint unique function name, composed by the endpoint name and the method.
See also: valid_function_name()
extract_snippets()
¶
Extracts all the code you have written in the file fname
and stores it in the snippets
dictionary.
The code extracted is the one between the f2c_start
and f2c_end
comments.
See Populating the Hexocode for more information.
Parameters:
mod
: The current Module we are working onfname
: The name of the file to be read and parsed
Note
You usually do not call this method directly, but it is implicitly called with the create_file() method.
### join_newlines()
This is a helper method that joins a list of strings into a single string, with a newline character between every num_elems
elements.
This is very useful when you want to create a list of imports, for example.
mk_documentation()
¶
mk_documentation ( self, main_doc: str, params_doc: list[str], ret_name: str, ret_type: str, ret_doc: str, TEMPL: dict[str,str] ) -> str:
This method creates the documentation string from the parameters passed.
Parameters:
main_doc
: The main documentation string.params_doc
: A list of strings, each of which is a parameter documentation string.ret_name
: The name of the return value.ret_type
: The type of the return value.ret_doc
: The documentation string for the return value.TEMPL
: A dictionary of strings, each of which is a template for a parameter documentation string.
See also: params_and_doc()
mod_name()
¶
Returns the name of the module in snake_case
format.
params_and_doc()
¶
params_and_doc ( self, fn: Endpoint | Function, TEMPL: dict[str,str], honour_float: bool = True ) -> tuple[list[str],list[str]]:
This method returns a tuple with two elements:
- A list of strings, each of which is a parameter declaration string.
- A list of strings, each of which is a parameter documentation string.
Parameters:
fn
: The function or endpoint to be documented.TEMPL
: A dictionary of templates.honour_float
: IfTrue
, thefloat
type will be treated asfloat
.
See also: mk_documentation()
prepare_field()
¶
prepare_field ( self, field: Field, template: str, template_obj: str, honour_float: bool = False, use_enums: bool = False ) -> str:
This method applies the template
or template_obj
to the field, depending on the type of the field, and returns a string with the result.
Parameters:
- field
: The field to be used to create the string.
- template
: The template to use.
- template_obj
: The template to use for objects.
- honour_float
: If True
, the float
types will be kept, if False
, they will be converted to int
.
- use_enums
: If True
, the template
will use Enums instead of strings.
valid_function_name()
¶
Returns the passed name
as a valid function name, stripping all the invalid characters