sprock-assets 0.0.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile.lock +27 -0
- data/bin/sprock-assets +18 -0
- data/lib/sprock_assets.rb +48 -12
- data/lib/sprock_assets/version.rb +2 -1
- data/readme.md +44 -2
- data/spec/sprock_assets_spec.rb +48 -0
- data/sprock_assets.gemspec +3 -0
- metadata +38 -5
- data/spec/rack_assets_spec.rb +0 -5
data/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
sprock-assets-*.gem
|
data/Gemfile.lock
CHANGED
@@ -7,10 +7,27 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
+
addressable (2.3.2)
|
11
|
+
capybara (1.1.2)
|
12
|
+
mime-types (>= 1.16)
|
13
|
+
nokogiri (>= 1.3.3)
|
14
|
+
rack (>= 1.0.0)
|
15
|
+
rack-test (>= 0.5.4)
|
16
|
+
selenium-webdriver (~> 2.0)
|
17
|
+
xpath (~> 0.1.4)
|
18
|
+
childprocess (0.3.5)
|
19
|
+
ffi (~> 1.0, >= 1.0.6)
|
10
20
|
diff-lcs (1.1.3)
|
21
|
+
ffi (1.1.5)
|
11
22
|
hike (1.2.1)
|
23
|
+
libwebsocket (0.1.5)
|
24
|
+
addressable
|
25
|
+
mime-types (1.19)
|
12
26
|
multi_json (1.3.6)
|
27
|
+
nokogiri (1.5.5)
|
13
28
|
rack (1.4.1)
|
29
|
+
rack-test (0.6.2)
|
30
|
+
rack (>= 1.0)
|
14
31
|
rake (0.9.2.2)
|
15
32
|
rspec (2.11.0)
|
16
33
|
rspec-core (~> 2.11.0)
|
@@ -20,17 +37,27 @@ GEM
|
|
20
37
|
rspec-expectations (2.11.3)
|
21
38
|
diff-lcs (~> 1.1.3)
|
22
39
|
rspec-mocks (2.11.3)
|
40
|
+
rubyzip (0.9.9)
|
41
|
+
selenium-webdriver (2.25.0)
|
42
|
+
childprocess (>= 0.2.5)
|
43
|
+
libwebsocket (~> 0.1.3)
|
44
|
+
multi_json (~> 1.0)
|
45
|
+
rubyzip
|
23
46
|
sprockets (2.6.0)
|
24
47
|
hike (~> 1.2)
|
25
48
|
multi_json (~> 1.0)
|
26
49
|
rack (~> 1.0)
|
27
50
|
tilt (~> 1.1, != 1.3.0)
|
28
51
|
tilt (1.3.3)
|
52
|
+
xpath (0.1.4)
|
53
|
+
nokogiri (~> 1.3)
|
29
54
|
|
30
55
|
PLATFORMS
|
31
56
|
ruby
|
32
57
|
|
33
58
|
DEPENDENCIES
|
59
|
+
capybara
|
60
|
+
rack
|
34
61
|
rake
|
35
62
|
rspec
|
36
63
|
sprock-assets!
|
data/bin/sprock-assets
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sprock_assets'
|
4
|
+
|
5
|
+
if %w(-v --version).include? ARGV.first
|
6
|
+
puts "sprock-assets, version #{SprockAssets::VERSION}"
|
7
|
+
elsif 'generate_assets' == ARGV.first
|
8
|
+
SprockAssets.new(nil).generate_assets
|
9
|
+
else
|
10
|
+
puts (<<-EOS).gsub('^ ', '')
|
11
|
+
usage: sprock-assets [switches] [commands]
|
12
|
+
switches:
|
13
|
+
-v/--version displays version number
|
14
|
+
-h/--help displays this help
|
15
|
+
commands:
|
16
|
+
generate_assets generates default assets
|
17
|
+
EOS
|
18
|
+
end
|
data/lib/sprock_assets.rb
CHANGED
@@ -1,23 +1,59 @@
|
|
1
|
-
require '
|
1
|
+
require 'fileutils'
|
2
2
|
require 'sprockets'
|
3
|
+
require 'sprock_assets/version'
|
3
4
|
|
4
5
|
class SprockAssets
|
5
|
-
|
6
|
-
|
6
|
+
# Public: Gets/Sets the Rack application instance.
|
7
|
+
attr_accessor :app
|
8
|
+
# Public: Gets/Sets the middleware settings.
|
9
|
+
attr_accessor :settings
|
10
|
+
# Public: Gets/Sets the Sprockets Enviroment.
|
11
|
+
attr_accessor :assets
|
12
|
+
|
13
|
+
# Public: Initialize SprockAssets a middleware.
|
14
|
+
#
|
15
|
+
# app - The current Rack app.
|
16
|
+
# settings - A hash of the asset path settings.
|
17
|
+
def initialize(app, settings={})
|
7
18
|
@app = app
|
8
|
-
@
|
9
|
-
|
19
|
+
@settings = {
|
20
|
+
assets_path: 'app',
|
21
|
+
javascripts_path: 'app/assets/javascripts',
|
22
|
+
stylesheets_path: 'app/assets/stylesheets',
|
23
|
+
}.merge(settings)
|
24
|
+
|
25
|
+
@assets = Sprockets::Environment.new(Dir.pwd) do |assets|
|
26
|
+
assets.logger = Logger.new(STDOUT)
|
27
|
+
assets.append_path @settings[:assets_path]
|
28
|
+
assets.append_path @settings[:javascripts_path]
|
29
|
+
assets.append_path @settings[:stylesheets_path]
|
10
30
|
end
|
11
|
-
@env.append_path 'app'
|
12
|
-
@env.append_path 'app/assets/stylesheets'
|
13
|
-
@env.append_path 'app/assets/javascripts'
|
14
31
|
end
|
15
32
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
33
|
+
# Public: A rack middleware call method routing URLs under /assets/ to the SprockAssets middleware.
|
34
|
+
def call(env)
|
35
|
+
if env['PATH_INFO'][/^\/assets/].nil?
|
20
36
|
@app.call env
|
37
|
+
else
|
38
|
+
@assets.call env
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Public: Generates the configured file structure for an applications assets.
|
43
|
+
def generate_assets
|
44
|
+
FileUtils.mkdir_p "#{@settings[:javascripts_path]}/coffee"
|
45
|
+
FileUtils.mkdir_p "#{@settings[:stylesheets_path]}/scss"
|
46
|
+
File.open("#{@settings[:javascripts_path]}/application.js", 'w') do |application_js|
|
47
|
+
application_js << (<<-EOS).gsub(' ', '')
|
48
|
+
//= require_tree ./coffee
|
49
|
+
EOS
|
50
|
+
end
|
51
|
+
File.open("#{@settings[:stylesheets_path]}/application.css", 'w') do |application_css|
|
52
|
+
application_css << (<<-EOS).gsub(' ', '')
|
53
|
+
/*
|
54
|
+
*= require_tree ./scss
|
55
|
+
*/
|
56
|
+
EOS
|
21
57
|
end
|
22
58
|
end
|
23
59
|
end
|
data/readme.md
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
# SprockAssets
|
2
|
+
|
2
3
|
SprockAssets is a Rack Middleware you can include in your application for compiling your assets on the fly with Sprockets.
|
3
4
|
|
4
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Here's how to use it.
|
5
8
|
|
6
|
-
|
9
|
+
### Add it to your Gemfile
|
7
10
|
|
8
11
|
gem 'sprock-assets', require 'sprock_assets'
|
9
12
|
|
13
|
+
### Vanilla Rack apps
|
14
|
+
|
10
15
|
Add a use to your `config.ru`
|
11
16
|
|
12
17
|
use SprockAssets
|
13
18
|
|
19
|
+
### Sinatra
|
20
|
+
|
21
|
+
If you're using Sinatra, you can use the flash hash just like in Rails:
|
22
|
+
|
23
|
+
require 'sinatra/base'
|
24
|
+
require 'sprock_assets'
|
25
|
+
|
26
|
+
class MyApp < Sinatra::Base
|
27
|
+
use SprockAssets
|
28
|
+
end
|
29
|
+
|
30
|
+
### Generate default assets
|
31
|
+
|
32
|
+
Use the built in generator to generate some default assets.
|
33
|
+
|
34
|
+
sprock-assets generate_assets
|
35
|
+
|
36
|
+
It will create a directory structure and default assets based on the configured settings.
|
37
|
+
|
38
|
+
tree app/
|
39
|
+
app/
|
40
|
+
└── assets
|
41
|
+
├── javascripts
|
42
|
+
│ ├── application.js
|
43
|
+
│ └── coffee
|
44
|
+
└── stylesheets
|
45
|
+
├── application.css.scss
|
46
|
+
└── scss
|
47
|
+
|
48
|
+
### Serve compiled assets
|
49
|
+
|
50
|
+
ruby config.ru
|
51
|
+
curl http://localhost/assets/stylesheets/application.css
|
52
|
+
curl http://localhost/assets/javascripts/application.js
|
53
|
+
|
54
|
+
Your compiled assets will now be served at their corresponding URIs.
|
55
|
+
|
14
56
|
### License
|
15
57
|
WTFPL © 2012 Nick Barth
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SprockAssets do
|
4
|
+
context 'on Rack initialize' do
|
5
|
+
it 'takes in custom paths' do
|
6
|
+
env = Sprockets::Environment.any_instance
|
7
|
+
env.should_receive(:append_path).with('ASSETS_PATH')
|
8
|
+
env.should_receive(:append_path).with('JAVASCRIPTS_PATH')
|
9
|
+
env.should_receive(:append_path).with('STYLESHEETS_PATH')
|
10
|
+
SprockAssets.new nil, assets_path: 'ASSETS_PATH',
|
11
|
+
javascripts_path: 'JAVASCRIPTS_PATH',
|
12
|
+
stylesheets_path: 'STYLESHEETS_PATH'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'on Rack request' do
|
17
|
+
it 'should invoke Sprocket on URIs under /assets/' do
|
18
|
+
rack_app = SprockAssets.new nil
|
19
|
+
rack_app.assets.should_receive(:call)
|
20
|
+
rack_app.call 'PATH_INFO' => '/assets/'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should not invoke Sprocket for other URIs' do
|
24
|
+
rack_app = SprockAssets.new double
|
25
|
+
rack_app.app.should_receive(:call)
|
26
|
+
rack_app.call 'PATH_INFO' => '/other/'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'on generate asset call' do
|
31
|
+
before(:each) do
|
32
|
+
FileUtils.stub(:mkdir_p)
|
33
|
+
File.stub(:open)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should create the correct folders' do
|
37
|
+
FileUtils.should_receive(:mkdir_p).with('app/assets/stylesheets/scss')
|
38
|
+
FileUtils.should_receive(:mkdir_p).with('app/assets/javascripts/coffee')
|
39
|
+
SprockAssets.new(nil).generate_assets
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should write an application.css and a application.js file' do
|
43
|
+
File.should_receive(:open).with('app/assets/javascripts/application.js', 'w')
|
44
|
+
File.should_receive(:open).with('app/assets/stylesheets/application.css', 'w')
|
45
|
+
SprockAssets.new(nil).generate_assets
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/sprock_assets.gemspec
CHANGED
@@ -11,10 +11,13 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.summary = 'A Ruby Gem for compiling assets through Sprock.'
|
12
12
|
gem.description = 'SprockAssets is a Rack Middleware you can include in your application for compiling your assets on the fly with Sprockets.'
|
13
13
|
gem.homepage = 'https://github.com/nickbarth/SprockAssets'
|
14
|
+
gem.executables = ['sprock-assets']
|
14
15
|
|
15
16
|
gem.add_dependency('sprockets')
|
16
17
|
gem.add_development_dependency('rake')
|
18
|
+
gem.add_development_dependency('rack')
|
17
19
|
gem.add_development_dependency('rspec')
|
20
|
+
gem.add_development_dependency('capybara')
|
18
21
|
|
19
22
|
gem.files = `git ls-files`.split($/)
|
20
23
|
gem.test_files = gem.files.grep /spec/
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprock-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rspec
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,11 +75,28 @@ dependencies:
|
|
59
75
|
- - ! '>='
|
60
76
|
- !ruby/object:Gem::Version
|
61
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: capybara
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
62
94
|
description: SprockAssets is a Rack Middleware you can include in your application
|
63
95
|
for compiling your assets on the fly with Sprockets.
|
64
96
|
email:
|
65
97
|
- nick@nickbarth.ca
|
66
|
-
executables:
|
98
|
+
executables:
|
99
|
+
- sprock-assets
|
67
100
|
extensions: []
|
68
101
|
extra_rdoc_files: []
|
69
102
|
files:
|
@@ -72,12 +105,12 @@ files:
|
|
72
105
|
- Gemfile
|
73
106
|
- Gemfile.lock
|
74
107
|
- Rakefile
|
108
|
+
- bin/sprock-assets
|
75
109
|
- lib/sprock_assets.rb
|
76
110
|
- lib/sprock_assets/version.rb
|
77
111
|
- readme.md
|
78
|
-
- spec/rack_assets_spec.rb
|
79
112
|
- spec/spec_helper.rb
|
80
|
-
-
|
113
|
+
- spec/sprock_assets_spec.rb
|
81
114
|
- sprock_assets.gemspec
|
82
115
|
homepage: https://github.com/nickbarth/SprockAssets
|
83
116
|
licenses: []
|
@@ -105,6 +138,6 @@ specification_version: 3
|
|
105
138
|
summary: A Ruby Gem for compiling assets through Sprock.
|
106
139
|
test_files:
|
107
140
|
- .rspec
|
108
|
-
- spec/rack_assets_spec.rb
|
109
141
|
- spec/spec_helper.rb
|
142
|
+
- spec/sprock_assets_spec.rb
|
110
143
|
- sprock_assets.gemspec
|