0.1.2 • Published 8 years ago

plaintemplate-parse v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Roll your own Mustache-like plaintext template language with custom syntax.

var parse = require('plaintemplate-parse')
var assert = require('assert')

assert.deepEqual(
  parse(
    // Template input
    '(( five { ))Howdy, (( = name ))! (( } ))',
    // Use custom double-parentheses template tags.
    { open: '((', close: '))', start: '{', end: '}' }),
  [ { tag: 'five',
      position: { line: 1, column: 1 },
      content: [
        { text: 'Howdy, ',
          position: { line: 1, column: 13 } },
        { tag: '= name',
          position: { line: 1, column: 20 } },
        { text: '! ',
          position: { line: 1, column: 32 } } ] } ])

The package exports a single function returning arrays of token objects for text and template tag tokens, of two arguments:

  1. Input, a string, containing the template text to parse
  2. Delimiters, an object with the following keys specifying the syntax for template tags:
    1. open, "<%" by default
    2. close, "%>" by default
    3. start, "{" by default
    4. end, "}" by default