evax 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,40 +1,47 @@
1
- # Evax Compressor
1
+ # Evax Assets Compressor
2
+
3
+ ![Evax compressor logo](http://farm8.staticflickr.com/7166/6505430865_1f9f232e8c_o_d.png)
4
+ *Evax compressor make you feel lighter*
2
5
 
3
6
  Evax is a simple asset packaging library for Ruby, providing JavaScript/CSS concatenation and compression using UglifyJS and a really simple regex based CSS compressor. Just because enough is enough.
4
7
 
5
- The idea behind it is to have a really simple library to compress your assets in the simplest way without any weird dependency. There are nice assets packaging systems out there but they have too many options for some cases. Sometimes, you just want to play with a pet project.
8
+ The idea behind it is to have a really **simple library to compress your assets** in the simplest way without any weird dependency (who said Java?). There are nice assets packaging systems out there but they have too many options for some cases. Sometimes, you just want to play with a pet project.
6
9
 
7
- Create a YAML file describing assets, Evax will take it and compress the javascript and stylesheets files to the output directory of your choice. Done.
10
+ Create a YAML file describing assets, Evax will take it and compress the javascript and stylesheets files to the *output directory* of your choice. Done.
8
11
 
9
12
  ## Instalation
10
13
 
11
- gem install evax
14
+ gem install evax
15
+
16
+ ## Dependencies
17
+
18
+ As *Evax* has a dependency in *uglifier* who has a dependency in *execjs* it is needed to have a proper **JS runtime** installed in your system. Pick one from the [execjs README page](https://github.com/sstephenson/execjs)
12
19
 
13
20
  ## Usage
14
21
 
15
22
  ### assets.yml
16
23
 
17
- output_path: tmp/
24
+ output_path: tmp/
18
25
 
19
- javascripts:
20
- js_package_one:
21
- - test/fixtures/javascripts/one.js
22
- - test/fixtures/javascripts/two.js
23
- - test/fixtures/javascripts/three.js
24
- js_package_two:
25
- - test/fixtures/javascripts/four.js
26
+ javascripts:
27
+ js_package_one:
28
+ - test/fixtures/javascripts/one.js
29
+ - test/fixtures/javascripts/two.js
30
+ - test/fixtures/javascripts/three.js
31
+ js_package_two:
32
+ - test/fixtures/javascripts/four.js
26
33
 
27
- stylesheets:
28
- css_package_one:
29
- - test/fixtures/stylesheets/one.css
30
- - test/fixtures/stylesheets/two.css
31
- css_package_two:
32
- - test/fixtures/stylesheets/three.css
33
- - test/fixtures/stylesheets/four.css
34
+ stylesheets:
35
+ css_package_one:
36
+ - test/fixtures/stylesheets/one.css
37
+ - test/fixtures/stylesheets/two.css
38
+ css_package_two:
39
+ - test/fixtures/stylesheets/three.css
40
+ - test/fixtures/stylesheets/four.css
34
41
 
35
42
  ### Command Line
36
43
 
37
- evax /path/to/assets.yml /relative/path
44
+ evax /path/to/assets.yml /relative/path
38
45
 
39
46
  ### Rails
40
47
 
@@ -47,8 +54,8 @@ Create a Rake task for running it, e.g.:
47
54
  namespace :evax do
48
55
  desc 'Build assets'
49
56
  task :build do
50
- ASSETS_PATH = /path/to/assets.yml
51
- RELATVE_PATH = /relative/path
52
- Evax.new(ASSETS_PATH, RELATVE_PATH).build
57
+ ASSETS_PATH = "#{Rails.root}/config/assets.yml"
58
+ RELATIVE_PATH = Rails.root
59
+ Evax.new( ASSETS_PATH, RELATIVE_PATH ).build
53
60
  end
54
61
  end
data/TODO.md ADDED
@@ -0,0 +1,87 @@
1
+ # TODO
2
+
3
+ ## JS Compressor options
4
+
5
+ Accept JS compressor options from the *config.yml* file.
6
+
7
+ ## CSS Minifier
8
+
9
+ from:
10
+
11
+ margin:0px 0px 0 0px
12
+ padding:0px 5px;
13
+
14
+ to:
15
+
16
+ margin:0
17
+ padding:0 5px;
18
+
19
+
20
+ from:
21
+
22
+ background:-moz-linear-gradient(top,#e2e2e2 0%,#fbfbfb 100%)
23
+
24
+ to:
25
+
26
+ background:-moz-linear-gradient(top,#e2e2e2 0,#fbfbfb 100%);
27
+
28
+
29
+ from:
30
+
31
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e2e2e2',endColorstr='#fbfbfb',GradientType=0 )}
32
+
33
+ to
34
+
35
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e2e2e2',endColorstr='#fbfbfb',GradientType=0)}
36
+
37
+
38
+ from:
39
+
40
+ border:2px solid #779900;
41
+ color:#FFFFFF;
42
+
43
+ to:
44
+
45
+ border:2px solid #790;
46
+ color:#FFF;
47
+
48
+ from:
49
+
50
+ background:#fcf7df url("/images/video/movie-fail.png") no-repeat 50% 50%;
51
+
52
+ to:
53
+
54
+ background:#fcf7df url(/images/video/movie-fail.png) no-repeat 50% 50%;
55
+
56
+ **This one is tricky because a path with weird characters can produces errors**
57
+
58
+
59
+ from:
60
+
61
+ @page{margin:0.5cm}
62
+
63
+ to:
64
+
65
+ @page{margin:.5cm}
66
+
67
+
68
+
69
+ from:
70
+
71
+ ul#offers > li .reward a{color:white;
72
+
73
+ to:
74
+
75
+ ul#offers>li .reward a{color:white;
76
+
77
+ from:
78
+
79
+ padding:0px 0px 0px 0px;
80
+ padding:0px 0px 0 0px;
81
+ padding:0 0px;
82
+
83
+ to:
84
+
85
+ padding:0;
86
+ padding:0;
87
+ padding:0;
data/etc/evax.png ADDED
Binary file
@@ -3,17 +3,16 @@
3
3
  module Evax::CssMinifier
4
4
 
5
5
  def self.build(css_string)
6
- css_string.split('}').map do |block|
7
- block.gsub!(/\n/,' ')
8
- block.gsub!(/\/\*.*?\*\//m,'')
9
- block.gsub!(/\s*:\s*/, ':')
10
- block.gsub!(/\s*;\s*/, ';')
11
- block.gsub!(/\s*,\s*/, ',')
12
- block.gsub!(/\s*\{\s*/, '{')
13
- block.gsub!(/\s\s+/, ' ')
14
-
15
- block.strip + '}' if block.include?('{')
16
- end.join(' ')
6
+ css_string.gsub!(/\n/," ")
7
+ css_string.gsub!(/\/\*.*?\*\//m,"")
8
+ css_string.gsub!(/\s*:\s*/, ":")
9
+ css_string.gsub!(/\s*;\s*/, ";")
10
+ css_string.gsub!(/\s*,\s*/, ",")
11
+ css_string.gsub!(/\s*\{\s*/, "{")
12
+ css_string.gsub!(/\s\s+/, " ")
13
+ css_string.gsub!(/^\s*/, "")
14
+ css_string.gsub!(/\s!important/, "!important")
15
+ css_string.gsub!(/;\s*\}\s*/, "}")
17
16
  end
18
17
 
19
18
  end
data/lib/evax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Evax
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/evax.rb CHANGED
@@ -27,8 +27,8 @@ class Evax
27
27
  end
28
28
 
29
29
  def build
30
- build_js
31
- build_css
30
+ build_js if js_configured?
31
+ build_css if css_configured?
32
32
  end
33
33
 
34
34
  def build_js
@@ -60,11 +60,7 @@ class Evax
60
60
  end
61
61
 
62
62
  def self.compress_js( js_string )
63
- opts = {
64
- :max_line_length => 1024,
65
- :toplevel => true,
66
- :copyright => false
67
- }
63
+ opts = { :copyright => false }
68
64
  Uglifier.compile( js_string, opts )
69
65
  end
70
66
 
@@ -72,4 +68,14 @@ class Evax
72
68
  Evax::CssMinifier.build( css_string )
73
69
  end
74
70
 
71
+ private
72
+
73
+ def js_configured?
74
+ !config["javascripts"].nil?
75
+ end
76
+
77
+ def css_configured?
78
+ !config["stylesheets"].nil?
79
+ end
80
+
75
81
  end
data/test/evax_test.rb CHANGED
@@ -64,7 +64,7 @@ class EvaxTest < Test::Unit::TestCase
64
64
  end
65
65
 
66
66
  def test_build_js
67
- evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
67
+ evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
68
68
  evax.expects( :write_output ).with( "js_one.js", File.read( "#{FIXTURES}/js_one.compress.js" ) )
69
69
  evax.expects( :write_output ).with( "js_two.js", File.read( "#{FIXTURES}/js_two.compress.js" ) )
70
70
 
@@ -72,19 +72,37 @@ class EvaxTest < Test::Unit::TestCase
72
72
  end
73
73
 
74
74
  def test_build_css
75
- evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
75
+ evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
76
76
  evax.expects( :write_output ).with( "css_one.css", File.read( "#{FIXTURES}/css_one.compress.css" ) )
77
77
  evax.expects( :write_output ).with( "css_two.css", File.read( "#{FIXTURES}/css_two.compress.css" ) )
78
78
 
79
79
  evax.build_css
80
80
  end
81
81
 
82
+ def test_build_only_css_if_js_not_configured
83
+ evax = Evax.new( "#{FIXTURES}/assets_without_javascripts.yml", "#{File.dirname(__FILE__)}/.." )
84
+
85
+ evax.expects( :write_output ).with( "css_one.css", File.read( "#{FIXTURES}/css_one.compress.css" ) )
86
+ evax.expects( :write_output ).with( "css_two.css", File.read( "#{FIXTURES}/css_two.compress.css" ) )
87
+
88
+ evax.build
89
+ end
90
+
91
+ def test_build_only_js_if_css_not_configured
92
+ evax = Evax.new( "#{FIXTURES}/assets_without_stylesheets.yml", "#{File.dirname(__FILE__)}/.." )
93
+
94
+ evax.expects( :write_output ).with( "js_one.js", File.read( "#{FIXTURES}/js_one.compress.js" ) )
95
+ evax.expects( :write_output ).with( "js_two.js", File.read( "#{FIXTURES}/js_two.compress.js" ) )
96
+
97
+ evax.build
98
+ end
99
+
82
100
  def test_build
83
- evax = Evax.new
101
+ evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
84
102
  evax.expects( :build_js )
85
103
  evax.expects( :build_css )
86
104
 
87
105
  evax.build
88
106
  end
89
107
 
90
- end
108
+ end
@@ -0,0 +1,10 @@
1
+ output_path: tmp/
2
+
3
+ stylesheets:
4
+ css_one:
5
+ - test/fixtures/stylesheets/one.css
6
+ - test/fixtures/stylesheets/two.css
7
+ css_two:
8
+ - test/fixtures/stylesheets/three.css
9
+ - test/fixtures/stylesheets/four.css
10
+
@@ -0,0 +1,10 @@
1
+ output_path: tmp/
2
+
3
+ javascripts:
4
+ js_one:
5
+ - test/fixtures/javascripts/one.js
6
+ - test/fixtures/javascripts/two.js
7
+ - test/fixtures/javascripts/three.js
8
+ js_two:
9
+ - test/fixtures/javascripts/four.js
10
+
@@ -1 +1 @@
1
- #my-id-one{background-color:pink;} #my-id-two{background-color:pink;}
1
+ #my-id-one{background-color:pink}#my-id-two{background-color:pink}
@@ -1 +1 @@
1
- #my-id-three{background-color:pink;} #my-id-four{background-color:pink;}
1
+ #my-id-three{background-color:pink}#my-id-four{background-color:pink}
@@ -1 +1 @@
1
- function a(){}function b(){}function c(){}
1
+ function js_one(){}function js_two(){}function js_three(){}
@@ -1 +1 @@
1
- function a(){}
1
+ function js_four(){}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Fernando Guillen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-13 00:00:00 +01:00
18
+ date: 2011-12-14 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -112,7 +112,9 @@ files:
112
112
  - Gemfile
113
113
  - README.md
114
114
  - Rakefile
115
+ - TODO.md
115
116
  - bin/evax
117
+ - etc/evax.png
116
118
  - evax.gemspec
117
119
  - lib/evax.rb
118
120
  - lib/evax/css_minifier.rb
@@ -120,6 +122,8 @@ files:
120
122
  - lib/evax/version.rb
121
123
  - test/evax_test.rb
122
124
  - test/fixtures/assets.yml
125
+ - test/fixtures/assets_without_javascripts.yml
126
+ - test/fixtures/assets_without_stylesheets.yml
123
127
  - test/fixtures/css_one.compress.css
124
128
  - test/fixtures/css_one.css
125
129
  - test/fixtures/css_two.compress.css
@@ -171,6 +175,8 @@ summary: Very simple assets compressor
171
175
  test_files:
172
176
  - test/evax_test.rb
173
177
  - test/fixtures/assets.yml
178
+ - test/fixtures/assets_without_javascripts.yml
179
+ - test/fixtures/assets_without_stylesheets.yml
174
180
  - test/fixtures/css_one.compress.css
175
181
  - test/fixtures/css_one.css
176
182
  - test/fixtures/css_two.compress.css