Skip to content

Commit

Permalink
merging in newlines-in-templates-allowed-by-default.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 23, 2011
2 parents d70a1c9 + b52e429 commit 1600574
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/jammit/compressor.rb
Expand Up @@ -98,7 +98,7 @@ def compile_jst(paths)
base_path = find_base_path(paths)
compiled = paths.map do |path|
contents = read_binary_file(path)
contents = contents.gsub(/\n/, '').gsub("'", '\\\\\'')
contents = contents.gsub(/\n/, "\\n").gsub("'", '\\\\\'')
name = template_name(path, base_path)
"#{namespace}['#{name}'] = #{Jammit.template_function}('#{contents}');"
end
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/jammed/js_test_with_templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/jammed/jst_test-custom-namespace.js
Expand Up @@ -2,5 +2,5 @@
custom_namespace = custom_namespace || {};
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
custom_namespace['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
custom_namespace['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
custom_namespace['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
})();
2 changes: 1 addition & 1 deletion test/fixtures/jammed/jst_test.js
Expand Up @@ -2,5 +2,5 @@
window.JST = window.JST || {};
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
window.JST['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
})();
4 changes: 2 additions & 2 deletions test/fixtures/jammed/jst_test_nested.js
Expand Up @@ -3,7 +3,7 @@ window.JST = window.JST || {};
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
window.JST['nested/double_nested/double_nested'] = template('<p><%= hello_world %></p>');
window.JST['nested/nested1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
window.JST['nested/nested2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
window.JST['nested/nested2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
window.JST['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
})();
1 change: 1 addition & 0 deletions test/unit/test_configuration.rb
Expand Up @@ -73,4 +73,5 @@ def test_environment_specific_configuration
Object.send(:remove_const, :RAILS_ENV)
Object.const_set :RAILS_ENV, "test"
end

end

0 comments on commit 1600574

Please sign in to comment.