jud-templater
0.0.4 • Public • Published Jud <template>
Transformer
Features
- convert a
<template>
element to JSON-like object
- autofix common mistakes & friendly warnings
- tag name
- attr
- text content
- parse data binding and expressions
- make sure only one root node
API
parse(code, done)
validate(json, done)
function parse(code, done) {}
function validate(json, done) {}
function done(err, data) {}
Validation
- root check: only one root element (ignore others)
- tagname check: native or hyphenated (autofix or warn non-hyphenated custom tagname)
- child/parent check: elements required certain child/parent (error)
- attr value check: special tag[attr] value (error or autofix or warn)
- text content check: only text element allows text content (error)
- data binding check:
- normal value (exp converting)
- event: non-mustache -> mustache (autofix)
- style:
k: {{v}}; ...
(styler.validate
needed)
- class:
a {{v}} c
Demo
var templater = require('jud-templater')
var code = '<template><container><text>Hello</text><img class="a {{x}} c" src="{{y}}" /><image style="opacity: {{z}}"></image></container></template>'
templater.parse(code, function (err, data) {
err
data.jsonTemplate
data.deps[]
data.log[]
})
var json = {
type: 'container',
children: [
{
type: 'text',
value: 'Hello'
},
{
type: 'image',
class: 'a {{x}} c',
attr: {
src: '{{y}}'
}
},
{
type: 'img',
style: {
opacity: '{{z}}'
}
}
]
}
Package Sidebar
Install
Weekly Downloads