handlebars 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -2
- data/README.mdown +15 -7
- data/handlebars.gemspec +2 -5
- data/lib/handlebars.rb +5 -5
- data/lib/handlebars/context.rb +3 -12
- data/lib/handlebars/version.rb +1 -1
- data/spec/handlebars_spec.rb +1 -1
- metadata +47 -58
- data/.gitmodules +0 -3
- data/vendor/handlebars/.gitignore +0 -8
- data/vendor/handlebars/.jshintrc +0 -52
- data/vendor/handlebars/.npmignore +0 -10
- data/vendor/handlebars/.rspec +0 -1
- data/vendor/handlebars/Gemfile +0 -5
- data/vendor/handlebars/LICENSE +0 -19
- data/vendor/handlebars/README.markdown +0 -317
- data/vendor/handlebars/Rakefile +0 -109
- data/vendor/handlebars/bench/benchwarmer.js +0 -149
- data/vendor/handlebars/bench/handlebars.js +0 -172
- data/vendor/handlebars/bin/handlebars +0 -193
- data/vendor/handlebars/dist/handlebars.js +0 -2201
- data/vendor/handlebars/dist/handlebars.runtime.js +0 -321
- data/vendor/handlebars/lib/handlebars.js +0 -14
- data/vendor/handlebars/lib/handlebars/base.js +0 -154
- data/vendor/handlebars/lib/handlebars/compiler/ast.js +0 -133
- data/vendor/handlebars/lib/handlebars/compiler/base.js +0 -21
- data/vendor/handlebars/lib/handlebars/compiler/compiler.js +0 -1267
- data/vendor/handlebars/lib/handlebars/compiler/index.js +0 -7
- data/vendor/handlebars/lib/handlebars/compiler/printer.js +0 -131
- data/vendor/handlebars/lib/handlebars/compiler/visitor.js +0 -13
- data/vendor/handlebars/lib/handlebars/runtime.js +0 -88
- data/vendor/handlebars/lib/handlebars/utils.js +0 -67
- data/vendor/handlebars/package.json +0 -35
- data/vendor/handlebars/spec/acceptance_spec.rb +0 -101
- data/vendor/handlebars/spec/parser_spec.rb +0 -433
- data/vendor/handlebars/spec/qunit_spec.js +0 -1370
- data/vendor/handlebars/spec/spec_helper.rb +0 -157
- data/vendor/handlebars/spec/tokenizer_spec.rb +0 -301
- data/vendor/handlebars/src/handlebars.l +0 -53
- data/vendor/handlebars/src/handlebars.yy +0 -109
- data/vendor/handlebars/src/parser-prefix.js +0 -1
- data/vendor/handlebars/src/parser-suffix.js +0 -4
@@ -1,131 +0,0 @@
|
|
1
|
-
var Handlebars = require("./base");
|
2
|
-
|
3
|
-
// BEGIN(BROWSER)
|
4
|
-
Handlebars.PrintVisitor = function() { this.padding = 0; };
|
5
|
-
Handlebars.PrintVisitor.prototype = new Handlebars.Visitor();
|
6
|
-
|
7
|
-
Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
|
8
|
-
var out = "";
|
9
|
-
|
10
|
-
for(var i=0,l=this.padding; i<l; i++) {
|
11
|
-
out = out + " ";
|
12
|
-
}
|
13
|
-
|
14
|
-
out = out + string;
|
15
|
-
|
16
|
-
if(newline !== false) { out = out + "\n"; }
|
17
|
-
return out;
|
18
|
-
};
|
19
|
-
|
20
|
-
Handlebars.PrintVisitor.prototype.program = function(program) {
|
21
|
-
var out = "",
|
22
|
-
statements = program.statements,
|
23
|
-
inverse = program.inverse,
|
24
|
-
i, l;
|
25
|
-
|
26
|
-
for(i=0, l=statements.length; i<l; i++) {
|
27
|
-
out = out + this.accept(statements[i]);
|
28
|
-
}
|
29
|
-
|
30
|
-
this.padding--;
|
31
|
-
|
32
|
-
return out;
|
33
|
-
};
|
34
|
-
|
35
|
-
Handlebars.PrintVisitor.prototype.block = function(block) {
|
36
|
-
var out = "";
|
37
|
-
|
38
|
-
out = out + this.pad("BLOCK:");
|
39
|
-
this.padding++;
|
40
|
-
out = out + this.accept(block.mustache);
|
41
|
-
if (block.program) {
|
42
|
-
out = out + this.pad("PROGRAM:");
|
43
|
-
this.padding++;
|
44
|
-
out = out + this.accept(block.program);
|
45
|
-
this.padding--;
|
46
|
-
}
|
47
|
-
if (block.inverse) {
|
48
|
-
if (block.program) { this.padding++; }
|
49
|
-
out = out + this.pad("{{^}}");
|
50
|
-
this.padding++;
|
51
|
-
out = out + this.accept(block.inverse);
|
52
|
-
this.padding--;
|
53
|
-
if (block.program) { this.padding--; }
|
54
|
-
}
|
55
|
-
this.padding--;
|
56
|
-
|
57
|
-
return out;
|
58
|
-
};
|
59
|
-
|
60
|
-
Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
|
61
|
-
var params = mustache.params, paramStrings = [], hash;
|
62
|
-
|
63
|
-
for(var i=0, l=params.length; i<l; i++) {
|
64
|
-
paramStrings.push(this.accept(params[i]));
|
65
|
-
}
|
66
|
-
|
67
|
-
params = "[" + paramStrings.join(", ") + "]";
|
68
|
-
|
69
|
-
hash = mustache.hash ? " " + this.accept(mustache.hash) : "";
|
70
|
-
|
71
|
-
return this.pad("{{ " + this.accept(mustache.id) + " " + params + hash + " }}");
|
72
|
-
};
|
73
|
-
|
74
|
-
Handlebars.PrintVisitor.prototype.partial = function(partial) {
|
75
|
-
var content = this.accept(partial.partialName);
|
76
|
-
if(partial.context) { content = content + " " + this.accept(partial.context); }
|
77
|
-
return this.pad("{{> " + content + " }}");
|
78
|
-
};
|
79
|
-
|
80
|
-
Handlebars.PrintVisitor.prototype.hash = function(hash) {
|
81
|
-
var pairs = hash.pairs;
|
82
|
-
var joinedPairs = [], left, right;
|
83
|
-
|
84
|
-
for(var i=0, l=pairs.length; i<l; i++) {
|
85
|
-
left = pairs[i][0];
|
86
|
-
right = this.accept(pairs[i][1]);
|
87
|
-
joinedPairs.push( left + "=" + right );
|
88
|
-
}
|
89
|
-
|
90
|
-
return "HASH{" + joinedPairs.join(", ") + "}";
|
91
|
-
};
|
92
|
-
|
93
|
-
Handlebars.PrintVisitor.prototype.STRING = function(string) {
|
94
|
-
return '"' + string.string + '"';
|
95
|
-
};
|
96
|
-
|
97
|
-
Handlebars.PrintVisitor.prototype.INTEGER = function(integer) {
|
98
|
-
return "INTEGER{" + integer.integer + "}";
|
99
|
-
};
|
100
|
-
|
101
|
-
Handlebars.PrintVisitor.prototype.BOOLEAN = function(bool) {
|
102
|
-
return "BOOLEAN{" + bool.bool + "}";
|
103
|
-
};
|
104
|
-
|
105
|
-
Handlebars.PrintVisitor.prototype.ID = function(id) {
|
106
|
-
var path = id.parts.join("/");
|
107
|
-
if(id.parts.length > 1) {
|
108
|
-
return "PATH:" + path;
|
109
|
-
} else {
|
110
|
-
return "ID:" + path;
|
111
|
-
}
|
112
|
-
};
|
113
|
-
|
114
|
-
Handlebars.PrintVisitor.prototype.PARTIAL_NAME = function(partialName) {
|
115
|
-
return "PARTIAL:" + partialName.name;
|
116
|
-
};
|
117
|
-
|
118
|
-
Handlebars.PrintVisitor.prototype.DATA = function(data) {
|
119
|
-
return "@" + data.id;
|
120
|
-
};
|
121
|
-
|
122
|
-
Handlebars.PrintVisitor.prototype.content = function(content) {
|
123
|
-
return this.pad("CONTENT[ '" + content.string + "' ]");
|
124
|
-
};
|
125
|
-
|
126
|
-
Handlebars.PrintVisitor.prototype.comment = function(comment) {
|
127
|
-
return this.pad("{{! '" + comment.comment + "' }}");
|
128
|
-
};
|
129
|
-
// END(BROWSER)
|
130
|
-
|
131
|
-
exports.PrintVisitor = Handlebars.PrintVisitor;
|
@@ -1,88 +0,0 @@
|
|
1
|
-
var Handlebars = require("./base");
|
2
|
-
|
3
|
-
// BEGIN(BROWSER)
|
4
|
-
Handlebars.VM = {
|
5
|
-
template: function(templateSpec) {
|
6
|
-
// Just add water
|
7
|
-
var container = {
|
8
|
-
escapeExpression: Handlebars.Utils.escapeExpression,
|
9
|
-
invokePartial: Handlebars.VM.invokePartial,
|
10
|
-
programs: [],
|
11
|
-
program: function(i, fn, data) {
|
12
|
-
var programWrapper = this.programs[i];
|
13
|
-
if(data) {
|
14
|
-
return Handlebars.VM.program(fn, data);
|
15
|
-
} else if(programWrapper) {
|
16
|
-
return programWrapper;
|
17
|
-
} else {
|
18
|
-
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
19
|
-
return programWrapper;
|
20
|
-
}
|
21
|
-
},
|
22
|
-
programWithDepth: Handlebars.VM.programWithDepth,
|
23
|
-
noop: Handlebars.VM.noop,
|
24
|
-
compilerInfo: null
|
25
|
-
};
|
26
|
-
|
27
|
-
return function(context, options) {
|
28
|
-
options = options || {};
|
29
|
-
var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
30
|
-
|
31
|
-
var compilerInfo = container.compilerInfo || [],
|
32
|
-
compilerRevision = compilerInfo[0] || 1,
|
33
|
-
currentRevision = Handlebars.COMPILER_REVISION;
|
34
|
-
|
35
|
-
if (compilerRevision !== currentRevision) {
|
36
|
-
if (compilerRevision < currentRevision) {
|
37
|
-
var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
|
38
|
-
compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
|
39
|
-
throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
|
40
|
-
"Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
|
41
|
-
} else {
|
42
|
-
// Use the embedded version info since the runtime doesn't know about this revision yet
|
43
|
-
throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
|
44
|
-
"Please update your runtime to a newer version ("+compilerInfo[1]+").";
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
return result;
|
49
|
-
};
|
50
|
-
},
|
51
|
-
|
52
|
-
programWithDepth: function(fn, data, $depth) {
|
53
|
-
var args = Array.prototype.slice.call(arguments, 2);
|
54
|
-
|
55
|
-
return function(context, options) {
|
56
|
-
options = options || {};
|
57
|
-
|
58
|
-
return fn.apply(this, [context, options.data || data].concat(args));
|
59
|
-
};
|
60
|
-
},
|
61
|
-
program: function(fn, data) {
|
62
|
-
return function(context, options) {
|
63
|
-
options = options || {};
|
64
|
-
|
65
|
-
return fn(context, options.data || data);
|
66
|
-
};
|
67
|
-
},
|
68
|
-
noop: function() { return ""; },
|
69
|
-
invokePartial: function(partial, name, context, helpers, partials, data) {
|
70
|
-
var options = { helpers: helpers, partials: partials, data: data };
|
71
|
-
|
72
|
-
if(partial === undefined) {
|
73
|
-
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
74
|
-
} else if(partial instanceof Function) {
|
75
|
-
return partial(context, options);
|
76
|
-
} else if (!Handlebars.compile) {
|
77
|
-
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
|
78
|
-
} else {
|
79
|
-
partials[name] = Handlebars.compile(partial, {data: data !== undefined});
|
80
|
-
return partials[name](context, options);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
};
|
84
|
-
|
85
|
-
Handlebars.template = Handlebars.VM.template;
|
86
|
-
|
87
|
-
// END(BROWSER)
|
88
|
-
|
@@ -1,67 +0,0 @@
|
|
1
|
-
var Handlebars = require("./base");
|
2
|
-
|
3
|
-
// BEGIN(BROWSER)
|
4
|
-
|
5
|
-
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
6
|
-
|
7
|
-
Handlebars.Exception = function(message) {
|
8
|
-
var tmp = Error.prototype.constructor.apply(this, arguments);
|
9
|
-
|
10
|
-
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
11
|
-
for (var idx = 0; idx < errorProps.length; idx++) {
|
12
|
-
this[errorProps[idx]] = tmp[errorProps[idx]];
|
13
|
-
}
|
14
|
-
};
|
15
|
-
Handlebars.Exception.prototype = new Error();
|
16
|
-
|
17
|
-
// Build out our basic SafeString type
|
18
|
-
Handlebars.SafeString = function(string) {
|
19
|
-
this.string = string;
|
20
|
-
};
|
21
|
-
Handlebars.SafeString.prototype.toString = function() {
|
22
|
-
return this.string.toString();
|
23
|
-
};
|
24
|
-
|
25
|
-
(function() {
|
26
|
-
var escape = {
|
27
|
-
"&": "&",
|
28
|
-
"<": "<",
|
29
|
-
">": ">",
|
30
|
-
'"': """,
|
31
|
-
"'": "'",
|
32
|
-
"`": "`"
|
33
|
-
};
|
34
|
-
|
35
|
-
var badChars = /[&<>"'`]/g;
|
36
|
-
var possible = /[&<>"'`]/;
|
37
|
-
|
38
|
-
var escapeChar = function(chr) {
|
39
|
-
return escape[chr] || "&";
|
40
|
-
};
|
41
|
-
|
42
|
-
Handlebars.Utils = {
|
43
|
-
escapeExpression: function(string) {
|
44
|
-
// don't escape SafeStrings, since they're already safe
|
45
|
-
if (string instanceof Handlebars.SafeString) {
|
46
|
-
return string.toString();
|
47
|
-
} else if (string == null || string === false) {
|
48
|
-
return "";
|
49
|
-
}
|
50
|
-
|
51
|
-
if(!possible.test(string)) { return string; }
|
52
|
-
return string.replace(badChars, escapeChar);
|
53
|
-
},
|
54
|
-
|
55
|
-
isEmpty: function(value) {
|
56
|
-
if (!value && value !== 0) {
|
57
|
-
return true;
|
58
|
-
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
59
|
-
return true;
|
60
|
-
} else {
|
61
|
-
return false;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
};
|
65
|
-
})();
|
66
|
-
// END(BROWSER)
|
67
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "handlebars",
|
3
|
-
"description": "Extension of the Mustache logicless template language",
|
4
|
-
"version": "1.0.8",
|
5
|
-
"homepage": "http://www.handlebarsjs.com/",
|
6
|
-
"keywords": [
|
7
|
-
"handlebars mustache template html"
|
8
|
-
],
|
9
|
-
"repository": {
|
10
|
-
"type": "git",
|
11
|
-
"url": "git://github.com/wycats/handlebars.js.git"
|
12
|
-
},
|
13
|
-
"engines": {
|
14
|
-
"node": ">=0.4.7"
|
15
|
-
},
|
16
|
-
"dependencies": {
|
17
|
-
"optimist": "~0.3",
|
18
|
-
"uglify-js": "~1.2"
|
19
|
-
},
|
20
|
-
"devDependencies": {
|
21
|
-
"benchmark": "~1.0",
|
22
|
-
"dust": "~0.3",
|
23
|
-
"jison": "~0.3",
|
24
|
-
"mocha": "*",
|
25
|
-
"mustache": "~0.7.2"
|
26
|
-
},
|
27
|
-
"main": "lib/handlebars.js",
|
28
|
-
"bin": {
|
29
|
-
"handlebars": "bin/handlebars"
|
30
|
-
},
|
31
|
-
"scripts": {
|
32
|
-
"test": "node_modules/.bin/mocha -u qunit spec/qunit_spec.js"
|
33
|
-
},
|
34
|
-
"optionalDependencies": {}
|
35
|
-
}
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class TestContext
|
4
|
-
class TestModule
|
5
|
-
attr_reader :name, :tests
|
6
|
-
|
7
|
-
def initialize(name)
|
8
|
-
@name = name
|
9
|
-
@tests = []
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :modules
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@modules = []
|
17
|
-
end
|
18
|
-
|
19
|
-
def module(name)
|
20
|
-
@modules << TestModule.new(name)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test(name, function)
|
24
|
-
@modules.last.tests << [name, function]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test_context = TestContext.new
|
29
|
-
js_context = Handlebars::Spec::CONTEXT
|
30
|
-
|
31
|
-
Module.new do
|
32
|
-
extend Test::Unit::Assertions
|
33
|
-
|
34
|
-
def self.js_backtrace(context)
|
35
|
-
begin
|
36
|
-
context.eval("throw")
|
37
|
-
rescue V8::JSError => e
|
38
|
-
return e.backtrace(:javascript)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
js_context["p"] = proc do |this, str|
|
43
|
-
p str
|
44
|
-
end
|
45
|
-
|
46
|
-
js_context["ok"] = proc do |this, ok, message|
|
47
|
-
js_context["$$RSPEC1$$"] = ok
|
48
|
-
|
49
|
-
result = js_context.eval("!!$$RSPEC1$$")
|
50
|
-
|
51
|
-
message ||= "#{ok} was not truthy"
|
52
|
-
|
53
|
-
unless result
|
54
|
-
backtrace = js_backtrace(js_context)
|
55
|
-
message << "\n#{backtrace.join("\n")}"
|
56
|
-
end
|
57
|
-
|
58
|
-
assert result, message
|
59
|
-
end
|
60
|
-
|
61
|
-
js_context["equals"] = proc do |this, first, second, message|
|
62
|
-
js_context["$$RSPEC1$$"] = first
|
63
|
-
js_context["$$RSPEC2$$"] = second
|
64
|
-
|
65
|
-
result = js_context.eval("$$RSPEC1$$ == $$RSPEC2$$")
|
66
|
-
|
67
|
-
additional_message = "#{first.inspect} did not == #{second.inspect}"
|
68
|
-
message = message ? "#{message} (#{additional_message})" : additional_message
|
69
|
-
|
70
|
-
unless result
|
71
|
-
backtrace = js_backtrace(js_context)
|
72
|
-
message << "\n#{backtrace.join("\n")}"
|
73
|
-
end
|
74
|
-
|
75
|
-
assert result, message
|
76
|
-
end
|
77
|
-
|
78
|
-
js_context["equal"] = js_context["equals"]
|
79
|
-
|
80
|
-
js_context["suite"] = proc do |this, name|
|
81
|
-
test_context.module(name)
|
82
|
-
end
|
83
|
-
|
84
|
-
js_context["test"] = proc do |this, name, function|
|
85
|
-
test_context.test(name, function)
|
86
|
-
end
|
87
|
-
|
88
|
-
local = Regexp.escape(File.expand_path(Dir.pwd))
|
89
|
-
qunit_spec = File.expand_path("../qunit_spec.js", __FILE__)
|
90
|
-
js_context.load(qunit_spec.sub(/^#{local}\//, ''))
|
91
|
-
end
|
92
|
-
|
93
|
-
test_context.modules.each do |mod|
|
94
|
-
describe mod.name do
|
95
|
-
mod.tests.each do |name, function|
|
96
|
-
it name do
|
97
|
-
function.call
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|