Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rake"
|
||||
gem "therubyracer", ">= 0.8.0"
|
||||
gem "therubyracer", ">= 0.9.8"
|
||||
gem "rspec"
|
||||
|
||||
+13
-11
@@ -1,17 +1,19 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.1.2)
|
||||
rake (0.9.2)
|
||||
rspec (2.1.0)
|
||||
rspec-core (~> 2.1.0)
|
||||
rspec-expectations (~> 2.1.0)
|
||||
rspec-mocks (~> 2.1.0)
|
||||
rspec-core (2.1.0)
|
||||
rspec-expectations (2.1.0)
|
||||
diff-lcs (1.1.3)
|
||||
libv8 (3.3.10.2)
|
||||
rake (0.9.2.2)
|
||||
rspec (2.7.0)
|
||||
rspec-core (~> 2.7.0)
|
||||
rspec-expectations (~> 2.7.0)
|
||||
rspec-mocks (~> 2.7.0)
|
||||
rspec-core (2.7.1)
|
||||
rspec-expectations (2.7.0)
|
||||
diff-lcs (~> 1.1.2)
|
||||
rspec-mocks (2.1.0)
|
||||
therubyracer (0.8.0)
|
||||
rspec-mocks (2.7.0)
|
||||
therubyracer (0.9.8)
|
||||
libv8 (~> 3.3.10)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
@@ -19,4 +21,4 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
rake
|
||||
rspec
|
||||
therubyracer (>= 0.8.0)
|
||||
therubyracer (>= 0.9.8)
|
||||
|
||||
@@ -166,6 +166,21 @@ example:
|
||||
// <li><a href="/people/2">Yehuda</a></li>
|
||||
// </ul>
|
||||
|
||||
|
||||
### Comments
|
||||
|
||||
You can add comments to your templates with the following syntax:
|
||||
|
||||
{{! This is a comment }}
|
||||
|
||||
You can also use real html comments if you want them to end up in the output.
|
||||
|
||||
<div>
|
||||
{{! This comment will not end up in the output }}
|
||||
<!-- This comment will show up in the output -->
|
||||
</div>
|
||||
|
||||
|
||||
Precompiling Templates
|
||||
----------------------
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ require "bundler/setup"
|
||||
file "lib/handlebars/compiler/parser.js" => ["src/handlebars.yy","src/handlebars.l"] do
|
||||
if ENV['PATH'].split(':').any? {|folder| File.exists?(folder+'/jison')}
|
||||
system "jison src/handlebars.yy src/handlebars.l"
|
||||
File.open("lib/handlebars/compiler/parser.js", "w") do |file|
|
||||
file.puts File.read("handlebars.js") + ";"
|
||||
end
|
||||
if $?.success?
|
||||
File.open("lib/handlebars/compiler/parser.js", "w") do |file|
|
||||
file.puts File.read("handlebars.js") + ";"
|
||||
end
|
||||
|
||||
sh "rm handlebars.js"
|
||||
sh "rm handlebars.js"
|
||||
else
|
||||
puts "Failed to run Jison."
|
||||
end
|
||||
else
|
||||
puts "Jison is not installed. Try running `npm install jison`."
|
||||
end
|
||||
|
||||
@@ -86,6 +86,10 @@ Handlebars.registerHelper('with', function(context, options) {
|
||||
return options.fn(context);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('log', function(context) {
|
||||
Handlebars.log(context);
|
||||
});
|
||||
|
||||
// END(BROWSER)
|
||||
|
||||
module.exports = Handlebars;
|
||||
|
||||
@@ -104,7 +104,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
'each': true,
|
||||
'if': true,
|
||||
'unless': true,
|
||||
'with': true
|
||||
'with': true,
|
||||
'log': true
|
||||
};
|
||||
if (knownHelpers) {
|
||||
for (var name in knownHelpers) {
|
||||
@@ -335,6 +336,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
initializeBuffer: function() {
|
||||
return this.quotedString("");
|
||||
},
|
||||
|
||||
namespace: "Handlebars",
|
||||
// END PUBLIC API
|
||||
|
||||
compile: function(environment, options, context, asObject) {
|
||||
@@ -405,8 +408,9 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
var out = [];
|
||||
|
||||
if (!this.isChild) {
|
||||
var copies = "helpers = helpers || Handlebars.helpers;";
|
||||
if(this.environment.usePartial) { copies = copies + " partials = partials || Handlebars.partials;"; }
|
||||
var namespace = this.namespace;
|
||||
var copies = "helpers = helpers || " + namespace + ".helpers;";
|
||||
if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
|
||||
out.push(copies);
|
||||
} else {
|
||||
out.push('');
|
||||
@@ -461,8 +465,6 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
params.push("depth" + this.environment.depths.list[i]);
|
||||
}
|
||||
|
||||
if(params.length === 4 && !this.environment.usePartial) { params.pop(); }
|
||||
|
||||
if (asObject) {
|
||||
params.push(this.source.join("\n "));
|
||||
|
||||
@@ -522,7 +524,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
+ " || "
|
||||
+ this.nameLookup('depth' + this.lastContext, name, 'context');
|
||||
}
|
||||
|
||||
|
||||
toPush += ';';
|
||||
this.source.push(toPush);
|
||||
} else {
|
||||
@@ -727,7 +729,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
};
|
||||
|
||||
var reservedWords = ("break case catch continue default delete do else finally " +
|
||||
"for function if in instanceof new return switch this throw " +
|
||||
"for function if in instanceof new return switch this throw " +
|
||||
"try typeof var void while with null true false").split(" ");
|
||||
|
||||
var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
|
||||
|
||||
@@ -64,7 +64,8 @@ Module.new do
|
||||
|
||||
result = js_context.eval("$$RSPEC1$$ == $$RSPEC2$$")
|
||||
|
||||
message ||= "#{first} did not == #{second}"
|
||||
additional_message = "#{first.inspect} did not == #{second.inspect}"
|
||||
message = message ? "#{message} (#{additional_message})" : additional_message
|
||||
|
||||
unless result
|
||||
backtrace = js_backtrace(js_context)
|
||||
|
||||
+18
-1
@@ -576,7 +576,11 @@ test("Invert blocks work in knownHelpers only mode", function() {
|
||||
equal(result, "bar", "'bar' should === '" + result);
|
||||
});
|
||||
|
||||
module("built-in helpers");
|
||||
var teardown;
|
||||
module("built-in helpers", {
|
||||
setup: function(){ teardown = null; },
|
||||
teardown: function(){ if (teardown) { teardown(); } }
|
||||
});
|
||||
|
||||
test("with", function() {
|
||||
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
|
||||
@@ -608,6 +612,19 @@ test("each", function() {
|
||||
"each with array argument ignores the contents when empty");
|
||||
});
|
||||
|
||||
test("log", function() {
|
||||
var string = "{{log blah}}"
|
||||
var hash = { blah: "whee" };
|
||||
|
||||
var logArg;
|
||||
var originalLog = Handlebars.log;
|
||||
Handlebars.log = function(arg){ logArg = arg; }
|
||||
teardown = function(){ Handlebars.log = originalLog; }
|
||||
|
||||
shouldCompileTo(string, hash, "", "log should not display");
|
||||
equals("whee", logArg, "should call log with 'whee'");
|
||||
});
|
||||
|
||||
test("overriding property lookup", function() {
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user