Permalink
Browse files

Function names withing dynamic expansion (fixes #2)

  • Loading branch information...
1 parent 0c0cf43 commit 7093c24b47ce60051f2a67d4a215d087b96660a7 @eprev committed May 24, 2013
View
@@ -1,3 +1,5 @@
+v0.1.3
+ Support for function name within dynamic mappings
v0.1.2
Added option to name compiled function
v0.1.1
View
@@ -82,6 +82,16 @@ module.exports = function (grunt) {
options: {
name: 'foo'
}
+ },
+ named_function_withing_dynamic_expansion: {
+ files: [{
+ expand: true, // Enable dynamic expantion.
+ src: ['test/fixtures/qux/**/*.xml'],
+ dest: 'test/tmp/dynamic-named' // Destination path prefix.
+ }],
+ options: {
+ name: true
+ }
}
},
View
@@ -67,7 +67,7 @@ Compiled file’s extension.
Type: `String`
Default value: `undefined`
-Compiled function’s name.
+Compiled function’s name. The basename of the source file will be used if is set to True.
#### options.template
View
@@ -1,7 +1,7 @@
{
"name": "grunt-fest",
"description": "Compile Fest templates",
- "version": "0.1.2",
+ "version": "0.1.3",
"homepage": "https://github.com/eprev/grunt-fest",
"author": {
"name": "Anton Eprev",
View
@@ -53,8 +53,12 @@ module.exports = function (grunt) {
dest = dest.slice(0, -de.length) + options.ext;
}
grunt.log.write('Compiling "' + src + '" to "' + dest + '"...');
+ name = options.name;
+ if (name === true) {
+ name = basename(src, se);
+ }
try {
- contents = compile(src, extend({}, options.compile), options.name);
+ contents = compile(src, extend({}, options.compile), name);
} catch (e) {
grunt.log.writeln();
grunt.log.error(e.stack);
@@ -1,149 +0,0 @@
-function(__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\/bar\/baz.xml";
- __fest_debug_line = "0";
- __fest_debug_block = "fest:template";
- __fest_debug_file = "test\/fixtures\/qux\/bar\/baz.xml";
- __fest_debug_line = "1";
- __fest_debug_block = "fest:get";
- __fest_select = "block";
- __fest_params = {};
- try {
- __fest_params = Grunt
- } catch (e) {
- __fest_log_error(e.message)
- }
- __fest_chunks.push(__fest_buf, {
- name: __fest_select,
- params: __fest_params,
- cp: false
- });
- __fest_buf = "";
- __fest_debug_file = "test\/fixtures\/qux\/bar\/baz.xml";
- __fest_debug_line = "2";
- __fest_debug_block = "fest:set";
- __fest_blocks.block = function(params) {
- var __fest_buf = "";
- __fest_buf += ("Hello,");
- __fest_debug_file = "test\/fixtures\/qux\/bar\/baz.xml";
- __fest_debug_line = "3";
- __fest_debug_block = "fest:space";
- __fest_buf += (" ");
- __fest_debug_file = "test\/fixtures\/qux\/bar\/baz.xml";
- __fest_debug_line = "3";
- __fest_debug_block = "fest:value";
- try {
- __fest_buf += (__fest_escapeHTML(params))
- } catch (e) {
- __fest_log_error(e.message + "3");
- }
- __fest_buf += ("!");
- return __fest_buf;
- };
- __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;
- }
-}
@@ -1,113 +0,0 @@
-function(__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;
- }
-}
@@ -1,4 +1,4 @@
-function(__fest_context) {
+function baz(__fest_context) {
"use strict";
var __fest_self = this,
__fest_buf = "",
@@ -1,4 +1,4 @@
-function(__fest_context) {
+function foo(__fest_context) {
"use strict";
var __fest_self = this,
__fest_buf = "",
View
@@ -74,5 +74,13 @@ exports.bem = {
test.equal(actual, expected);
});
test.done();
+ },
+ named_function_within_dynamic_expansion: function (test) {
+ this.templates.forEach(function (tpl) {
+ var actual = grunt.file.read('test/tmp/dynamic-named/test/fixtures/' + tpl + '.js');
+ var expected = grunt.file.read('test/expected/tmp/dynamic-named/test/fixtures/' + tpl + '.js');
+ test.equal(actual, expected);
+ });
+ test.done();
}
};

0 comments on commit 7093c24

Please sign in to comment.