From c08d29e523284b95a98a523bc6d40edd02d6b9de Mon Sep 17 00:00:00 2001 From: Bruno Carriere Date: Fri, 27 Jul 2012 14:07:14 -0400 Subject: [PATCH 1/4] Added support for Uglifier options in assets.yml --- lib/evax.rb | 15 ++++++++++++--- test/evax_test.rb | 8 ++++++++ test/fixtures/assets.yml | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/evax.rb b/lib/evax.rb index 0d06790..0525657 100644 --- a/lib/evax.rb +++ b/lib/evax.rb @@ -49,12 +49,14 @@ def watch end def build_js( group_names=[] ) + options = symbolize_hash( config["options"] || {} ) + groups = config["javascripts"] groups.select!{|k, v| group_names.include? k } if group_names.any? groups.each_key do |group_name| result_string = join( :javascripts, group_name ) - result_string = Evax.compress_js( result_string ) if config["compress"] + result_string = Evax.compress_js( result_string, options ) if config["compress"] write_output( "#{group_name}.js", result_string ) end @@ -82,8 +84,8 @@ def write_output( file_name, string ) File.open( file_path, 'w' ) { |f| f.write string } end - def self.compress_js( js_string ) - opts = { :copyright => false } + def self.compress_js( js_string, options = {} ) + opts = { :copyright => false }.merge!( options ) Uglifier.compile( js_string, opts ) end @@ -93,6 +95,13 @@ def self.compress_css( css_string ) private + def symbolize_hash(hash) + hash.inject({}) do |symbol_hash, (k,v)| + symbol_hash[k.to_sym] = v.is_a?(Hash) ? symbolize_hash(v) : v + symbol_hash + end + end + def js_configured? !config["javascripts"].nil? end diff --git a/test/evax_test.rb b/test/evax_test.rb index e426944..75cbb7d 100644 --- a/test/evax_test.rb +++ b/test/evax_test.rb @@ -59,6 +59,14 @@ def test_compress_js assert_equal( File.read( "#{FIXTURES}/js_one.compress.js" ), result) end + def test_compress_js_receives_options + evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." ) + Evax.expects( :compress_js ).at_least_once.with do |js, opts| + opts == { :max_line_length => 800 } + end + evax.build_js + end + def test_compress_css result = Evax.compress_css( File.read( "#{FIXTURES}/css_one.css" ) ) diff --git a/test/fixtures/assets.yml b/test/fixtures/assets.yml index 432fb7d..1d6447c 100644 --- a/test/fixtures/assets.yml +++ b/test/fixtures/assets.yml @@ -1,5 +1,6 @@ output_path: tmp/ - +options: + max_line_length: 800 javascripts: js_one: - test/fixtures/javascripts/one.js From 31211d7c2c66ad92c1119ceabb440857128a0c2e Mon Sep 17 00:00:00 2001 From: Bruno Carriere Date: Fri, 27 Jul 2012 14:22:07 -0400 Subject: [PATCH 2/4] Added nested option to ensure recursive symbolize_hash function works. --- test/evax_test.rb | 5 ++++- test/fixtures/assets.yml | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/evax_test.rb b/test/evax_test.rb index 75cbb7d..bb4bde1 100644 --- a/test/evax_test.rb +++ b/test/evax_test.rb @@ -60,9 +60,12 @@ def test_compress_js end def test_compress_js_receives_options + evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." ) Evax.expects( :compress_js ).at_least_once.with do |js, opts| - opts == { :max_line_length => 800 } + opts == { :max_line_length => 800, + :beautify_options => + { :indent_level => 4 }} end evax.build_js end diff --git a/test/fixtures/assets.yml b/test/fixtures/assets.yml index 1d6447c..7c00f1b 100644 --- a/test/fixtures/assets.yml +++ b/test/fixtures/assets.yml @@ -1,6 +1,8 @@ output_path: tmp/ options: max_line_length: 800 + beautify_options: + indent_level: 4 javascripts: js_one: - test/fixtures/javascripts/one.js From 7291702d5923b419540270c90e52f9f9670f9386 Mon Sep 17 00:00:00 2001 From: Ilya Shindyapin Date: Mon, 24 Jun 2013 14:40:36 -0600 Subject: [PATCH 3/4] Added compiled on date option and updated the gemspec for bundler 1.3.5 Signed-off-by: Ilya Shindyapin --- evax.gemspec | 2 +- lib/evax.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/evax.gemspec b/evax.gemspec index 6c0aec4..e37bc6a 100644 --- a/evax.gemspec +++ b/evax.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.rubyforge_project = "evax" - s.add_development_dependency "bundler", "1.1.0" + s.add_development_dependency "bundler", "1.3.5" s.add_development_dependency "rake", "0.9.2.2" s.add_development_dependency "mocha", "0.10.0" s.add_development_dependency "delorean", "1.1.1" diff --git a/lib/evax.rb b/lib/evax.rb index 0525657..bb56054 100644 --- a/lib/evax.rb +++ b/lib/evax.rb @@ -26,7 +26,7 @@ def run_as_daemon end def config - default_opts = { "compress" => true } + default_opts = { "compress" => true, "add_compile_date" => false } default_opts.merge(YAML::load_file( @config_file )) end @@ -57,6 +57,7 @@ def build_js( group_names=[] ) groups.each_key do |group_name| result_string = join( :javascripts, group_name ) result_string = Evax.compress_js( result_string, options ) if config["compress"] + result_string = Evax.add_compile_date( results_string ) if config["add_compile_date"] write_output( "#{group_name}.js", result_string ) end @@ -69,6 +70,7 @@ def build_css( group_names=[] ) groups.each_key do |group_name| result_string = join( :stylesheets, group_name ) result_string = Evax.compress_css( result_string ) if config["compress"] + result_string = Evax.add_compile_date( results_string ) if config["add_compile_date"] write_output( "#{group_name}.css", result_string ) end @@ -83,6 +85,10 @@ def write_output( file_name, string ) FileUtils.mkdir_p path File.open( file_path, 'w' ) { |f| f.write string } end + + def self.add_compile_date( result_string ) + "/* Compiled on #{Time.new} */\n#{result_string}" + end def self.compress_js( js_string, options = {} ) opts = { :copyright => false }.merge!( options ) From 68669a67c0da743f563b676ae9330e77871f358f Mon Sep 17 00:00:00 2001 From: Ilya Shindyapin Date: Mon, 24 Jun 2013 16:18:08 -0600 Subject: [PATCH 4/4] Changed the variable and added a simple rake test Signed-off-by: Ilya Shindyapin --- lib/evax.rb | 10 +++++----- test/evax_test.rb | 5 +++++ test/fixtures/assets_compiled_datetime.yml | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/assets_compiled_datetime.yml diff --git a/lib/evax.rb b/lib/evax.rb index bb56054..5a37d3b 100644 --- a/lib/evax.rb +++ b/lib/evax.rb @@ -26,7 +26,7 @@ def run_as_daemon end def config - default_opts = { "compress" => true, "add_compile_date" => false } + default_opts = { "compress" => true, "compiled_datetime" => false } default_opts.merge(YAML::load_file( @config_file )) end @@ -57,7 +57,7 @@ def build_js( group_names=[] ) groups.each_key do |group_name| result_string = join( :javascripts, group_name ) result_string = Evax.compress_js( result_string, options ) if config["compress"] - result_string = Evax.add_compile_date( results_string ) if config["add_compile_date"] + result_string = Evax.compiled_datetime( result_string ) if config["compiled_datetime"] write_output( "#{group_name}.js", result_string ) end @@ -70,7 +70,7 @@ def build_css( group_names=[] ) groups.each_key do |group_name| result_string = join( :stylesheets, group_name ) result_string = Evax.compress_css( result_string ) if config["compress"] - result_string = Evax.add_compile_date( results_string ) if config["add_compile_date"] + result_string = Evax.compiled_datetime( result_string ) if config["compiled_datetime"] write_output( "#{group_name}.css", result_string ) end @@ -86,7 +86,7 @@ def write_output( file_name, string ) File.open( file_path, 'w' ) { |f| f.write string } end - def self.add_compile_date( result_string ) + def self.compiled_datetime( result_string ) "/* Compiled on #{Time.new} */\n#{result_string}" end @@ -132,4 +132,4 @@ def filter_groups_by_file(type, file) config[type.to_s].select {|k, v| v.include? file }.keys end -end +end \ No newline at end of file diff --git a/test/evax_test.rb b/test/evax_test.rb index bb4bde1..efc2a86 100644 --- a/test/evax_test.rb +++ b/test/evax_test.rb @@ -28,6 +28,11 @@ def test_read_config_file_compress_off assert_equal( false, evax.config["compress"] ) end + def test_read_config_file_compiled_datetime + evax = Evax.new( "#{FIXTURES}/assets_compiled_datetime.yml") + assert_equal( true, evax.config["compiled_datetime"] ) + end + def test_join evax = Evax.new( "#{FIXTURES}/assets.yml", "/wadus" ) diff --git a/test/fixtures/assets_compiled_datetime.yml b/test/fixtures/assets_compiled_datetime.yml new file mode 100644 index 0000000..23037d2 --- /dev/null +++ b/test/fixtures/assets_compiled_datetime.yml @@ -0,0 +1,19 @@ +compress: on +compiled_datetime: true +output_path: tmp/ + +javascripts: + js_one: + - test/fixtures/javascripts/one.js + - test/fixtures/javascripts/two.js + - test/fixtures/javascripts/three.js + js_two: + - test/fixtures/javascripts/four.js + +stylesheets: + css_one: + - test/fixtures/stylesheets/one.css + - test/fixtures/stylesheets/two.css + css_two: + - test/fixtures/stylesheets/three.css + - test/fixtures/stylesheets/four.css