sprock-assets 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/Gemfile.lock +10 -10
- data/lib/sprock_assets.rb +9 -11
- data/lib/sprock_assets/version.rb +1 -1
- data/readme.md +16 -4
- data/spec/sprock_assets_spec.rb +9 -10
- metadata +1 -1
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sprock-assets (0.9.
|
4
|
+
sprock-assets (0.9.5)
|
5
5
|
sprockets
|
6
6
|
|
7
7
|
GEM
|
@@ -9,17 +9,17 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.1.3)
|
11
11
|
hike (1.2.1)
|
12
|
-
multi_json (1.
|
12
|
+
multi_json (1.4.0)
|
13
13
|
rack (1.4.1)
|
14
|
-
rake (0.
|
15
|
-
rspec (2.
|
16
|
-
rspec-core (~> 2.
|
17
|
-
rspec-expectations (~> 2.
|
18
|
-
rspec-mocks (~> 2.
|
19
|
-
rspec-core (2.
|
20
|
-
rspec-expectations (2.
|
14
|
+
rake (10.0.2)
|
15
|
+
rspec (2.12.0)
|
16
|
+
rspec-core (~> 2.12.0)
|
17
|
+
rspec-expectations (~> 2.12.0)
|
18
|
+
rspec-mocks (~> 2.12.0)
|
19
|
+
rspec-core (2.12.1)
|
20
|
+
rspec-expectations (2.12.0)
|
21
21
|
diff-lcs (~> 1.1.3)
|
22
|
-
rspec-mocks (2.
|
22
|
+
rspec-mocks (2.12.0)
|
23
23
|
sprockets (2.8.1)
|
24
24
|
hike (~> 1.2)
|
25
25
|
multi_json (~> 1.0)
|
data/lib/sprock_assets.rb
CHANGED
@@ -18,18 +18,20 @@ class SprockAssets
|
|
18
18
|
@app = app
|
19
19
|
@settings = {
|
20
20
|
assets_path: 'app',
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
compiled_path: 'public',
|
22
|
+
javascripts_path: '/assets/javascripts',
|
23
|
+
stylesheets_path: '/assets/stylesheets',
|
24
24
|
}.merge(settings)
|
25
25
|
|
26
|
+
javascript_file = "#{Dir.pwd}/#{@settings[:assets_path]}/#{@settings[:javascripts_path]}/application.js"
|
27
|
+
stylesheet_file = "#{Dir.pwd}/#{@settings[:assets_path]}/#{@settings[:stylesheets_path]}/application.css"
|
28
|
+
javascript_compiled = "#{Dir.pwd}/public/#{@settings[:javascripts_path]}/application.js"
|
29
|
+
stylesheet_compiled = "#{Dir.pwd}/public/#{@settings[:stylesheets_path]}/application.css"
|
26
30
|
|
27
|
-
javascript_file = "#{Dir.pwd}/#{@settings[:javascripts_path]}/application.js"
|
28
31
|
unless File.exists? javascript_file
|
29
32
|
raise "Javascript application file (#{javascript_file}) was not found"
|
30
33
|
end
|
31
34
|
|
32
|
-
stylesheet_file = "#{Dir.pwd}/#{@settings[:stylesheets_path]}/application.css"
|
33
35
|
unless File.exists? stylesheet_file
|
34
36
|
raise "Stylesheet application file (#{stylesheet_file}) was not found"
|
35
37
|
end
|
@@ -37,12 +39,8 @@ class SprockAssets
|
|
37
39
|
@assets = Sprockets::Environment.new(Dir.pwd) do |assets|
|
38
40
|
assets.logger = Logger.new(STDOUT)
|
39
41
|
assets.append_path @settings[:assets_path]
|
40
|
-
assets.append_path @settings[:javascripts_path]
|
41
|
-
assets.append_path @settings[:stylesheets_path]
|
42
|
-
if @settings[:compile]
|
43
|
-
assets.js_compressor = Uglifier.new({ mangle: true })
|
44
|
-
assets.css_compressor = YUI::CssCompressor.new
|
45
|
-
end
|
42
|
+
assets.append_path "#{@settings[:assets_path]}/#{@settings[:javascripts_path]}"
|
43
|
+
assets.append_path "#{@settings[:assets_path]}/#{@settings[:stylesheets_path]}"
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
data/readme.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![Build Status](https://secure.travis-ci.org/nickbarth/SprockAssets.png?branch=master)](https://travis-ci.org/nickbarth/SprockAssets)
|
3
3
|
[![Dependency Status](https://gemnasium.com/nickbarth/SprockAssets.png)](https://gemnasium.com/nickbarth/SprockAssets)
|
4
4
|
|
5
|
-
SprockAssets is a Rack middleware that makes compiling your assets
|
5
|
+
SprockAssets is a Rack middleware that makes compiling your assets easy and fast.
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
@@ -12,7 +12,7 @@ Here is how to use it.
|
|
12
12
|
|
13
13
|
gem 'sprock-assets', require: 'sprock_assets'
|
14
14
|
|
15
|
-
###
|
15
|
+
### Rack apps
|
16
16
|
|
17
17
|
Add a use to your `config.ru`
|
18
18
|
|
@@ -33,13 +33,16 @@ You can use assets just like in Rails.
|
|
33
33
|
|
34
34
|
<table>
|
35
35
|
<tr>
|
36
|
-
<th>
|
36
|
+
<th>Source Path</th>
|
37
|
+
<th>Compiled Path</th>
|
37
38
|
</tr>
|
38
39
|
<tr>
|
39
40
|
<td>app/assets/stylesheets/application.css</td>
|
41
|
+
<td>public/assets/stylesheets/application.css</td>
|
40
42
|
</tr>
|
41
43
|
<tr>
|
42
44
|
<td>app/assets/javascripts/application.js</td>
|
45
|
+
<td>public/assets/javascripts/application.js</td>
|
43
46
|
</tr>
|
44
47
|
</table>
|
45
48
|
|
@@ -49,7 +52,16 @@ You can use assets just like in Rails.
|
|
49
52
|
curl http://localhost/assets/stylesheets/application.css
|
50
53
|
curl http://localhost/assets/javascripts/application.js
|
51
54
|
|
52
|
-
Your compiled assets will now be served at their corresponding URIs.
|
55
|
+
Your compiled assets will now be served at their corresponding URIs. When your
|
56
|
+
application is run in production your assets will automatically be compiled and
|
57
|
+
saved to disk.
|
58
|
+
|
59
|
+
### Notes
|
60
|
+
|
61
|
+
Make sure you require the compressors if you use SprockAssets in production.
|
62
|
+
|
63
|
+
gem 'yui-compressor', require: 'yui/compressor'
|
64
|
+
gem 'uglifier', require: 'uglifier'
|
53
65
|
|
54
66
|
### License
|
55
67
|
WTFPL © 2012 Nick Barth
|
data/spec/sprock_assets_spec.rb
CHANGED
@@ -12,25 +12,24 @@ describe SprockAssets do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'on Rack initialize' do
|
15
|
+
let(:env) { Sprockets::Environment.any_instance }
|
16
|
+
|
15
17
|
it 'takes in custom paths' do
|
16
|
-
|
18
|
+
ENV['RACK_ENV'] = 'test'
|
17
19
|
env.should_receive(:append_path).with('ASSETS_PATH')
|
18
|
-
env.should_receive(:append_path).with('JAVASCRIPTS_PATH')
|
19
|
-
env.should_receive(:append_path).with('STYLESHEETS_PATH')
|
20
|
+
env.should_receive(:append_path).with('ASSETS_PATH/JAVASCRIPTS_PATH')
|
21
|
+
env.should_receive(:append_path).with('ASSETS_PATH/STYLESHEETS_PATH')
|
20
22
|
SprockAssets.new nil, assets_path: 'ASSETS_PATH',
|
21
23
|
javascripts_path: 'JAVASCRIPTS_PATH',
|
22
24
|
stylesheets_path: 'STYLESHEETS_PATH'
|
23
25
|
end
|
24
|
-
|
25
|
-
it 'sets compressors on compile flag' do
|
26
|
-
env = Sprockets::Environment.any_instance
|
27
|
-
env.should_receive(:js_compressor=)
|
28
|
-
env.should_receive(:css_compressor=)
|
29
|
-
SprockAssets.new nil, compile: true
|
30
|
-
end
|
31
26
|
end
|
32
27
|
|
33
28
|
context 'on Rack request' do
|
29
|
+
before(:each) do
|
30
|
+
ENV['RACK_ENV'] = 'test'
|
31
|
+
end
|
32
|
+
|
34
33
|
it 'should invoke Sprocket on URIs under /assets/' do
|
35
34
|
rack_app = SprockAssets.new nil
|
36
35
|
rack_app.assets.should_receive(:call)
|