Skip to content

Commit 1600574

Browse files
committed
merging in newlines-in-templates-allowed-by-default.
2 parents d70a1c9 + b52e429 commit 1600574

6 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/jammit/compressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def compile_jst(paths)
9898
base_path = find_base_path(paths)
9999
compiled = paths.map do |path|
100100
contents = read_binary_file(path)
101-
contents = contents.gsub(/\n/, '').gsub("'", '\\\\\'')
101+
contents = contents.gsub(/\n/, "\\n").gsub("'", '\\\\\'')
102102
name = template_name(path, base_path)
103103
"#{namespace}['#{name}'] = #{Jammit.template_function}('#{contents}');"
104104
end

test/fixtures/jammed/js_test_with_templates.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/jammed/jst_test-custom-namespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
custom_namespace = custom_namespace || {};
33
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;};
44
custom_namespace['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
5-
custom_namespace['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
5+
custom_namespace['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
66
})();

test/fixtures/jammed/jst_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
window.JST = window.JST || {};
33
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;};
44
window.JST['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
5-
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
5+
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
66
})();

test/fixtures/jammed/jst_test_nested.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ window.JST = window.JST || {};
33
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;};
44
window.JST['nested/double_nested/double_nested'] = template('<p><%= hello_world %></p>');
55
window.JST['nested/nested1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
6-
window.JST['nested/nested2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
6+
window.JST['nested/nested2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
77
window.JST['template1'] = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
8-
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
8+
window.JST['template2'] = template('<% _([1,2,3]).each(function(num) { %>\n <li class="number">\n <%= num %>\n </li>\n<% }) %>');
99
})();

test/unit/test_configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ def test_environment_specific_configuration
7373
Object.send(:remove_const, :RAILS_ENV)
7474
Object.const_set :RAILS_ENV, "test"
7575
end
76+
7677
end

0 commit comments

Comments
 (0)