padrino-pipeline 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +12 -1
- data/lib/padrino-pipeline/configuration.rb +44 -0
- data/lib/padrino-pipeline/pipelines/asset_pack.rb +9 -9
- data/lib/padrino-pipeline/pipelines/sprockets.rb +10 -9
- data/lib/padrino-pipeline/version.rb +1 -1
- data/lib/padrino-pipeline.rb +2 -3
- data/test/api/test_compression.rb +40 -0
- data/test/api/test_css.rb +1 -1
- data/test/fixtures/asset_pack_app/assets/javascripts/app.js +3 -0
- metadata +5 -3
- data/lib/padrino-pipeline/pipelines/common.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14f082abda1188fbc0576b04796503d7067fa9c6
|
4
|
+
data.tar.gz: bc74e3d743a9fc243caeaf39b911d6b008463da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c923aab61e2b1c0a04143993cb9fe42114df3a2de17f8120ce4ab6c61354b0119dbeefab02674c6ee290463448d5372fa6abfd408dbab41d3dfc65d1a420dfbd
|
7
|
+
data.tar.gz: 52eb92c79db4d701ba3d7313e6d9f4cc5f32fc5fd4e04adc7ecbb89da72b58bd80a6d8fdfe4497d003eea9003d3f4075ab12e94dcdb960b6c722ee7163b69539
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -82,7 +82,18 @@ The following options can be set
|
|
82
82
|
TODO
|
83
83
|
|
84
84
|
## Asset pack packages
|
85
|
-
|
85
|
+
```ruby
|
86
|
+
module Example
|
87
|
+
class App < Padrino::Application
|
88
|
+
register Padrino::Pipeline
|
89
|
+
configure_assets do |config|
|
90
|
+
config.pipeline = Padrino::Pipeline::AssetPack
|
91
|
+
config.packages << [:js, :application, '/assets/javascripts/application.js', ['/assets/javascripts/*.js']]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
Will serve /assets/javascripts/application.js as a bundle
|
86
97
|
|
87
98
|
## Sprocket directive require/include/require tree
|
88
99
|
TODO
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Pipeline
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
attr_accessor :pipeline, :packages, :prefix
|
6
|
+
attr_accessor :css_prefix, :js_prefix, :image_prefix
|
7
|
+
attr_accessor :css_assets, :js_assets, :image_assets
|
8
|
+
attr_accessor :enable_compression
|
9
|
+
|
10
|
+
def initialize(app)
|
11
|
+
@app = app
|
12
|
+
@packages = []
|
13
|
+
@image_prefix = '/assets/images'
|
14
|
+
@js_prefix = '/assets/javascripts'
|
15
|
+
@css_prefix = '/assets/stylesheets'
|
16
|
+
|
17
|
+
@image_assets = "#{app_root}/assets/images"
|
18
|
+
@js_assets = "#{app_root}/assets/javascripts"
|
19
|
+
@css_assets = "#{app_root}/assets/stylesheets"
|
20
|
+
end
|
21
|
+
|
22
|
+
def app_root
|
23
|
+
@app.settings.root
|
24
|
+
end
|
25
|
+
|
26
|
+
def image_prefix
|
27
|
+
"#{prefix || ''}#{@image_prefix}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def js_prefix
|
31
|
+
"#{prefix || ''}#{@js_prefix}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def css_prefix
|
35
|
+
"#{prefix || ''}#{@css_prefix}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def serve_compressed?
|
39
|
+
enable_compression || PADRINO_ENV == "production"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'sinatra/assetpack' unless defined? Sinatra::AssetPack
|
2
|
-
require 'padrino-pipeline/pipelines/common'
|
3
2
|
|
4
3
|
module Padrino
|
5
4
|
module Pipeline
|
6
5
|
class AssetPack
|
7
|
-
include Padrino::Pipeline::Common
|
8
6
|
|
9
7
|
def initialize(app, config)
|
10
8
|
@app = app
|
@@ -24,9 +22,10 @@ module Padrino
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def setup_pipeline
|
27
|
-
js_prefix, css_prefix, image_prefix =
|
28
|
-
js_assets, css_assets, image_assets =
|
29
|
-
packages
|
25
|
+
js_prefix, css_prefix, image_prefix = @config.js_prefix, @config.css_prefix, @config.image_prefix
|
26
|
+
js_assets, css_assets, image_assets = @config.js_assets, @config.css_assets, @config.image_assets
|
27
|
+
packages = self.packages
|
28
|
+
compression_enabled = @config.serve_compressed?
|
30
29
|
|
31
30
|
@app.assets {
|
32
31
|
def mount_asset(prefix, assets)
|
@@ -41,10 +40,11 @@ module Padrino
|
|
41
40
|
mount_asset css_prefix, css_assets
|
42
41
|
mount_asset image_prefix, image_assets
|
43
42
|
|
44
|
-
packages.each { |package| send(package.shift, *package) }
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
packages.each { |package| send(package.shift, *package) }
|
44
|
+
if compression_enabled
|
45
|
+
js_compression :uglify
|
46
|
+
css_compression :sass
|
47
|
+
end
|
48
48
|
}
|
49
49
|
end
|
50
50
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'sprockets'
|
2
2
|
require 'uglifier'
|
3
|
-
require 'padrino-pipeline/pipelines/common'
|
4
3
|
|
5
4
|
module Padrino
|
6
5
|
module Pipeline
|
7
6
|
class Sprockets
|
8
|
-
include Padrino::Pipeline::Common
|
9
7
|
|
10
8
|
def initialize(app, config)
|
11
9
|
@app = app
|
@@ -16,23 +14,26 @@ module Padrino
|
|
16
14
|
|
17
15
|
private
|
18
16
|
def paths
|
19
|
-
js_assets
|
20
|
-
css_assets
|
21
|
-
image_assets =
|
17
|
+
js_assets = @config.js_assets.kind_of?(Array) ? @config.js_assets : [@config.js_assets]
|
18
|
+
css_assets = @config.css_assets.kind_of?(Array) ? @config.css_assets : [@config.css_assets]
|
19
|
+
image_assets = @config.image_assets.kind_of?(Array) ? @config.image_assets : [@config.image_assets]
|
22
20
|
js_assets + css_assets + image_assets
|
23
21
|
end
|
24
22
|
|
25
23
|
def setup_sprockets
|
26
24
|
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
|
25
|
+
mount_js_assets @config.js_prefix
|
26
|
+
mount_css_assets @config.css_prefix
|
27
|
+
mount_image_assets @config.image_prefix
|
30
28
|
end
|
31
29
|
|
32
30
|
def setup_enviroment
|
33
31
|
@app.set :serve_assets, true
|
34
32
|
@app.set :assets, ::Sprockets::Environment.new
|
35
|
-
@
|
33
|
+
if @config.serve_compressed?
|
34
|
+
@app.settings.assets.js_compressor = Uglifier.new(:mangle => true)
|
35
|
+
@app.settings.assets.css_compressor = :sass
|
36
|
+
end
|
36
37
|
end
|
37
38
|
|
38
39
|
def mount_image_assets(prefix)
|
data/lib/padrino-pipeline.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'padrino-pipeline/pipelines/sprockets'
|
2
2
|
require 'padrino-pipeline/pipelines/asset_pack'
|
3
3
|
require 'padrino-pipeline/ext/padrino-helpers/asset_tag_helper'
|
4
|
-
require '
|
4
|
+
require 'padrino-pipeline/configuration'
|
5
5
|
|
6
6
|
module Padrino
|
7
7
|
##
|
@@ -9,8 +9,7 @@ module Padrino
|
|
9
9
|
module Pipeline
|
10
10
|
|
11
11
|
def configure_assets(&block)
|
12
|
-
assets =
|
13
|
-
assets.packages = []
|
12
|
+
assets = Padrino::Pipeline::Configuration.new(self)
|
14
13
|
yield assets if block_given?
|
15
14
|
assets.pipeline.new(self, assets)
|
16
15
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../extra/helper')
|
2
|
+
|
3
|
+
shared_examples_for 'A Pipeline' do
|
4
|
+
describe 'compression' do
|
5
|
+
let(:app) { rack_app }
|
6
|
+
before do
|
7
|
+
assets_location = "#{fixture_path('asset_pack_app')}/assets/"
|
8
|
+
pipeline = @pipeline
|
9
|
+
mock_app do
|
10
|
+
register Padrino::Pipeline
|
11
|
+
configure_assets do |config|
|
12
|
+
config.pipeline = pipeline
|
13
|
+
config.css_assets = "#{assets_location}/stylesheets"
|
14
|
+
config.js_assets = "#{assets_location}/javascripts"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not compress css in development mode' do
|
20
|
+
get '/assets/stylesheets/app.css'
|
21
|
+
assert_match "body {\n", last_response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should not compress js in development mode' do
|
25
|
+
get '/assets/javascripts/app.js'
|
26
|
+
assert_match "function test() {\n", last_response.body
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Padrino::Pipeline::Sprockets do
|
33
|
+
before { @pipeline = Padrino::Pipeline::Sprockets }
|
34
|
+
it_behaves_like 'A Pipeline'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe Padrino::Pipeline::AssetPack do
|
38
|
+
before { @pipeline = Padrino::Pipeline::AssetPack}
|
39
|
+
it_behaves_like 'A Pipeline'
|
40
|
+
end
|
data/test/api/test_css.rb
CHANGED
@@ -21,7 +21,7 @@ shared_examples_for 'A Pipeline' do
|
|
21
21
|
it 'makes sure that sass is compiled' do
|
22
22
|
get '/assets/stylesheets/default.css'
|
23
23
|
assert_equal 200, last_response.status
|
24
|
-
assert_match ".content
|
24
|
+
assert_match ".content", last_response.body
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'can not get a file other than .css' do
|
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.2
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: padrino-core
|
@@ -136,12 +136,13 @@ files:
|
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
138
|
- lib/padrino-pipeline.rb
|
139
|
+
- lib/padrino-pipeline/configuration.rb
|
139
140
|
- lib/padrino-pipeline/ext/padrino-helpers/asset_tag_helper.rb
|
140
141
|
- lib/padrino-pipeline/pipelines/asset_pack.rb
|
141
|
-
- lib/padrino-pipeline/pipelines/common.rb
|
142
142
|
- lib/padrino-pipeline/pipelines/sprockets.rb
|
143
143
|
- lib/padrino-pipeline/version.rb
|
144
144
|
- padrino-pipeline.gemspec
|
145
|
+
- test/api/test_compression.rb
|
145
146
|
- test/api/test_css.rb
|
146
147
|
- test/api/test_images.rb
|
147
148
|
- test/api/test_js.rb
|
@@ -194,6 +195,7 @@ signing_key:
|
|
194
195
|
specification_version: 4
|
195
196
|
summary: The Padrino asset management system
|
196
197
|
test_files:
|
198
|
+
- test/api/test_compression.rb
|
197
199
|
- test/api/test_css.rb
|
198
200
|
- test/api/test_images.rb
|
199
201
|
- test/api/test_js.rb
|
@@ -1,35 +0,0 @@
|
|
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
|