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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae583739b857e66675c501c51fb349afe552eb7
4
- data.tar.gz: 6401ed2ffbe33dba531735a533f79b15b911e411
3
+ metadata.gz: 14f082abda1188fbc0576b04796503d7067fa9c6
4
+ data.tar.gz: bc74e3d743a9fc243caeaf39b911d6b008463da0
5
5
  SHA512:
6
- metadata.gz: a3b001b81d9e56971e911575aaa4faec94da4859db068ceef9b52863bc576c9cb2e2af3ad8094edb5017f0dc4d3cc232ba1c35dadba5079359991b9004f92af1
7
- data.tar.gz: 015dc113ce5d617544322d968807d5236e641c6041590e940e15b4881f71b6d5fd624094c4b8124a6c7e9e76fafd1ec8699a4247cead44b68d6300502796f137
6
+ metadata.gz: c923aab61e2b1c0a04143993cb9fe42114df3a2de17f8120ce4ab6c61354b0119dbeefab02674c6ee290463448d5372fa6abfd408dbab41d3dfc65d1a420dfbd
7
+ data.tar.gz: 52eb92c79db4d701ba3d7313e6d9f4cc5f32fc5fd4e04adc7ecbb89da72b58bd80a6d8fdfe4497d003eea9003d3f4075ab12e94dcdb960b6c722ee7163b69539
data/.travis.yml CHANGED
@@ -8,7 +8,7 @@ rvm:
8
8
  - 1.9.3
9
9
  - 2.0.0
10
10
  - rbx-18mode
11
- - jruby-19mode
11
+ - jruby-19mode-1.7.4
12
12
  branches:
13
13
  only:
14
14
  - master
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
  gem "rake"
5
- gem "nokogiri", "~> 1.5.10"
5
+ (RUBY_VERSION < "1.9") ? gem("nokogiri", "~> 1.5.10") : gem("nokogiri", "~> 1.6")
6
6
 
7
7
  group :test do
8
8
  gem "webrat", ">= 0.5.1"
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
- TODO
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 = 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
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
- js_compression :uglify
47
- css_compression :simple
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 = 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]
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
- @app.settings.assets.js_compressor = Uglifier.new(:mangle => true)
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)
@@ -1,5 +1,5 @@
1
1
  module Padrino
2
2
  module Pipeline
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -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 'ostruct'
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 = OpenStruct.new
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 {\n display: none; }\n", last_response.body
24
+ assert_match ".content", last_response.body
25
25
  end
26
26
 
27
27
  it 'can not get a file other than .css' do
@@ -1 +1,4 @@
1
1
  var mainApp = true;
2
+ function test() {
3
+
4
+ }
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.1
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 00:00:00.000000000 Z
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