1.0.0 • Published 6 years ago

@idrinth/simple-templating v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Simple Templating

This small library provides minimal templating options for javascrpt in multiple enviroments, have a look at /min to see the options.

TypeStatus
BuildBuild Status
CoverageTest Coverage Codacy Badge
QualityCodacy Badge
MaintainabilityMaintainability

Values

assume the following values: {key: 'value', keys:{key:2}

{{key}} will be replaced by value, {{keys.key}} will be replaced by 2

Logic

logic blocks may contain other logic blocks.

IF

{%if check%}This shows if the boolean value of check is true.{{%end%}}
{%if !check%}This shows if the boolean value of check is false.{{%end%}}
{%if !check.property%}This shows if the boolean value of check.property is false.{{%end%}}

This does not support more than one variable. You can invert the check by adding an exclamation mark in front of the condition tho.

EACH

{%each list%}- {{_list.key}}: {{_list.value}}{%end%}

Each iterates over Objects and Arrays, exposing an object with the following properties within the loop:

  • key: the position in case of an array or the property name in case of other objects
  • pos: the position integer in the list, equal to list_key in the case of arrays
  • value: the value of the current item
  • even: a boolean, useful for conditions

The object's name is generated by prepending an underscrore to the name of the variable iterated over, so list will provide _list, list.sublist will provide _list#sublist.