Giter Site home page Giter Site logo

gulp-inline-template's Introduction

gulp-inline-template

Inline template into js file as string or function.

Usage

use __inline(filePath) to inline template to js file as string (Only relative path support);

use __template(filePath) to inline ejs template to js file as function (Only relative path support);

Example

<!-- content.tpl -->
<ul class="ul">
	<% for(var i=0;i<data.list.length;i++) { %>
	<li><%=data.list[i]%></li>
	<% } %>
</ul>
var a = __inline("./content.tpl")
var b = __template("./content.tpl")

//after compile:
var a = "<ul class=\"ul\">\n\t<% for(var i=0;i<data.list.length;i++) { %>\n\t<li><%=data.list[i]%></li>\n\t<% } %>\n</ul>\n";
var b = function(data,escape
/**/) {
escape = escape || function (markup) {
  return markup == undefined
    ? ''
    : String(markup)
        .replace(_MATCH_HTML, encode_char);
};
var _ENCODE_HTML_RULES = {
      "&": "&amp;"
    , "<": "&lt;"
    , ">": "&gt;"
    , '"': "&#34;"
    , "'": "&#39;"
    }
  , _MATCH_HTML = /[&<>'"]/g;
function encode_char(c) {
  return _ENCODE_HTML_RULES[c] || c;
};
;
  var __output = [], __append = __output.push.bind(__output);
    ; __append("<ul class=\"ul\">\n	")
    ;  for(var i=0;i<data.list.length;i++) { 
    ; __append("\n	<li>")
    ; __append(escape(data.list[i]))
    ; __append("</li>\n	")
    ;  } 
    ; __append("\n</ul>\n")
  return __output.join("");

}

gulp-inline-template's People

Contributors

loviselu avatar

Stargazers

zhengji avatar RJ avatar Chestnut Chen avatar plusice avatar  avatar

Watchers

James Cloos avatar  avatar

gulp-inline-template's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.