evax 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/evax +13 -2
- data/evax.gemspec +2 -1
- data/lib/evax.rb +42 -4
- data/lib/evax/version.rb +1 -1
- data/test/evax_test.rb +32 -2
- data/test/fixtures/js_one.compress.js +1 -1
- data/test/fixtures/js_two.compress.js +1 -1
- metadata +24 -13
data/bin/evax
CHANGED
@@ -11,8 +11,19 @@ rescue LoadError
|
|
11
11
|
end
|
12
12
|
|
13
13
|
if ( ARGV.size < 2 )
|
14
|
-
|
14
|
+
usage = "Usage:\n"\
|
15
|
+
"$ evax <config_file_path> <relative_path> [<options>]\n"\
|
16
|
+
"options:\n"\
|
17
|
+
"\t-w\t- watch assets for changes and rebuild when necessary"
|
18
|
+
Evax::Logger.log usage
|
15
19
|
exit 1
|
16
20
|
end
|
17
21
|
|
18
|
-
Evax.new( ARGV[0], ARGV[1] )
|
22
|
+
evax = Evax.new( ARGV[0], ARGV[1] )
|
23
|
+
options = ARGV[2..-1]
|
24
|
+
|
25
|
+
if options.include?("-w")
|
26
|
+
evax.run_as_daemon
|
27
|
+
else
|
28
|
+
evax.run_once
|
29
|
+
end
|
data/evax.gemspec
CHANGED
@@ -18,12 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.rubyforge_project = "evax"
|
20
20
|
|
21
|
-
s.add_development_dependency "bundler", "1.0
|
21
|
+
s.add_development_dependency "bundler", "1.1.0"
|
22
22
|
s.add_development_dependency "rake", "0.9.2.2"
|
23
23
|
s.add_development_dependency "mocha", "0.10.0"
|
24
24
|
s.add_development_dependency "delorean", "1.1.1"
|
25
25
|
|
26
26
|
s.add_dependency "uglifier", "1.2.3"
|
27
|
+
s.add_dependency "watchr", "0.7"
|
27
28
|
|
28
29
|
s.files = `git ls-files`.split("\n")
|
29
30
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/evax.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "yaml"
|
2
2
|
require "uglifier"
|
3
|
+
require "watchr"
|
3
4
|
|
4
5
|
require_relative "evax/version"
|
5
6
|
require_relative "evax/css_minifier"
|
@@ -16,6 +17,14 @@ class Evax
|
|
16
17
|
Evax::Logger.log "Relative Path: #{self.relative_path}"
|
17
18
|
end
|
18
19
|
|
20
|
+
def run_once
|
21
|
+
build
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_as_daemon
|
25
|
+
watch
|
26
|
+
end
|
27
|
+
|
19
28
|
def config
|
20
29
|
default_opts = { "compress" => true }
|
21
30
|
default_opts.merge(YAML::load_file( @config_file ))
|
@@ -32,8 +41,18 @@ class Evax
|
|
32
41
|
build_css if css_configured?
|
33
42
|
end
|
34
43
|
|
35
|
-
def
|
36
|
-
|
44
|
+
def watch
|
45
|
+
script = Watchr::Script.new
|
46
|
+
script.watch( asset_files_regex(:javascripts) ) {|asset| build_js( js_groups_for( asset[0] ) ) } if js_configured?
|
47
|
+
script.watch( asset_files_regex(:stylesheets) ) {|asset| build_css( css_groups_for( asset[0] ) ) } if css_configured?
|
48
|
+
Watchr::Controller.new( script, Watchr.handler.new ).run
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_js( group_names=[] )
|
52
|
+
groups = config["javascripts"]
|
53
|
+
groups.select!{|k, v| group_names.include? k } if group_names.any?
|
54
|
+
|
55
|
+
groups.each_key do |group_name|
|
37
56
|
result_string = join( :javascripts, group_name )
|
38
57
|
result_string = Evax.compress_js( result_string ) if config["compress"]
|
39
58
|
|
@@ -41,8 +60,11 @@ class Evax
|
|
41
60
|
end
|
42
61
|
end
|
43
62
|
|
44
|
-
def build_css
|
45
|
-
config["stylesheets"]
|
63
|
+
def build_css( group_names=[] )
|
64
|
+
groups = config["stylesheets"]
|
65
|
+
groups.select!{|k, v| group_names.include? k } if group_names.any?
|
66
|
+
|
67
|
+
groups.each_key do |group_name|
|
46
68
|
result_string = join( :stylesheets, group_name )
|
47
69
|
result_string = Evax.compress_css( result_string ) if config["compress"]
|
48
70
|
|
@@ -79,4 +101,20 @@ class Evax
|
|
79
101
|
!config["stylesheets"].nil?
|
80
102
|
end
|
81
103
|
|
104
|
+
def asset_files_regex(type)
|
105
|
+
config[type.to_s].values.flatten.uniq.map {|path| Regexp.quote( path ) }.join( "|" )
|
106
|
+
end
|
107
|
+
|
108
|
+
def js_groups_for( file )
|
109
|
+
filter_groups_by_file( :javascripts, file )
|
110
|
+
end
|
111
|
+
|
112
|
+
def css_groups_for( file )
|
113
|
+
filter_groups_by_file( :stylesheets, file )
|
114
|
+
end
|
115
|
+
|
116
|
+
def filter_groups_by_file(type, file)
|
117
|
+
config[type.to_s].select {|k, v| v.include? file }.keys
|
118
|
+
end
|
119
|
+
|
82
120
|
end
|
data/lib/evax/version.rb
CHANGED
data/test/evax_test.rb
CHANGED
@@ -74,7 +74,7 @@ class EvaxTest < Test::Unit::TestCase
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
77
|
+
def test_build_js_all_groups
|
78
78
|
evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
|
79
79
|
evax.expects( :write_output ).with( "js_one.js", File.read( "#{FIXTURES}/js_one.compress.js" ) )
|
80
80
|
evax.expects( :write_output ).with( "js_two.js", File.read( "#{FIXTURES}/js_two.compress.js" ) )
|
@@ -82,6 +82,13 @@ class EvaxTest < Test::Unit::TestCase
|
|
82
82
|
evax.build_js
|
83
83
|
end
|
84
84
|
|
85
|
+
def test_build_js_selected_groups
|
86
|
+
evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
|
87
|
+
evax.expects( :write_output ).with( "js_one.js", File.read( "#{FIXTURES}/js_one.compress.js" ) ).once
|
88
|
+
|
89
|
+
evax.build_js(["js_one"])
|
90
|
+
end
|
91
|
+
|
85
92
|
def test_build_js_compress_off
|
86
93
|
evax = Evax.new( "#{FIXTURES}/assets_compress_off.yml", "#{File.dirname(__FILE__)}/.." )
|
87
94
|
Evax.expects( :compress_js ).never
|
@@ -91,7 +98,7 @@ class EvaxTest < Test::Unit::TestCase
|
|
91
98
|
evax.build_js
|
92
99
|
end
|
93
100
|
|
94
|
-
def
|
101
|
+
def test_build_css_all_groups
|
95
102
|
evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
|
96
103
|
evax.expects( :write_output ).with( "css_one.css", File.read( "#{FIXTURES}/css_one.compress.css" ) )
|
97
104
|
evax.expects( :write_output ).with( "css_two.css", File.read( "#{FIXTURES}/css_two.compress.css" ) )
|
@@ -99,6 +106,13 @@ class EvaxTest < Test::Unit::TestCase
|
|
99
106
|
evax.build_css
|
100
107
|
end
|
101
108
|
|
109
|
+
def test_build_css_selected_groups
|
110
|
+
evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
|
111
|
+
evax.expects( :write_output ).with( "css_one.css", File.read( "#{FIXTURES}/css_one.compress.css" ) ).once
|
112
|
+
|
113
|
+
evax.build_css(["css_one"])
|
114
|
+
end
|
115
|
+
|
102
116
|
def test_build_css_off
|
103
117
|
evax = Evax.new( "#{FIXTURES}/assets_compress_off.yml", "#{File.dirname(__FILE__)}/.." )
|
104
118
|
Evax.expects( :compress_css ).never
|
@@ -134,4 +148,20 @@ class EvaxTest < Test::Unit::TestCase
|
|
134
148
|
evax.build
|
135
149
|
end
|
136
150
|
|
151
|
+
def test_watch
|
152
|
+
evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
|
153
|
+
Watchr::Controller.any_instance.stubs(:run)
|
154
|
+
|
155
|
+
watchr = mock()
|
156
|
+
Watchr::Script.stubs(:new => watchr)
|
157
|
+
watchr.expects(:watch).with do |pattern, block|
|
158
|
+
pattern == "test/fixtures/javascripts/one\\.js|test/fixtures/javascripts/two\\.js|test/fixtures/javascripts/three\\.js|test/fixtures/javascripts/four\\.js"
|
159
|
+
end
|
160
|
+
watchr.expects(:watch).with do |pattern, block|
|
161
|
+
pattern == "test/fixtures/stylesheets/one\\.css|test/fixtures/stylesheets/two\\.css|test/fixtures/stylesheets/three\\.css|test/fixtures/stylesheets/four\\.css"
|
162
|
+
end
|
163
|
+
|
164
|
+
evax.watch
|
165
|
+
end
|
166
|
+
|
137
167
|
end
|
@@ -1 +1 @@
|
|
1
|
-
function js_one(){}function js_two(){}function js_three(){}
|
1
|
+
function js_one(){}function js_two(){}function js_three(){};
|
@@ -1 +1 @@
|
|
1
|
-
function js_four(){}
|
1
|
+
function js_four(){};
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-02
|
13
|
+
date: 2012-04-02 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
|
-
requirement: &
|
17
|
+
requirement: &70165757679220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - =
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.0
|
22
|
+
version: 1.1.0
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70165757679220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &70165757678720 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - =
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.9.2.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70165757678720
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: mocha
|
39
|
-
requirement: &
|
39
|
+
requirement: &70165757678260 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - =
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.10.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70165757678260
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: delorean
|
50
|
-
requirement: &
|
50
|
+
requirement: &70165757677800 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - =
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.1.1
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70165757677800
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: uglifier
|
61
|
-
requirement: &
|
61
|
+
requirement: &70165757677340 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - =
|
@@ -66,7 +66,18 @@ dependencies:
|
|
66
66
|
version: 1.2.3
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70165757677340
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: watchr
|
72
|
+
requirement: &70165757676880 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - =
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.7'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70165757676880
|
70
81
|
description: ! " Evax is a simple asset packaging library for Ruby,\n providing
|
71
82
|
JavaScript/CSS concatenation and compression\n using UglifyJS and a really simple
|
72
83
|
regex based CSS\n compressor. Just because enough is enough.\n"
|