Skip to content
Browse files

Adjust handling of whitespace. Leading/trailing whitespace is not str…

…ipped from sources unless minifying, and fewer line breaks are inserted.
  • Loading branch information...
1 parent 264c1cf commit 30ddc83886d6505827c5f6476e45462efcc8afb1 @jcoglan committed Mar 31, 2012
View
8 lib/jake/buildable.rb
@@ -58,9 +58,9 @@ def header
Jake.read(Jake.path( directory, @config[:header])) :
(parent ? parent.header : @build.header)
- header = Jake.erb(content).result(@build.helper.scope).strip
+ header = Jake.erb(content).result(@build.helper.scope)
return nil if header == ''
- header << "\n"
+ header
end
# Returns the Packr settings to use for this package during the given build.
@@ -92,10 +92,10 @@ def write!
output_code = code(name)
source_map = output_code.source_map if output_code.respond_to?(:source_map)
- File.open(path, 'w') { |f| f.write(output_code.strip) }
+ File.open(path, 'w') { |f| f.write(output_code) }
if source_map and source_map.enabled?
- File.open(source_map.filename, 'w') { |f| f.write(source_map.to_s.strip) }
+ File.open(source_map.filename, 'w') { |f| f.write(source_map.to_s) }
end
@build.fire(:file_created, self, name, path)
View
5 lib/jake/bundle.rb
@@ -12,15 +12,16 @@ def files
# simply builds the raw template for further processing by other
# methods.
def source
- @source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n\n")
+ @source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n")
end
# Returns the result of building the source template and minifying
# the output using the given named set of Packr settings.
def code(build_name)
return @code[build_name] if @code[build_name]
- joiner = (packer_settings(build_name) == false) ? "\n\n" : ""
+ packer = packer_settings(build_name)
+ joiner = (packer[:minify] == false) ? "\n" : ""
code = @config[:files].map { |pkg| @build.package(pkg).code(build_name, false) }.join(joiner)
if head = header
View
9 lib/jake/package.rb
@@ -15,7 +15,7 @@ def files
# simply builds the raw template for further processing by other
# methods.
def source
- @source ||= files.map { |path| Jake.read(path) }.join("\n\n")
+ @source ||= files.map { |path| Jake.read(path) }.join("\n")
end
# Returns the result of building the source template and minifying
@@ -25,7 +25,12 @@ def code(build_name, with_header = true)
return with_header ? cached : cached.code
end
- packer = packer_settings(build_name).merge(:header => header)
+ packer = packer_settings(build_name)
+
+ head = header
+ head = head.strip unless packer[:minify] == false
+
+ packer = packer.merge(:header => head)
code = code_for_packer(packer, build_name)
cached = @code[build_name] = code
View
1 test/expected/basic-min.js
@@ -3,6 +3,5 @@
* even if they have been minified.
* 0.5.0-min
**/
-
Basic={VERSION:"0.5.0-min",function(a){var b=4;return b+this._0+a}};
//@ sourceMappingURL=basic-min.js.map
View
2 test/expected/basic-min.js.map
@@ -4,5 +4,5 @@
"sourceRoot": "",
"sources": ["basic.js"],
"names": ["_foo", "myVar", "something"],
- "mappings": ";;;;;;AAOA,OACE,eAAiB,KAEjB,SAASE,GACP,IAAID,IACJ,OAAOA,EAAQ,KAAKD,GAAOE;"
+ "mappings": ";;;;;AAOA,OACE,eAAiB,KAEjB,SAASE,GACP,IAAID,IACJ,OAAOA,EAAQ,KAAKD,GAAOE;"
}
View
2 test/expected/basic.js
@@ -12,4 +12,4 @@ Basic = {
var myVar = 4;
return myVar + this._foo + something;
}
-};
+};
View
5 test/expected/combo/box.js
@@ -3,6 +3,8 @@
* even if they have been minified.
* 0.5.0-src
**/
+
+
Foo = (function(my, vars) {
var another = true;
@@ -25,6 +27,5 @@ Basic = {
+Basic.Ext = "SRC";
-
-Basic.Ext = "SRC";
View
1 test/expected/ext-min.js
@@ -3,6 +3,5 @@
* even if they have been minified.
* 0.5.0-min
**/
-
Basic={VERSION:"0.5.0-min",function(a){var b=4;return b+this._foo+a}};Basic.Ext="MIN";
//@ sourceMappingURL=ext-min.js.map
View
2 test/expected/ext-min.js.map
@@ -4,5 +4,5 @@
"sourceRoot": "",
"sources": ["../src/basic-ext.js", "../src/basic.js"],
"names": ["myVar", "something"],
- "mappings": ";;;;;;ACAA,OACE,eAAiB,KAEjB,SAASC,GACP,IAAID,IACJ,OAAOA,EAAQ,KAAK,KAAOC,IDF/B,MAAM,KAAO;"
+ "mappings": ";;;;;ACAA,OACE,eAAiB,KAEjB,SAASC,GACP,IAAID,IACJ,OAAOA,EAAQ,KAAK,KAAOC,IDF/B,MAAM,KAAO;"
}
View
3 test/expected/ext.js
@@ -17,6 +17,5 @@ Basic = {
+Basic.Ext = "SRC";
-
-Basic.Ext = "SRC";
View
1 test/expected/sub/dir/foo-min.js
@@ -3,6 +3,5 @@
* even if they have been minified.
* 0.5.0-min
**/
-
Foo=(function(b,c){var a=true;return{_0:null,field:a,global:foo}})(window,something);
//@ sourceMappingURL=foo-min.js.map
View
4 test/expected/sub/dir/foo.js
@@ -5,6 +5,8 @@
**/
+
+
Foo = (function(my, vars) {
var another = true;
@@ -13,4 +15,4 @@ Foo = (function(my, vars) {
field: another,
global: foo
};
-})(window, something);
+})(window, something);
View
1 test/expected/sub/path/bar-min.js
@@ -1,4 +1,3 @@
/** Alternate header 0.5.0-min **/
-
(function(object){var Bar={_0:object}})();
//@ sourceMappingURL=bar-min.js.map
View
8 test/expected/sub/path/bar.js
@@ -1,6 +1,12 @@
+
+
+
/** Alternate header 0.5.0-src **/
+
+
+
(function(object) {
var Bar = {_another: object};
-})();
+})();
View
1 test/src/basic.js
@@ -6,4 +6,3 @@ Basic = {
return myVar + this._foo + something;
}
};
-
View
1 test/src/foo/bar.js
@@ -1,4 +1,3 @@
(function(object) {
var Bar = {_another: object};
})();
-
View
3 test/src/foo/foo.js
@@ -1,3 +1,5 @@
+
+
Foo = (function(my, vars) {
var another = true;
@@ -7,4 +9,3 @@ Foo = (function(my, vars) {
global: foo
};
})(window, something);
-
View
1 test/src/head.js
@@ -3,4 +3,3 @@
* even if they have been minified.
* <%= version %>-<%= build %>
**/
-

0 comments on commit 30ddc83

Please sign in to comment.
Something went wrong with that request. Please try again.