Permalink
Browse files

v0.1.2 (close #1)

  • Loading branch information...
1 parent 898e739 commit 21fd81eaa854b2886d056c83114dded56d79cff8 @eprev committed Mar 13, 2013
Showing with 164 additions and 6 deletions.
  1. +2 −0 CHANGELOG.md
  2. +7 −0 Gruntfile.js
  3. +26 −4 README.md
  4. +1 −1 package.json
  5. +7 −1 tasks/fest.js
  6. +113 −0 test/expected/tmp/named/foo.js
  7. +8 −0 test/fest_test.js
View
@@ -1,3 +1,5 @@
+v0.1.2
+ Added option to name compiled function
v0.1.1
Use of initial compile options
v0.1.0
View
@@ -75,6 +75,13 @@ module.exports = function (grunt) {
beautify: false
}
}
+ },
+ named_function: {
+ src: 'test/fixtures/qux/foo.xml',
+ dest: 'test/tmp/named/foo.js',
+ options: {
+ name: 'foo'
+ }
}
},
View
@@ -62,6 +62,13 @@ Default value: `.js`
Compiled file’s extension.
+#### options.name
+
+Type: `String`
+Default value: `undefined`
+
+Compiled function’s name.
+
#### options.template
Type: `Function`
@@ -89,16 +96,31 @@ grunt.initConfig({
debug: true
}
},
- put_in_the_same_derictory: { // Compiles "fest/**/*.xml" to "fest/**/*.js"
+
+ // Compiles "fest/**/*.xml" to "fest/**/*.js"
+ put_in_the_same_derictory: {
src: 'fest/**/*.xml'
},
- put_in_the_same_derictory_and_append_ext: { // Compiles "fest/**/*.xml" to "fest/**/*.xml.js"
+
+ // Compiles "fest/**/*.xml" to "fest/**/*.xml.js"
+ put_in_the_same_derictory_and_append_ext: {
src: 'fest/**/*.xml',
options: {
ext: '.xml.js'
}
},
- 'build': ['fest/**/*.xml'] // Compiles "test/**/*.xml" to "build/fest/**/*.js"
+
+ // Compiles "test/**/*.xml" to "build/fest/**/*.js",
+ 'build': ['fest/**/*.xml']
+
+ // Compiles "test/qux.xml" to named function and writes it to "build/qux.js"
+ v8: {
+ src: 'fest/qux.xml',
+ dest 'build/qux.js',
+ options: {
+ name: 'qux'
+ }
+ }
}
})
```
@@ -148,7 +170,7 @@ grunt.initConfig({
template: function (data) {
// Make AMD module
return grunt.template.process(
- 'define(<%= JSON.stringify(name + ".js") %>, function () { return <%= contents %> ; });',
+ 'define(<%= JSON.stringify(name) %>, function () { return <%= contents %> ; });',
{data: data}
);
},
View
@@ -1,7 +1,7 @@
{
"name": "grunt-fest",
"description": "Compile Fest templates",
- "version": "0.1.1",
+ "version": "0.1.2",
"homepage": "https://github.com/eprev/grunt-fest",
"author": {
"name": "Anton Eprev",
View
@@ -35,9 +35,15 @@ module.exports = function (grunt) {
f.src.forEach(function (src) {
var dest, relSrc, name, contents;
if (f.orig.expand) {
+ // dynamic mapping
dest = f.dest;
relSrc = f.orig.cwd ? relative(f.orig.cwd, src) : src;
+ } else if (f.orig.src.length === 1 && grunt.file.isFile(f.orig.src[0])) {
+ // file to file mapping
+ dest = f.dest;
+ relSrc = src;
} else {
+ // files to directory mapping
dest = f.dest ? join(f.dest, src) : src;
relSrc = src;
}
@@ -48,7 +54,7 @@ module.exports = function (grunt) {
}
grunt.log.write('Compiling "' + src + '" to "' + dest + '"...');
try {
- contents = compile(src, extend({}, options.compile));
+ contents = compile(src, extend({}, options.compile), options.name);
} catch (e) {
grunt.log.writeln();
grunt.log.error(e.stack);
@@ -0,0 +1,113 @@
+function foo(__fest_context) {
+ "use strict";
+ var __fest_self = this,
+ __fest_buf = "",
+ __fest_chunks = [],
+ __fest_chunk, __fest_attrs = [],
+ __fest_select, __fest_if, __fest_iterator, __fest_to, __fest_fn, __fest_html = "",
+ __fest_blocks = {},
+ __fest_params, __fest_element, __fest_debug_file = "",
+ __fest_debug_line = "",
+ __fest_debug_block = "",
+ __fest_htmlchars = /[&<>"]/g,
+ __fest_short_tags = {
+ "area": true,
+ "base": true,
+ "br": true,
+ "col": true,
+ "command": true,
+ "embed": true,
+ "hr": true,
+ "img": true,
+ "input": true,
+ "keygen": true,
+ "link": true,
+ "meta": true,
+ "param": true,
+ "source": true,
+ "wbr": true
+ },
+ __fest_element_stack = [],
+ __fest_htmlhash = {
+ "&": "&amp;",
+ "<": "&lt;",
+ ">": "&gt;",
+ "\"": "&quot;"
+ },
+ __fest_jschars = /[\\'"\/\n\r\t\b\f<>]/g,
+ __fest_jshash = {
+ "\"": "\\\"",
+ "\\": "\\\\",
+ "/": "\\/",
+ "\n": "\\n",
+ "\r": "\\r",
+ "\t": "\\t",
+ "\b": "\\b",
+ "\f": "\\f",
+ "'": "\\'",
+ "<": "\\u003C",
+ ">": "\\u003E"
+ },
+ ___fest_log_error;
+ if (typeof __fest_error === "undefined") {
+ ___fest_log_error = (typeof console !== "undefined" && console.error) ?
+ function() {
+ return Function.prototype.apply.call(console.error, console, arguments)
+ } : function() {};
+ } else {
+ ___fest_log_error = __fest_error
+ };
+
+ function __fest_log_error(msg) {
+ ___fest_log_error(msg + "\nin block \"" + __fest_debug_block + "\" at line: " + __fest_debug_line + "\nfile: " + __fest_debug_file)
+ }
+ function __fest_replaceHTML(chr) {
+ return __fest_htmlhash[chr]
+ }
+ function __fest_replaceJS(chr) {
+ return __fest_jshash[chr]
+ }
+ function __fest_extend(dest, src) {
+ for (var i in src) if (src.hasOwnProperty(i)) dest[i] = src[i];
+ }
+ function __fest_param(fn) {
+ fn.param = true;
+ return fn
+ }
+ function __fest_call(fn, params, cp) {
+ if (cp) for (var i in params) if (typeof params[i] == "function" && params[i].param) params[i] = params[i]();
+ return fn.call(__fest_self, params)
+ }
+ function __fest_escapeJS(s) {
+ if (typeof s === "string") {
+ if (__fest_jschars.test(s)) return s.replace(__fest_jschars, __fest_replaceJS);
+ } else if (typeof s === "undefined") return "";
+ return s;
+ }
+ function __fest_escapeHTML(s) {
+ if (typeof s === "string") {
+ if (__fest_htmlchars.test(s)) return s.replace(__fest_htmlchars, __fest_replaceHTML);
+ } else if (typeof s === "undefined") return "";
+ return s;
+ }
+ __fest_debug_file = "test\/fixtures\/qux\/foo.xml";
+ __fest_debug_line = "0";
+ __fest_debug_block = "fest:template";
+ __fest_buf += ("Test");
+ __fest_to = __fest_chunks.length;
+ if (__fest_to) {
+ __fest_iterator = 0;
+ for (; __fest_iterator < __fest_to; __fest_iterator++) {
+ __fest_chunk = __fest_chunks[__fest_iterator];
+ if (typeof __fest_chunk === "string") {
+ __fest_html += __fest_chunk;
+ } else {
+ __fest_fn = __fest_blocks[__fest_chunk.name];
+ if (__fest_fn) __fest_html += __fest_call(__fest_fn, __fest_chunk.params, __fest_chunk.cp);
+ }
+ }
+ return __fest_html + __fest_buf;
+ } else {
+ return __fest_buf;
+ }
+}
View
@@ -66,5 +66,13 @@ exports.bem = {
test.equal(actual, expected);
});
test.done();
+ },
+ named_function: function (test) {
+ ['foo'].forEach(function (tpl) {
+ var actual = grunt.file.read('test/tmp/named/' + tpl + '.js');
+ var expected = grunt.file.read('test/expected/tmp/named/' + tpl + '.js');
+ test.equal(actual, expected);
+ });
+ test.done();
}
};

0 comments on commit 21fd81e

Please sign in to comment.