padrino-pipeline 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +64 -36
- data/lib/padrino-pipeline.rb +1 -0
- data/lib/padrino-pipeline/pipelines/asset_pack.rb +17 -21
- data/lib/padrino-pipeline/pipelines/common.rb +35 -0
- data/lib/padrino-pipeline/pipelines/sprockets.rb +24 -18
- data/lib/padrino-pipeline/version.rb +1 -1
- data/test/api/test_css.rb +104 -0
- data/test/api/test_images.rb +113 -0
- data/test/api/test_js.rb +111 -0
- data/test/api/test_other.rb +47 -0
- data/test/extra/helper.rb +21 -0
- data/test/fixtures/asset_pack_app/asset_pack_app.rb +2 -2
- data/test/sprockets/test_asset_tag.rb +2 -2
- data/test/sprockets/test_js.rb +5 -70
- metadata +11 -10
- data/test/asset_pack/test_css.rb +0 -33
- data/test/asset_pack/test_js.rb +0 -33
- data/test/sprockets/test_assets.rb +0 -40
- data/test/sprockets/test_css.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ae583739b857e66675c501c51fb349afe552eb7
|
4
|
+
data.tar.gz: 6401ed2ffbe33dba531735a533f79b15b911e411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b001b81d9e56971e911575aaa4faec94da4859db068ceef9b52863bc576c9cb2e2af3ad8094edb5017f0dc4d3cc232ba1c35dadba5079359991b9004f92af1
|
7
|
+
data.tar.gz: 015dc113ce5d617544322d968807d5236e641c6041590e940e15b4881f71b6d5fd624094c4b8124a6c7e9e76fafd1ec8699a4247cead44b68d6300502796f137
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,60 +1,88 @@
|
|
1
|
-
|
2
|
-
[
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
#Padrino Pipeline
|
2
|
+
Padrino Pipeline is a gem for [Padrino](http://www.padrinorb.com). It provides
|
3
|
+
a unified way to use several different asset management systems.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/Ortuna/padrino-pipeline)
|
6
|
+
[](https://codeclimate.com/github/Ortuna/padrino-pipeline)
|
7
|
+
[](https://gemnasium.com/Ortuna/padrino-pipeline)
|
8
|
+
|
9
|
+
|
10
|
+
##Supported Pipelines
|
11
|
+
- [Sprockets](https://github.com/sstephenson/sprockets)
|
12
|
+
- [sinatra-assetpack](https://github.com/rstacruz/sinatra-assetpack)
|
13
|
+
|
14
|
+
##Simple Usage
|
15
|
+
|
16
|
+
### Gemfile
|
17
|
+
Add to your Gemfile:
|
9
18
|
```ruby
|
10
|
-
gem 'padrino-
|
19
|
+
gem 'padrino-pipeline'
|
11
20
|
```
|
12
21
|
|
13
|
-
|
22
|
+
These examples examples setup a pipeline with defaulted options(see default options):
|
14
23
|
|
24
|
+
### Sprockets pipeline
|
15
25
|
```ruby
|
16
|
-
module
|
26
|
+
module Example
|
17
27
|
class App < Padrino::Application
|
18
|
-
register Padrino::
|
19
|
-
configure_assets do |
|
20
|
-
|
28
|
+
register Padrino::Pipeline
|
29
|
+
configure_assets do |config|
|
30
|
+
config.pipeline = Padrino::Pipeline::Sprockets
|
21
31
|
end
|
22
32
|
end
|
23
33
|
end
|
24
34
|
```
|
25
35
|
|
26
|
-
|
27
|
-
from http://localhost:3000/assets/javascripts and http://localhost:3000/assets/styleseets
|
28
|
-
|
29
|
-
##Usage with options
|
36
|
+
### Sinatra AssetPack pipeline
|
30
37
|
```ruby
|
31
|
-
module
|
38
|
+
module Example
|
32
39
|
class App < Padrino::Application
|
33
|
-
register Padrino::
|
40
|
+
register Padrino::Pipeline
|
41
|
+
configure_assets do |config|
|
42
|
+
config.pipeline = Padrino::Pipeline::AssetPack
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
34
47
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assets.js_prefix = '/custom/location' # defaults to /assets/javascripts
|
39
|
-
assets.css_prefix = '/custom/stylesheets' # defaults to /assets/stylesheets
|
48
|
+
## Options
|
49
|
+
Certain options can be configured to change the behavior of the pipelines.
|
50
|
+
These options should be used within the configure_assets block.
|
40
51
|
|
41
|
-
|
52
|
+
for example:
|
53
|
+
```ruby
|
54
|
+
module Example
|
55
|
+
class App < Padrino::Application
|
56
|
+
register Padrino::Pipeline
|
57
|
+
configure_assets do |config|
|
58
|
+
config.pipeline = Padrino::Pipeline::AssetPack
|
59
|
+
config.css_prefix = '/xyz'
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
45
63
|
```
|
46
64
|
|
47
|
-
|
48
|
-
app/assets/javascripts/app.js
|
65
|
+
The following options can be set
|
49
66
|
|
50
|
-
|
51
|
-
|
67
|
+
### Pipeline
|
68
|
+
- #pipeline
|
52
69
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
function stuff() {
|
70
|
+
### Assets URI(mounting location) String
|
71
|
+
- #css_prefix
|
72
|
+
- #js_prefix
|
57
73
|
|
58
|
-
|
59
|
-
|
74
|
+
### Asset location(path to files) String/Array
|
75
|
+
- #css_assets
|
76
|
+
- #js_assets
|
77
|
+
|
78
|
+
### Prefix prepend this prefix before all assets
|
79
|
+
- #prefix
|
80
|
+
|
81
|
+
### Default option values
|
82
|
+
TODO
|
83
|
+
|
84
|
+
## Asset pack packages
|
85
|
+
TODO
|
60
86
|
|
87
|
+
## Sprocket directive require/include/require tree
|
88
|
+
TODO
|
data/lib/padrino-pipeline.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'sinatra/assetpack' unless defined? Sinatra::AssetPack
|
2
|
+
require 'padrino-pipeline/pipelines/common'
|
2
3
|
|
3
4
|
module Padrino
|
4
5
|
module Pipeline
|
5
6
|
class AssetPack
|
7
|
+
include Padrino::Pipeline::Common
|
8
|
+
|
6
9
|
def initialize(app, config)
|
7
10
|
@app = app
|
8
11
|
@config = config
|
@@ -10,22 +13,6 @@ module Padrino
|
|
10
13
|
setup_pipeline
|
11
14
|
end
|
12
15
|
|
13
|
-
def js_prefix
|
14
|
-
(@config.prefix || '') + (@config.js_prefix || '/assets/javascripts')
|
15
|
-
end
|
16
|
-
|
17
|
-
def css_prefix
|
18
|
-
(@config.prefix || '') + (@config.css_prefix || '/assets/stylesheets')
|
19
|
-
end
|
20
|
-
|
21
|
-
def js_assets
|
22
|
-
@config.js_assets || 'assets/javascripts'
|
23
|
-
end
|
24
|
-
|
25
|
-
def css_assets
|
26
|
-
@config.css_assets || 'assets/stylesheets'
|
27
|
-
end
|
28
|
-
|
29
16
|
def packages
|
30
17
|
@config.packages || []
|
31
18
|
end
|
@@ -37,13 +24,22 @@ module Padrino
|
|
37
24
|
end
|
38
25
|
|
39
26
|
def setup_pipeline
|
40
|
-
js_prefix, css_prefix
|
41
|
-
js_assets, css_assets
|
42
|
-
packages
|
27
|
+
js_prefix, css_prefix, image_prefix = self.js_prefix, self.css_prefix, self.image_prefix
|
28
|
+
js_assets, css_assets, image_assets = self.js_assets, self.css_assets, self.image_assets
|
29
|
+
packages = self.packages
|
43
30
|
|
44
31
|
@app.assets {
|
45
|
-
|
46
|
-
|
32
|
+
def mount_asset(prefix, assets)
|
33
|
+
if assets.respond_to?(:each)
|
34
|
+
assets.each {|asset| serve prefix, :from => asset}
|
35
|
+
else
|
36
|
+
serve prefix, :from => assets
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
mount_asset js_prefix, js_assets
|
41
|
+
mount_asset css_prefix, css_assets
|
42
|
+
mount_asset image_prefix, image_assets
|
47
43
|
|
48
44
|
packages.each { |package| send(package.shift, *package) }
|
49
45
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Pipeline
|
3
|
+
module Common
|
4
|
+
|
5
|
+
def app_root
|
6
|
+
@app.settings.root
|
7
|
+
end
|
8
|
+
|
9
|
+
def js_assets
|
10
|
+
@config.js_assets || "#{app_root}/assets/javascripts"
|
11
|
+
end
|
12
|
+
|
13
|
+
def css_assets
|
14
|
+
@config.css_assets || "#{app_root}/assets/stylesheets"
|
15
|
+
end
|
16
|
+
|
17
|
+
def image_assets
|
18
|
+
@config.image_assets || "#{app_root}/assets/images"
|
19
|
+
end
|
20
|
+
|
21
|
+
def image_prefix
|
22
|
+
(@config.prefix || '') + (@config.image_prefix || '/assets/images')
|
23
|
+
end
|
24
|
+
|
25
|
+
def js_prefix
|
26
|
+
(@config.prefix || '') + (@config.js_prefix || '/assets/javascripts')
|
27
|
+
end
|
28
|
+
|
29
|
+
def css_prefix
|
30
|
+
(@config.prefix || '') + (@config.css_prefix || '/assets/stylesheets')
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'sprockets'
|
2
2
|
require 'uglifier'
|
3
|
-
require 'padrino-pipeline/
|
3
|
+
require 'padrino-pipeline/pipelines/common'
|
4
4
|
|
5
5
|
module Padrino
|
6
6
|
module Pipeline
|
7
7
|
class Sprockets
|
8
|
+
include Padrino::Pipeline::Common
|
9
|
+
|
8
10
|
def initialize(app, config)
|
9
|
-
@app
|
10
|
-
@config
|
11
|
+
@app = app
|
12
|
+
@config = config
|
11
13
|
setup_enviroment
|
12
14
|
setup_sprockets
|
13
15
|
end
|
14
16
|
|
15
17
|
private
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
["#{app_root}/assets/javascripts", "#{app_root}/assets/stylesheets"]
|
18
|
+
def paths
|
19
|
+
js_assets = self.js_assets.kind_of?(Array) ? self.js_assets : [self.js_assets]
|
20
|
+
css_assets = self.css_assets.kind_of?(Array) ? self.css_assets : [self.css_assets]
|
21
|
+
image_assets = self.image_assets.kind_of?(Array) ? self.image_assets : [self.image_assets]
|
22
|
+
js_assets + css_assets + image_assets
|
22
23
|
end
|
23
24
|
|
24
25
|
def setup_sprockets
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
paths.each { |path| @app.settings.assets.append_path path }
|
27
|
+
mount_js_assets js_prefix
|
28
|
+
mount_css_assets css_prefix
|
29
|
+
mount_image_assets image_prefix
|
29
30
|
end
|
30
31
|
|
31
32
|
def setup_enviroment
|
@@ -34,14 +35,18 @@ module Padrino
|
|
34
35
|
@app.settings.assets.js_compressor = Uglifier.new(:mangle => true)
|
35
36
|
end
|
36
37
|
|
38
|
+
def mount_image_assets(prefix)
|
39
|
+
mount_assets(:prefix => prefix)
|
40
|
+
end
|
41
|
+
|
37
42
|
def mount_js_assets(prefix)
|
38
|
-
mount_assets(:prefix => prefix,
|
43
|
+
mount_assets(:prefix => prefix,
|
39
44
|
:extension => "js",
|
40
45
|
:content_type => "application/javascript")
|
41
46
|
end
|
42
47
|
|
43
48
|
def mount_css_assets(prefix)
|
44
|
-
mount_assets(:prefix => prefix,
|
49
|
+
mount_assets(:prefix => prefix,
|
45
50
|
:extension => "css",
|
46
51
|
:content_type => "text/css")
|
47
52
|
end
|
@@ -50,9 +55,10 @@ module Padrino
|
|
50
55
|
prefix = options[:prefix]
|
51
56
|
extension = options[:extension]
|
52
57
|
content_type = options[:content_type]
|
53
|
-
@app.get "#{prefix}/:
|
54
|
-
|
55
|
-
|
58
|
+
@app.get "#{prefix}/:path.:ext" do |path, ext|
|
59
|
+
return not_found if (extension && ext != extension)
|
60
|
+
content_type(content_type || Rack::Mime::MIME_TYPES[".#{ext}"])
|
61
|
+
settings.assets["#{path}.#{ext}"] || not_found
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
+
|
3
|
+
shared_examples_for 'A Pipeline' do
|
4
|
+
describe 'default options' do
|
5
|
+
let(:app) { rack_app }
|
6
|
+
before do
|
7
|
+
pipeline = @pipeline
|
8
|
+
app_root = fixture_path('asset_pack_app')
|
9
|
+
mock_app do
|
10
|
+
set :root, app_root
|
11
|
+
register Padrino::Pipeline
|
12
|
+
configure_assets{ |c| c.pipeline = pipeline }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can get a stylesheet file' do
|
17
|
+
get '/assets/stylesheets/app.css'
|
18
|
+
assert_equal 200, last_response.status
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'makes sure that sass is compiled' do
|
22
|
+
get '/assets/stylesheets/default.css'
|
23
|
+
assert_equal 200, last_response.status
|
24
|
+
assert_match ".content {\n display: none; }\n", last_response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can not get a file other than .css' do
|
28
|
+
skip if @pipeline == Padrino::Pipeline::AssetPack #http_router issue :(
|
29
|
+
get '/assets/stylesheets/default.scss'
|
30
|
+
assert_equal 404, last_response.status
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'gives 404 for unknown files' do
|
34
|
+
skip if @pipeline == Padrino::Pipeline::AssetPack #http_router issue :(
|
35
|
+
get '/assets/stylesheets/omg.css'
|
36
|
+
assert_equal 404, last_response.status
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe 'custom options' do
|
42
|
+
let(:app) { rack_app }
|
43
|
+
before do
|
44
|
+
@assets_location = "#{fixture_path('asset_pack_app')}/assets/stylesheets"
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'get CSS asset from a custom location' do
|
48
|
+
assets_location = @assets_location
|
49
|
+
pipeline = @pipeline
|
50
|
+
mock_app do
|
51
|
+
register Padrino::Pipeline
|
52
|
+
configure_assets do |assets|
|
53
|
+
assets.pipeline = pipeline
|
54
|
+
assets.css_assets = assets_location
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
get '/assets/stylesheets/app.css'
|
59
|
+
assert_equal 200, last_response.status
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'get CSS asset from custom location(Array)' do
|
63
|
+
assets_location = @assets_location
|
64
|
+
pipeline = @pipeline
|
65
|
+
mock_app do
|
66
|
+
register Padrino::Pipeline
|
67
|
+
configure_assets do |assets|
|
68
|
+
assets.pipeline = pipeline
|
69
|
+
assets.css_assets = ['some/unknown/source', assets_location]
|
70
|
+
assets.css_prefix = '/custom/location'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
get '/custom/location/app.css'
|
74
|
+
assert_equal 200, last_response.status
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'get CSS asset form custom URI' do
|
78
|
+
assets_location = @assets_location
|
79
|
+
pipeline = @pipeline
|
80
|
+
mock_app do
|
81
|
+
register Padrino::Pipeline
|
82
|
+
configure_assets do |assets|
|
83
|
+
assets.pipeline = pipeline
|
84
|
+
assets.css_assets = assets_location
|
85
|
+
assets.css_prefix = '/custom/location'
|
86
|
+
end
|
87
|
+
end#mock-app
|
88
|
+
get '/custom/location/app.css'
|
89
|
+
assert_equal 200, last_response.status
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Padrino::Pipeline::Sprockets do
|
95
|
+
before { @pipeline = Padrino::Pipeline::Sprockets }
|
96
|
+
it_behaves_like 'A Pipeline'
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Padrino::Pipeline::AssetPack do
|
100
|
+
before { @pipeline = Padrino::Pipeline::AssetPack}
|
101
|
+
it_behaves_like 'A Pipeline'
|
102
|
+
end
|
103
|
+
|
104
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
+
|
3
|
+
shared_examples_for 'A Pipeline' do
|
4
|
+
describe 'default options' do
|
5
|
+
let(:app) { rack_app }
|
6
|
+
before do
|
7
|
+
pipeline = @pipeline
|
8
|
+
app_root = fixture_path('sprockets_app')
|
9
|
+
mock_app do
|
10
|
+
set :root, app_root
|
11
|
+
register Padrino::Pipeline
|
12
|
+
configure_assets{ |c| c.pipeline = pipeline }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can get an image' do
|
18
|
+
get '/assets/images/glass.png'
|
19
|
+
assert_equal 200, last_response.status
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have the right content type' do
|
23
|
+
get '/assets/images/glass.png'
|
24
|
+
assert_equal 'image/png', last_response.content_type
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gives 404 for unkown image files' do
|
28
|
+
skip if @pipeline == Padrino::Pipeline::AssetPack #http_router issue :(
|
29
|
+
get '/assets/images/unkown.png'
|
30
|
+
assert_equal 404, last_response.status
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'custom options' do
|
35
|
+
let(:app) { rack_app }
|
36
|
+
before do
|
37
|
+
@assets_location = "#{fixture_path('sprockets_app')}/assets/images"
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'get image asset from a custom location' do
|
41
|
+
assets_location = @assets_location
|
42
|
+
pipeline = @pipeline
|
43
|
+
mock_app do
|
44
|
+
register Padrino::Pipeline
|
45
|
+
configure_assets do |assets|
|
46
|
+
assets.pipeline = pipeline
|
47
|
+
assets.image_assets = assets_location
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/assets/images/glass.png'
|
52
|
+
assert_equal 200, last_response.status
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'get image asset from a custom location(Array)' do
|
56
|
+
assets_location = @assets_location
|
57
|
+
pipeline = @pipeline
|
58
|
+
mock_app do
|
59
|
+
register Padrino::Pipeline
|
60
|
+
configure_assets do |assets|
|
61
|
+
assets.pipeline = pipeline
|
62
|
+
assets.image_assets = ['some/unkown/place', assets_location]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
get '/assets/images/glass.png'
|
67
|
+
assert_equal 200, last_response.status
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'get image asset form custom URI' do
|
71
|
+
assets_location = @assets_location
|
72
|
+
pipeline = @pipeline
|
73
|
+
mock_app do
|
74
|
+
register Padrino::Pipeline
|
75
|
+
configure_assets do |assets|
|
76
|
+
assets.pipeline = pipeline
|
77
|
+
assets.image_assets = assets_location
|
78
|
+
assets.image_prefix = '/custom/location'
|
79
|
+
end
|
80
|
+
end#mock-app
|
81
|
+
get '/custom/location/glass.png'
|
82
|
+
assert_equal 200, last_response.status
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'get image asset form custom prefix' do
|
86
|
+
assets_location = @assets_location
|
87
|
+
pipeline = @pipeline
|
88
|
+
mock_app do
|
89
|
+
register Padrino::Pipeline
|
90
|
+
configure_assets do |assets|
|
91
|
+
assets.pipeline = pipeline
|
92
|
+
assets.image_assets = assets_location
|
93
|
+
assets.prefix = '/custom'
|
94
|
+
end
|
95
|
+
end#mock-app
|
96
|
+
get '/custom/assets/images/glass.png'
|
97
|
+
assert_equal 200, last_response.status
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe Padrino::Pipeline::Sprockets do
|
104
|
+
before { @pipeline = Padrino::Pipeline::Sprockets }
|
105
|
+
it_behaves_like 'A Pipeline'
|
106
|
+
end
|
107
|
+
|
108
|
+
describe Padrino::Pipeline::AssetPack do
|
109
|
+
before { @pipeline = Padrino::Pipeline::AssetPack}
|
110
|
+
it_behaves_like 'A Pipeline'
|
111
|
+
end
|
112
|
+
|
113
|
+
|
data/test/api/test_js.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
+
|
3
|
+
shared_examples_for 'A Pipeline' do
|
4
|
+
describe 'default options' do
|
5
|
+
let(:app) { rack_app }
|
6
|
+
before do
|
7
|
+
pipeline = @pipeline
|
8
|
+
app_root = fixture_path('asset_pack_app')
|
9
|
+
mock_app do
|
10
|
+
set :root, app_root
|
11
|
+
register Padrino::Pipeline
|
12
|
+
configure_assets{ |c| c.pipeline = pipeline }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'GET a basic JS file' do
|
17
|
+
get '/assets/javascripts/app.js'
|
18
|
+
assert_equal 200, last_response.status
|
19
|
+
assert_match 'var mainApp', last_response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'GET a coffee script file' do
|
23
|
+
get '/assets/javascripts/coffee.js'
|
24
|
+
assert_equal 200, last_response.status
|
25
|
+
assert_match 'coffee', last_response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'is the right content type' do
|
29
|
+
get '/assets/javascripts/app.js'
|
30
|
+
assert_match 'application/javascript', last_response.content_type
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can not get a file other than .js' do
|
34
|
+
skip if @pipeline == Padrino::Pipeline::AssetPack #http_router issue :(
|
35
|
+
get '/assets/javscripts/coffee.coffee'
|
36
|
+
assert_equal 404, last_response.status
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it 'gives 404 for unknown JS file' do
|
41
|
+
skip if @pipeline == Padrino::Pipeline::AssetPack #http_router issue :(
|
42
|
+
get '/assets/javascripts/doesnotexist.js'
|
43
|
+
assert_equal 404, last_response.status
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
describe 'custom options' do
|
49
|
+
let(:app) { rack_app }
|
50
|
+
before do
|
51
|
+
@assets_location = "#{fixture_path('asset_pack_app')}/assets/javascripts"
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'get JS asset from a custom location' do
|
55
|
+
assets_location = @assets_location
|
56
|
+
pipeline = @pipeline
|
57
|
+
mock_app do
|
58
|
+
register Padrino::Pipeline
|
59
|
+
configure_assets do |assets|
|
60
|
+
assets.pipeline = pipeline
|
61
|
+
assets.js_assets = assets_location
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
get '/assets/javascripts/app.js'
|
66
|
+
assert_equal 200, last_response.status
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'get JS asset from custom location(Array)' do
|
70
|
+
assets_location = @assets_location
|
71
|
+
pipeline = @pipeline
|
72
|
+
mock_app do
|
73
|
+
register Padrino::Pipeline
|
74
|
+
configure_assets do |assets|
|
75
|
+
assets.pipeline = pipeline
|
76
|
+
assets.js_assets = ['some/unknown/source', assets_location]
|
77
|
+
assets.js_prefix = '/custom/location'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
get '/custom/location/app.js'
|
81
|
+
assert_equal 200, last_response.status
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'get JS asset form custom URI' do
|
85
|
+
assets_location = @assets_location
|
86
|
+
pipeline = @pipeline
|
87
|
+
mock_app do
|
88
|
+
register Padrino::Pipeline
|
89
|
+
configure_assets do |assets|
|
90
|
+
assets.pipeline = pipeline
|
91
|
+
assets.js_assets = assets_location
|
92
|
+
assets.js_prefix = '/custom/location'
|
93
|
+
end
|
94
|
+
end#mock-app
|
95
|
+
get '/custom/location/app.js'
|
96
|
+
assert_equal 200, last_response.status
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe Padrino::Pipeline::Sprockets do
|
102
|
+
before { @pipeline = Padrino::Pipeline::Sprockets }
|
103
|
+
it_behaves_like 'A Pipeline'
|
104
|
+
end
|
105
|
+
|
106
|
+
describe Padrino::Pipeline::AssetPack do
|
107
|
+
before { @pipeline = Padrino::Pipeline::AssetPack}
|
108
|
+
it_behaves_like 'A Pipeline'
|
109
|
+
end
|
110
|
+
|
111
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
+
|
3
|
+
shared_examples_for 'A Pipeline' do
|
4
|
+
describe 'non-default options' do
|
5
|
+
let(:app) { rack_app }
|
6
|
+
before do
|
7
|
+
@assets_location = "#{fixture_path('asset_pack_app')}/assets/javascripts"
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'knows that assets should be served' do
|
11
|
+
pipeline = @pipeline
|
12
|
+
mock_app do
|
13
|
+
register Padrino::Pipeline
|
14
|
+
configure_assets {|c| c.pipeline = pipeline}
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal true, @app.serve_assets?
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can set a general prefix for all asset types' do
|
21
|
+
assets_location = @assets_location
|
22
|
+
pipeline = @pipeline
|
23
|
+
mock_app do
|
24
|
+
register Padrino::Pipeline
|
25
|
+
configure_assets do |assets|
|
26
|
+
assets.pipeline = pipeline
|
27
|
+
assets.js_assets = assets_location
|
28
|
+
assets.prefix = '/trunk'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/trunk/assets/javascripts/app.js'
|
33
|
+
assert_equal 200, last_response.status
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
describe Padrino::Pipeline::Sprockets do
|
40
|
+
before { @pipeline = Padrino::Pipeline::Sprockets }
|
41
|
+
it_behaves_like 'A Pipeline'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Padrino::Pipeline::AssetPack do
|
45
|
+
before { @pipeline = Padrino::Pipeline::AssetPack}
|
46
|
+
it_behaves_like 'A Pipeline'
|
47
|
+
end
|
data/test/extra/helper.rb
CHANGED
@@ -28,6 +28,27 @@ class MiniTest::Spec
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
MiniTest::Spec.class_eval do
|
32
|
+
def self.shared_examples
|
33
|
+
@shared_examples ||= {}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module MiniTest::Spec::SharedExamples
|
38
|
+
def shared_examples_for(desc, &block)
|
39
|
+
MiniTest::Spec.shared_examples[desc] = block
|
40
|
+
end
|
41
|
+
|
42
|
+
def it_behaves_like(desc)
|
43
|
+
self.instance_eval do
|
44
|
+
MiniTest::Spec.shared_examples[desc].call
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Object.class_eval { include(MiniTest::Spec::SharedExamples) }
|
50
|
+
|
51
|
+
|
31
52
|
module Webrat
|
32
53
|
module Logging
|
33
54
|
def logger # @private
|
@@ -22,10 +22,10 @@ class AssetsAppAssetPackCustom < BaseApp
|
|
22
22
|
configure_assets do |config|
|
23
23
|
config.pipeline = Padrino::Pipeline::AssetPack
|
24
24
|
config.js_prefix = '/meow/javascripts'
|
25
|
-
config.js_assets = '
|
25
|
+
config.js_assets = 'assets/js'
|
26
26
|
|
27
27
|
config.css_prefix = '/meow/stylesheets'
|
28
|
-
config.css_assets = '
|
28
|
+
config.css_assets = 'assets/css'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -12,8 +12,8 @@ describe 'Asset tags' do
|
|
12
12
|
register Padrino::Pipeline
|
13
13
|
register Padrino::Helpers
|
14
14
|
configure_assets do |assets|
|
15
|
-
assets.pipeline
|
16
|
-
assets.
|
15
|
+
assets.pipeline = Padrino::Pipeline::Sprockets
|
16
|
+
assets.js_assets = [assets_location]
|
17
17
|
end
|
18
18
|
get('/') { render :erb, "<%= javascript_include_tag 'app.js' %>" }
|
19
19
|
end
|
data/test/sprockets/test_js.rb
CHANGED
@@ -4,76 +4,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../fixtures/sprockets_app/sp
|
|
4
4
|
|
5
5
|
describe 'Javascripts' do
|
6
6
|
let(:app) { AssetsAppSprockets }
|
7
|
-
context 'for
|
8
|
-
it '
|
9
|
-
get '/assets/javascripts/
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'is compiled' do
|
14
|
-
get '/assets/javascripts/coffee.js'
|
15
|
-
assert_match 'a="yes"', last_response.body
|
7
|
+
context 'for //= require' do
|
8
|
+
it 'picks up require statements' do
|
9
|
+
get '/assets/javascripts/app.js'
|
10
|
+
assert_match 'var in_second_file;', last_response.body
|
16
11
|
end
|
17
12
|
end
|
18
|
-
|
19
|
-
context 'for javascript assets' do
|
20
|
-
it 'can retrieve a js asset by file name' do
|
21
|
-
get '/assets/javascripts/unrequired.js'
|
22
|
-
assert_match 'var unrequired;', last_response.body
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'is the right content type' do
|
26
|
-
get '/assets/javascripts/unrequired.js'
|
27
|
-
assert_match 'application/javascript', last_response.content_type
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'shows a 404 for unkown assets' do
|
31
|
-
get '/assets/javascripts/xyz.js'
|
32
|
-
assert_not_equal 200, last_response.status
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'for //= require' do
|
36
|
-
it 'picks up require statements' do
|
37
|
-
get '/assets/javascripts/app.js'
|
38
|
-
assert_match 'var in_second_file;', last_response.body
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'for custom options' do
|
43
|
-
let(:app) { rack_app }
|
44
|
-
before do
|
45
|
-
@assets_location = "#{fixture_path('sprockets_app')}/assets/javascripts"
|
46
|
-
end
|
47
|
-
|
48
|
-
it '#append_asset_path' do
|
49
|
-
assets_location = @assets_location
|
50
|
-
mock_app do
|
51
|
-
register Padrino::Pipeline
|
52
|
-
configure_assets do |assets|
|
53
|
-
assets.pipeline = Padrino::Pipeline::Sprockets
|
54
|
-
assets.paths = [assets_location]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
get '/assets/javascripts/app.js'
|
59
|
-
assert_match 'var in_second_file', last_response.body
|
60
|
-
end
|
61
|
-
|
62
|
-
it '#js_prefix mounts assets to the correct spot' do
|
63
|
-
assets_location = @assets_location
|
64
|
-
mock_app do
|
65
|
-
register Padrino::Pipeline
|
66
|
-
configure_assets do |assets|
|
67
|
-
assets.pipeline = Padrino::Pipeline::Sprockets
|
68
|
-
assets.paths = [assets_location]
|
69
|
-
assets.js_prefix = '/custom/location'
|
70
|
-
end
|
71
|
-
end#mock-app
|
72
|
-
get '/custom/location/app.js'
|
73
|
-
assert_match 'var in_second_file', last_response.body
|
74
|
-
assert_equal 200, last_response.status
|
75
|
-
end
|
76
|
-
|
77
|
-
end#context
|
78
|
-
end#context
|
13
|
+
|
79
14
|
end#describe
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sumeet Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: padrino-core
|
@@ -138,11 +138,14 @@ files:
|
|
138
138
|
- lib/padrino-pipeline.rb
|
139
139
|
- lib/padrino-pipeline/ext/padrino-helpers/asset_tag_helper.rb
|
140
140
|
- lib/padrino-pipeline/pipelines/asset_pack.rb
|
141
|
+
- lib/padrino-pipeline/pipelines/common.rb
|
141
142
|
- lib/padrino-pipeline/pipelines/sprockets.rb
|
142
143
|
- lib/padrino-pipeline/version.rb
|
143
144
|
- padrino-pipeline.gemspec
|
144
|
-
- test/
|
145
|
-
- test/
|
145
|
+
- test/api/test_css.rb
|
146
|
+
- test/api/test_images.rb
|
147
|
+
- test/api/test_js.rb
|
148
|
+
- test/api/test_other.rb
|
146
149
|
- test/asset_pack/test_packages.rb
|
147
150
|
- test/extra/helper.rb
|
148
151
|
- test/extra/mini_shoulda.rb
|
@@ -165,8 +168,6 @@ files:
|
|
165
168
|
- test/fixtures/sprockets_app/assets/stylesheets/second_file.css
|
166
169
|
- test/fixtures/sprockets_app/sprockets_app.rb
|
167
170
|
- test/sprockets/test_asset_tag.rb
|
168
|
-
- test/sprockets/test_assets.rb
|
169
|
-
- test/sprockets/test_css.rb
|
170
171
|
- test/sprockets/test_js.rb
|
171
172
|
homepage: http://www.padrinorb.com
|
172
173
|
licenses: []
|
@@ -193,8 +194,10 @@ signing_key:
|
|
193
194
|
specification_version: 4
|
194
195
|
summary: The Padrino asset management system
|
195
196
|
test_files:
|
196
|
-
- test/
|
197
|
-
- test/
|
197
|
+
- test/api/test_css.rb
|
198
|
+
- test/api/test_images.rb
|
199
|
+
- test/api/test_js.rb
|
200
|
+
- test/api/test_other.rb
|
198
201
|
- test/asset_pack/test_packages.rb
|
199
202
|
- test/extra/helper.rb
|
200
203
|
- test/extra/mini_shoulda.rb
|
@@ -217,7 +220,5 @@ test_files:
|
|
217
220
|
- test/fixtures/sprockets_app/assets/stylesheets/second_file.css
|
218
221
|
- test/fixtures/sprockets_app/sprockets_app.rb
|
219
222
|
- test/sprockets/test_asset_tag.rb
|
220
|
-
- test/sprockets/test_assets.rb
|
221
|
-
- test/sprockets/test_css.rb
|
222
223
|
- test/sprockets/test_js.rb
|
223
224
|
has_rdoc:
|
data/test/asset_pack/test_css.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/asset_pack_app/asset_pack_app')
|
3
|
-
|
4
|
-
describe 'AssetPack Stylesheets' do
|
5
|
-
let(:app) { AssetsAppAssetPack }
|
6
|
-
|
7
|
-
it 'can get a stylesheet file' do
|
8
|
-
get '/assets/stylesheets/app.css'
|
9
|
-
assert_equal 200, last_response.status
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'makes sure that sass is compiled' do
|
13
|
-
get '/assets/stylesheets/default.css'
|
14
|
-
assert_equal 200, last_response.status
|
15
|
-
assert_match ".content {\n display: none; }\n", last_response.body
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'gives 404 for unknown files' do
|
19
|
-
get '/assets/stylesheets/omg.css'
|
20
|
-
assert_equal 404, last_response.status
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'for non-defualt options' do
|
24
|
-
let(:app) { AssetsAppAssetPackCustom }
|
25
|
-
|
26
|
-
it 'can serve from another stylesheets path' do
|
27
|
-
get '/meow/stylesheets/meow.css'
|
28
|
-
assert_equal 200, last_response.status
|
29
|
-
assert_match '.meow', last_response.body
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
data/test/asset_pack/test_js.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/asset_pack_app/asset_pack_app')
|
3
|
-
|
4
|
-
describe 'AssetPack Javascripts' do
|
5
|
-
let(:app) { AssetsAppAssetPack }
|
6
|
-
|
7
|
-
it 'can get a javascript file' do
|
8
|
-
get '/assets/javascripts/app.js'
|
9
|
-
assert_equal 200, last_response.status
|
10
|
-
assert_match 'var mainApp = true;', last_response.body
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'makes sure that coffeescript is compiled' do
|
14
|
-
get '/assets/javascripts/coffee.js'
|
15
|
-
assert_equal 200, last_response.status
|
16
|
-
assert_match 'coffee = true', last_response.body
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'gives 404 for unknown files' do
|
20
|
-
get '/assets/javascripts/omg.js'
|
21
|
-
assert_equal 404, last_response.status
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'for non-defualt options' do
|
25
|
-
let(:app) { AssetsAppAssetPackCustom }
|
26
|
-
|
27
|
-
it 'can serve from another javascript path' do
|
28
|
-
get '/meow/javascripts/myapp.js'
|
29
|
-
assert_equal 200, last_response.status
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
-
|
3
|
-
describe Padrino::Pipeline do
|
4
|
-
let(:app) { AssetsAppSprockets }
|
5
|
-
|
6
|
-
context 'for application behavior' do
|
7
|
-
it 'knows that assets should be served' do
|
8
|
-
assert_equal app.serve_assets?, true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'detects the root location of the running app' do
|
12
|
-
app_path = fixture_path('sprockets_app')
|
13
|
-
assert_equal app_path, app.root
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'general options' do
|
18
|
-
let(:app) { rack_app }
|
19
|
-
|
20
|
-
before do
|
21
|
-
@assets_location = "#{fixture_path('sprockets_app')}/assets/javascripts"
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'can set a general prefix for all asset types' do
|
25
|
-
assets_location = @assets_location
|
26
|
-
mock_app do
|
27
|
-
register Padrino::Pipeline
|
28
|
-
configure_assets do |assets|
|
29
|
-
assets.pipeline = Padrino::Pipeline::Sprockets
|
30
|
-
assets.paths = [assets_location]
|
31
|
-
assets.prefix = '/trunk'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
get '/trunk/assets/javascripts/app.js'
|
36
|
-
assert_equal 200, last_response.status
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end#describe
|
data/test/sprockets/test_css.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
-
|
3
|
-
describe 'Stylesheets' do
|
4
|
-
let(:app) { AssetsAppSprockets }
|
5
|
-
|
6
|
-
context 'for css assets' do
|
7
|
-
it 'can retrieve an css asset by file name' do
|
8
|
-
get '/assets/stylesheets/application.css'
|
9
|
-
assert_equal 200, last_response.status
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'is the right content type' do
|
13
|
-
get '/assets/stylesheets/application.css'
|
14
|
-
assert_match 'text/css', last_response.content_type
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'works with directives' do
|
18
|
-
get '/assets/stylesheets/application.css'
|
19
|
-
assert_match '.home {', last_response.body
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'for SASS assets' do
|
23
|
-
|
24
|
-
it 'can retrieve a .scss asset by file name' do
|
25
|
-
get '/assets/stylesheets/sass.css'
|
26
|
-
assert_match 'body .div', last_response.body
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'for custom options' do
|
32
|
-
let(:app) { rack_app }
|
33
|
-
before do
|
34
|
-
@assets_location = "#{fixture_path('sprockets_app')}/assets/stylesheets"
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'can modify the default asset path by configuration' do
|
38
|
-
assets_location = "#{fixture_path('sprockets_app')}/assets/other"
|
39
|
-
mock_app do
|
40
|
-
register Padrino::Pipeline
|
41
|
-
configure_assets do |assets|
|
42
|
-
assets.pipeline = Padrino::Pipeline::Sprockets
|
43
|
-
assets.paths = [assets_location]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
get '/assets/stylesheets/other.css'
|
48
|
-
assert_equal 200, last_response.status
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'can modify the default css prefix by configuration' do
|
52
|
-
assets_location = @assets_location
|
53
|
-
mock_app do
|
54
|
-
register Padrino::Pipeline
|
55
|
-
configure_assets do |assets|
|
56
|
-
assets.pipeline = Padrino::Pipeline::Sprockets
|
57
|
-
assets.paths = [assets_location]
|
58
|
-
assets.css_prefix = '/myassets/items'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
get '/myassets/items/application.css'
|
63
|
-
assert_equal 200, last_response.status
|
64
|
-
end
|
65
|
-
|
66
|
-
end #context
|
67
|
-
end #context
|
68
|
-
end #describe
|