Permalink
Browse files

add component.json

  • Loading branch information...
1 parent e7b7c78 commit e137b5ab4f9ab5dba24b719a5aae9678bf1ab7a5 @tj tj committed Sep 5, 2012
Showing with 90 additions and 85 deletions.
  1. +7 −0 component.json
  2. +83 −1 index.js
  3. +0 −84 lib/minstache.js
View
@@ -0,0 +1,7 @@
+{
+ "name": "minstache",
+ "version": "0.0.1",
+ "description": "Mini mustache template engine",
+ "keywords": ["mustache", "template", "engine"],
+ "scripts": ["index.js"]
+}
View
@@ -1,2 +1,84 @@
-module.exports = require('./lib/minstache');
+/**
+ * Expose `render()`.`
+ */
+
+exports = module.exports = render;
+
+/**
+ * Expose `compile()`.
+ */
+
+exports.compile = compile;
+
+/**
+ * Render the given mustache `str` with `obj`.
+ *
+ * @param {String} str
+ * @param {Object} obj
+ * @return {String}
+ * @api public
+ */
+
+function render(str, obj) {
+ obj = obj || {};
+ var fn = compile(str);
+ return fn(obj);
+}
+
+/**
+ * Compile the given `str` to a `Function`.
+ *
+ * @param {String} str
+ * @return {Function}
+ * @api public
+ */
+
+function compile(str) {
+ var js = [];
+ var toks = parse(str);
+ var tok;
+
+ for (var i = 0; i < toks.length; ++i) {
+ tok = toks[i];
+ if (i % 2 == 0) {
+ js.push('"' + tok.replace(/"/g, '\\"') + '"');
+ } else {
+ if (!tok.match(/^[\w.]+$/)) throw new Error('invalid property "' + tok + '"');
+ js.push(' + escape(obj.' + tok + ') + ');
+ }
+ }
+
+ js = js.join('').replace(/\n/g, '\\n');
+ js = escape.toString().replace(/^/gm, ' ') + ';\n return ' + js;
+
+ return new Function('obj', js);
+}
+
+/**
+ * Parse `str`.
+ *
+ * @param {String} str
+ * @return {Array}
+ * @api private
+ */
+
+function parse(str) {
+ return str.split(/\{\{|\}\}/);
+}
+
+/**
+ * Escape the given `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+function escape(html) {
+ return String(html)
+ .replace(/&/g, '&amp;')
+ .replace(/"/g, '&quot;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+}
View
@@ -1,84 +0,0 @@
-
-/**
- * Expose `render()`.`
- */
-
-exports = module.exports = render;
-
-/**
- * Expose `compile()`.
- */
-
-exports.compile = compile;
-
-/**
- * Render the given mustache `str` with `obj`.
- *
- * @param {String} str
- * @param {Object} obj
- * @return {String}
- * @api public
- */
-
-function render(str, obj) {
- obj = obj || {};
- var fn = compile(str);
- return fn(obj);
-}
-
-/**
- * Compile the given `str` to a `Function`.
- *
- * @param {String} str
- * @return {Function}
- * @api public
- */
-
-function compile(str) {
- var js = [];
- var toks = parse(str);
- var tok;
-
- for (var i = 0; i < toks.length; ++i) {
- tok = toks[i];
- if (i % 2 == 0) {
- js.push('"' + tok.replace(/"/g, '\\"') + '"');
- } else {
- if (!tok.match(/^[\w.]+$/)) throw new Error('invalid property "' + tok + '"');
- js.push(' + escape(obj.' + tok + ') + ');
- }
- }
-
- js = js.join('').replace(/\n/g, '\\n');
- js = escape.toString().replace(/^/gm, ' ') + ';\n return ' + js;
-
- return new Function('obj', js);
-}
-
-/**
- * Parse `str`.
- *
- * @param {String} str
- * @return {Array}
- * @api private
- */
-
-function parse(str) {
- return str.split(/\{\{|\}\}/);
-}
-
-/**
- * Escape the given `html`.
- *
- * @param {String} html
- * @return {String}
- * @api private
- */
-
-function escape(html) {
- return String(html)
- .replace(/&/g, '&amp;')
- .replace(/"/g, '&quot;')
- .replace(/</g, '&lt;')
- .replace(/>/g, '&gt;');
-}

0 comments on commit e137b5a

Please sign in to comment.