JSPM

remixml

1.0.13
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 738
  • Score
    100M100P100Q82262F
  • License (ISC OR GPL-3.0)

XML/HTML-like macro language/template engine

Package Exports

  • remixml

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remixml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Remixml

Remixml is an XML/HTML macro language/template engine.

The language and primitives used blend in completely with standard XML/HTML syntax and therefore integrate smoothly with existing XML/HTML syntax colouring editors.

Requirements

It runs inside any webbrowser environment (starting at IE11 and up).

The engine uses browser primitives to accellerate parsing; most notably it uses documentFragments and will therefore have trouble running in a plain NodeJS environment.

Basic usage

In essence Remixml is a macro language that has HTML/XML-like syntax and uses special entities to fill in templates. The entities that are recognised by Remixml are always of the form: &scope.varname; I.e. they distinguish themselves from regular HTML entities by always having at least one dot in the entity name.

The following sample code will illustrate the point:

Remixml.parse('<h1>Title of &_.sitename; for &_.description;</h1>'
  + '<p at="&anything.whatever;"> Some global variables &var.some; '
  + 'or &var.globalvars; or'
  + ' &var.arrays.1; or &var.arrays.2; or &var.objects.foo; or '
  + '&anything.really;',
 {_: {
    sitename: "foo.bar",
    description: "faster than lightning templates"
  },
  var: {
    some: "other",
    globalvars: 7,
    arrays: ["abc", 14, "def"],
    objects: {"foo":"bar", "indeed":"yes"}
  },
  anything: {
    really: "other",
    whatever: 7
  }
 });

Reference documentation

Full entity syntax

&scope.variablename:encoding%formatting;

  • scope:
    References the primary level in the variables object (the second argument to parse()).
  • variablename:
    References second and deeper levels in the variables object (can contain multiple dots to designate deeper levels, is used to access both objects and arrays).
  • encoding (optional):
    Specifies the encoding to be used when substituting the variable. The encodings available are:
    • html<br/ > Default, encodes using HTML entities.
    • uric<br/ > URI component, encodes URI arguments in an URL.
    • json<br/ > Encodes as a JSON string.
    • none<br/ > No encoding, as is, can be abbreviated as ":;".
  • formatting (optional):
    printf()-like formatting specification .
    Supported formats: %c, %d, %e, %f, %g, %s, %x.
    If the formatting string equals a three-letter currency (all capitals), the value will be formatted like a currency (including currency symbol) in the current locale.

Language statements

Simple assigment:

<set var="_.variablename">the new value</set>

Simple calculations:

<set var="_.variablename" expr="_.variablename + 1"></set>

Conditionals:

<if expr="_.variablename > 1">
 yes
</if>
<elif expr="_.variablename == 'foobar'">
 second condition valid
</elif>
<else>
 otherwise
</else>

Counted loop:

<for from="1" to="42">
 This is line &_._recno;<br />
</for>

Iterating through an object or array:

<for in="&_.variablename;">
 This is line &_._recno;<br />
</for>

API

Reserved object variables

  • $.sys.lang
    If set, it overrides the default locale of the browser environment (currently only used during currency formatting).

References

Soon to be launched: