gulp-mejs
Mejs plugin for gulp
Mejs -- Moduled and Embedded JavaScript templates
Install
Install with npm
npm install --save-dev gulp-mejs
Usage
var gulpMejs = gulp gulp gulp
options and Mejs class API: https://github.com/teambition/mejs
Demo
test/fixtures/header.html
:
<%= it.title || 'gulp' %> module<%- include('user', it.user) %>
test/fixtures/user-list.html
:
<% it.users.forEach(function(user) { -%> <%= user.name %> <% }) -%>
test/fixtures/user.html
:
<%= it.name %>
precompile to test/templates.js
(Run it in node.js/io.js/browers):
// **Github:** https://github.com/teambition/mejs//// **License:** MIT/* global module, define, window */ // Mejs is a compiled templates class, it can be run in node.js or browers ; { 'use strict' if typeof module === 'object' && moduleexports moduleexports = else if typeof define === 'function' && defineamd else rootMejs = }typeof window === 'object' ? window : this { 'use strict' var hasOwn = ObjectprototypehasOwnProperty var templates = {} var htmlEscapes = '&': '&' '<': '<' '>': '>' '"': '"' "'": ''' '`': '`' { thislocals = locals || {} thistemplates = } Mejs { return this } var proto = Mejsprototype protocopy = copy proto { var template = this if typeof template !== 'function' throw tplName + ' is not found' return template } proto { return hasOwn ? thistemplatestplName : null } proto { if !overwrite && hasOwn throw tplName + ' exist' thistemplatestplName = tplFn return this } proto { delete thistemplatestplName return this } proto { if typeof ns !== 'string' overwrite = mejs mejs = ns ns = '/' else ns = ns for var tplName in mejstemplates if hasOwn this return this } proto { parent = this current = this current = /^\// && !/\/$/ ? current : parent + current current = current while /\/\.\.\// current = current return current } proto { return this } proto { return str == null ? '' : Stringstr } { dst = dst || {} for var key in src if hasOwn && overwrite || !hasOwn dstkey = srckey return dst } templates'header' = { var ctx = this __output = "" var { return ctx } ;__output += "<p class=\"test\">";;__output += ctx;__output += " module</p>\n";;__output += ctx;__output += "\n"; return __output }; templates'user-list' = { var ctx = this __output = "" ;__output += "<ul>\n ";;itusers ;__output += "</ul>\n"; return __output }; templates'user' = { var ctx = this __output = "" ;__output += "<h1>";;__output += ctx;__output += "</h1>\n"; return __output }; return Mejs}
License
MIT © Teambition