0.1.0 • Published 10 years ago

mew-template v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 years ago

mew-template

precompile template to a cmd module, support jst doT Handlebars xtemplate

Install

npm install mew-template

Usage

var template = require('mew-teplate');
var html = template(tmplContent, options);

options = {
    engine: 'dot', // dot jst handlebars xtemplate
    syntax: '{{}}' // {{}} or <%%>  only works with dot & jst
 }

Sample

template

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{{= it.title }}</title>
</head>
<body>
    <h1>Hello,{{= it.name }}</h1>

    <h2>Condition</h2>
    {{? it.name.length }}
    <p>{{= it.name }} is a good name</p>
    {{? }}

    <h2>Array</h2>
    <ul>
    {{~ it.skills :val:idx}}
    <li>{{= idx }}. {{= val }}</li>
    {{~ }}
    </ul>
</body>
</html>

compiled

define(function() {
    var template = function anonymous(it) {
        var out = '<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>' + (it.title) + '</title></head><body> <h1>Hello,' + (it.name) + '</h1> <h2>Condition</h2> ';
        if (it.name.length) {
            out += ' <p>' + (it.name) + ' is a good name</p> ';
        }
        out += ' <h2>Array</h2> <ul> ';
        var arr1 = it.skills;
        if (arr1) {
            var val, idx = -1,
                l1 = arr1.length - 1;
            while (idx < l1) {
                val = arr1[idx += 1];
                out += ' <li>' + (idx) + '. ' + (val) + '</li> ';
            }
        }
        out += ' </ul></body></html>';
        return out;
    }
    return {
        render: function(data) {
            return template(data || {});
        }
    };
});

Test

make test
0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago