0.99.7 • Published 5 years ago

composium v0.99.7

Weekly downloads
15
License
SEE LICENSE IN li...
Repository
-
Last release
5 years ago

Composium™

Ultra-fast, lightweight, general purpose composition engine for Node.js

$ npm i composium

Composium is an easily and incrementally adoptable ultra fast and lightweight general purpose composition engine that targets the Node.js platform as an NPM module.

Unlike templating engines, Composium does not require the use of a templating paradigm and supports advanced logic using ECMAScript and optionally Node.js modules.

  • Clear separation of presentation and logic
  • Full presentation and logic support in included templates

Quickstart

Contrived example referencing data with no logic:

const composium = require('composium')

let template = '<presentation>Hi <data>firstName</data>!</presentation>'
composium.loadTemplate('Hi Template', template)

let output = composium.compose('Hi Template', { firstName: 'Sam' })

Template format

Templates are comprised of a presentation tag and/or a script tag for logic and for explicit manipulation of the output.

<script>
    let name = (data.firstName) ? data.firstName | 'world'
</script>

<presentation>
    <p>Hello <variable>name</variable>!</p>
<presentation>

Presentation tag

The presentation tag contains a tag-based logicless template for merging copy with data and variables created in a corresponding script tag.

  • Required when script tag is absent
  • White space is preserved
  • Data and variable value encoding can be specified optionally with a profile

Quick guide | Tag | Use | | ------ | ------ | | data | <data>name</data> | | else | <if condition="condition">...<else>...</else></if>| | for | <for each="item" in="items">...</for>| | if | <if condition="condition">...</if>| | include | <include>name</include>| | variable | <variable>name</variable |

Script tag

The script tag contains ECMAScript for template logic and for optionally manipulating the output explicitly.

  • Required when presentation tag is absent

Any variable created in the script tag can be referenced by the variable tag in the presentation.

Quick guide | Object | Use | | ------ | ------ | | data | data.property[.property] etc | | include | include('templateName') | | output | output.clear() | | output | output.set('string') | | output | output.toString() | | profile | profile.property[.property] etc | | require | require('moduleName') | | workspace | workspace.get('name') | | workspace | workspace.set('name',object) |

Profile

The profile provides a mechanism for externalizing behavior for a single compose call.

  • A profile is not required
  • Encoding settings for data and variables (defaults to none)
  • Before/After compostion to optionally invoke specified template(s) by name
  • Properties can be referenced within logic to customize behavior

Quick guide

{
    name: 'Profile name',
    variableEncoding: 'none/xml/html',
    dataEncoding: 'none/xml/html',
    beforeComposition: ['Template name'],
    afterComposition: ['Template name'],
    properties: {
        samplePropertyName: 'samplePropertyValue'
    }
}

Coming soon!

  • Custom tags
  • Enhanced encoding support
  • Data and variable defaulting
  • Variable prefix whitelisting
  • More...
0.99.7

5 years ago

0.99.7-beta

5 years ago

0.99.6-beta

5 years ago

0.99.5

5 years ago

0.99.4

5 years ago

0.99.3

5 years ago

0.99.2

5 years ago

0.99.1

5 years ago

0.99.0

5 years ago