active_assets 0.3.1 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -22
- data/Rakefile +2 -0
- data/active_assets.gemspec +2 -5
- data/lib/active_assets.rb +3 -11
- data/lib/active_assets/active_expansions.rb +10 -17
- data/lib/active_assets/active_expansions/assets.rb +1 -1
- data/lib/active_assets/active_expansions/configurable.rb +14 -0
- data/lib/active_assets/active_expansions/expansion.rb +1 -0
- data/lib/active_assets/active_expansions/expansions.rb +5 -13
- data/lib/active_assets/active_expansions/railtie.rb +1 -1
- data/lib/active_assets/active_sprites.rb +31 -14
- data/lib/active_assets/active_sprites/configurable.rb +13 -0
- data/lib/active_assets/active_sprites/railtie.rb +1 -1
- data/lib/active_assets/active_sprites/runners/abstract_runner.rb +11 -23
- data/lib/active_assets/active_sprites/sprite_piece.rb +2 -0
- data/lib/active_assets/active_sprites/sprites.rb +14 -20
- data/lib/tasks/active_expansions/cache.rake +6 -0
- data/lib/tasks/active_sprites/sprites.rake +5 -0
- data/test/active_assets/active_expansions/expansions_test.rb +0 -12
- data/test/helper.rb +5 -2
- data/test/support/rails_helper.rb +5 -17
- metadata +52 -227
- data/lib/active_assets/rails2_support.rb +0 -32
- data/rails_generators/active_assets/USAGE +0 -0
- data/rails_generators/active_assets/active_assets_generator.rb +0 -8
- data/rails_generators/active_assets/templates/active_assets.rake +0 -4
- data/rails_generators/active_assets/templates/active_assets.rb +0 -57
- data/test/fixtures/rails_root_23/Rakefile +0 -10
- data/test/fixtures/rails_root_23/config/assets/assets.rb +0 -71
- data/test/fixtures/rails_root_23/config/boot.rb +0 -113
- data/test/fixtures/rails_root_23/config/environment.rb +0 -41
- data/test/fixtures/rails_root_23/config/environments/development.rb +0 -17
- data/test/fixtures/rails_root_23/config/environments/production.rb +0 -28
- data/test/fixtures/rails_root_23/config/environments/test.rb +0 -28
- data/test/fixtures/rails_root_23/config/initializers/active_assets.rb +0 -53
- data/test/fixtures/rails_root_23/config/initializers/backtrace_silencers.rb +0 -7
- data/test/fixtures/rails_root_23/config/initializers/cookie_verification_secret.rb +0 -7
- data/test/fixtures/rails_root_23/config/initializers/inflections.rb +0 -10
- data/test/fixtures/rails_root_23/config/initializers/mime_types.rb +0 -5
- data/test/fixtures/rails_root_23/config/initializers/new_rails_defaults.rb +0 -21
- data/test/fixtures/rails_root_23/config/initializers/session_store.rb +0 -15
- data/test/fixtures/rails_root_23/config/locales/en.yml +0 -5
- data/test/fixtures/rails_root_23/config/routes.rb +0 -43
- data/test/fixtures/rails_root_23/config/sprites.rb +0 -14
- data/test/fixtures/rails_root_23/log/test.log +0 -1
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite3/1.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite3/2.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Argentina.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Australia.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Austria.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Belgium.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Brazil.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Cameroon.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Canada.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Chile.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/China.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Denmark.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Finland.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/France.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Germany.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Greece.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Hong Kong.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Hungary.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Iceland.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/India.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Indonesia.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Ireland.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Israel.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Italy.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Japan.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Malaysia.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Mexico.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/New Zealand.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Norway.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Pakistan.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Palestine.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Peru.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Poland.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Portugal.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Puerto Rico.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Romania.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Russia.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Saudi Arabia.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Singapore.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/South Africa.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/South Korea.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Spain.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Sweden.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Switzerland.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Thailand.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/The Netherlands.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Turkey.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/UK.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/USA.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Ukraine.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Uruguay.png +0 -0
- data/test/fixtures/rails_root_23/public/images/sprite_images/sprite4/Venezuela.png +0 -0
- data/test/fixtures/rails_root_23/public/javascripts/bar/bas.js +0 -1
- data/test/fixtures/rails_root_23/public/javascripts/bas/bar.js +0 -1
- data/test/fixtures/rails_root_23/public/stylesheets/bar/bas.css +0 -1
- data/test/fixtures/rails_root_23/public/stylesheets/bas/bar.css +0 -1
data/README.md
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
Active Assets
|
2
2
|
=============
|
3
3
|
|
4
|
-
A
|
4
|
+
A Railtie that provides an asset management system for css, javascript, and sprites in your Rails applications and engines. ActiveAssets includes two libraries, ActiveExpansions and ActiveSprites. ActiveSprites generates sprites defined by a dsl similar to a route definition. Similarly, ActiveExpansions' dsl creates `ActionView::Helpers::AssetTagHelper` javascript and stylesheet expansions, and adds additional features:
|
5
5
|
|
6
6
|
* Concatenation of included assets for expansions at boot or deploy time.
|
7
7
|
* Support for environment specific assets, so that, say, you can use one file for development and another for production or one file for development and then a cdn resource for production.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem install active_assets -v 0.3.0
|
13
|
-
|
14
|
-
Using Bundler?
|
15
|
-
--------------
|
16
|
-
### Gemfile
|
9
|
+
Gemfile
|
10
|
+
-------
|
17
11
|
|
18
12
|
...
|
19
|
-
gem 'active_assets'
|
13
|
+
gem 'active_assets'
|
20
14
|
...
|
21
15
|
group :development do
|
22
16
|
...
|
@@ -32,14 +26,28 @@ Using Bundler?
|
|
32
26
|
|
33
27
|
The above order of image libraries is also the load order precedence.
|
34
28
|
|
35
|
-
|
29
|
+
In your Rails app
|
36
30
|
-----------------
|
31
|
+
### application.rb
|
32
|
+
|
33
|
+
...
|
34
|
+
require 'rails/all'
|
35
|
+
require 'active_assets/railtie'
|
36
|
+
...
|
37
|
+
|
38
|
+
#### You can also include only ActiveSprites or only ActiveExpansions in your application
|
39
|
+
### application.rb
|
40
|
+
Instead of the above,
|
37
41
|
|
38
|
-
|
42
|
+
...
|
43
|
+
require 'rails/all'
|
44
|
+
require 'active_assets/active_expansions/railtie'
|
45
|
+
... OR ...
|
46
|
+
require 'active_assets/active_sprites/railtie'
|
47
|
+
...
|
39
48
|
|
40
|
-
The DSLs
|
41
|
-
|
42
|
-
## Introduction to Active Sprites
|
49
|
+
## The DSLs
|
50
|
+
### Introduction to Active Sprites
|
43
51
|
|
44
52
|
ActiveSprites allows you to generate sprites within your Rails apps with `rake sprites`! All you need is `rmagick`, `chunky_png`, or `mini_magick` and you are on your way. Store the images that make up your sprites within your Rails project, use the dsl below to inform ActiveSprites of which images to include in your sprites as well as the css selector corresponding to each image, the location to write the sprite, and the location to write the stylesheet.
|
45
53
|
|
@@ -89,9 +97,9 @@ Rmagick is used by default and is by far the fastest. You can use one of two me
|
|
89
97
|
...
|
90
98
|
|
91
99
|
|
92
|
-
|
100
|
+
### Introduction to Active Expansions
|
93
101
|
|
94
|
-
ActiveExpansions allow you to register Rails javascript and stylesheet expansions via a simple dsl.
|
102
|
+
ActiveExpansions allow you to register Rails javascript and stylesheet expansions via a simple dsl. Addionally, the assets in the expansion are concatenated when appropriate and the expansion delivers the concatenated (or 'cached') assets' path in the appropriate environments. Also, files can be specified as deploy only or only for a specific environment. For example, you may wish to include jQuery or Prototype src files in development and use minified libraries from cdn sources in production. This is supported.
|
95
103
|
|
96
104
|
* Below demonstration shows several variations on how to declare expansions. Note that these declaration are redundant to demonstrate how to accomplish the same thing in different ways.
|
97
105
|
* Alternatively you can also register your assets in multiple files. Simply omit `config/asets.rb` and add as many .rb files as you like inside a directory `config/assets`
|
@@ -181,12 +189,16 @@ You can specify certain assets only be used in a deployment setting or only be u
|
|
181
189
|
|
182
190
|
`_` and `a` are aliases for `asset`
|
183
191
|
|
184
|
-
#### ActiveExpansions
|
185
|
-
By default, ActiveExpansions will not cache your assets
|
192
|
+
#### ActiveExpansions configuration and deployment
|
193
|
+
By default, ActiveExpansions will not cache your assets even if `ActionController.perform_caching` is enabled. This is because if you are not serving assets from the same server as where your application resides, then you most likely want to cache your assets at deploy time (on the front-end servers). To cache assets manually,
|
186
194
|
|
187
195
|
Rails.application.expansions.javascripts.cache!
|
188
196
|
Rails.application.expansions.stylesheets.cache!
|
189
197
|
|
190
|
-
|
191
|
-
|
192
|
-
|
198
|
+
To enable your application to cache assets when the application is initialized, i.e. boot time, follow this example,
|
199
|
+
|
200
|
+
##### config/environments/production.rb
|
201
|
+
|
202
|
+
...
|
203
|
+
config.active_expansions.precache_assets = true
|
204
|
+
...
|
data/Rakefile
CHANGED
data/active_assets.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "active_assets"
|
4
|
-
s.version = '0.
|
4
|
+
s.version = '1.0.0.rc1'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ["Sam Woodard"]
|
7
7
|
s.email = ["sam@wildfireapp.com"]
|
@@ -16,15 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_runtime_dependency "activesupport", "~>2.3.5"
|
20
|
-
|
21
|
-
s.add_development_dependency 'rails', "~>2.3.5"
|
22
|
-
s.add_development_dependency 'rake'
|
23
19
|
s.add_development_dependency 'oily_png'
|
24
20
|
s.add_development_dependency 'chunky_png'
|
25
21
|
s.add_development_dependency 'rmagick'
|
26
22
|
s.add_development_dependency 'mini_magick'
|
27
23
|
s.add_development_dependency 'css_parser', '~>1.1.5'
|
24
|
+
s.add_development_dependency "rails", "~>3.0.3"
|
28
25
|
s.add_development_dependency "test-unit", "> 2.0"
|
29
26
|
s.add_development_dependency "ZenTest", "~>4.4.2"
|
30
27
|
end
|
data/lib/active_assets.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
|
3
3
|
module ActiveAssets
|
4
|
-
|
5
|
-
autoload :ActiveSprites, 'active_assets/active_sprites'
|
4
|
+
extend ActiveSupport::Autoload
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
rv ||= RAILS_GEM_VERSION rescue nil
|
10
|
-
rv ||= Gem.loaded_specs.find { |n,spec| n == 'rails' }[1].version.to_s
|
11
|
-
|
12
|
-
Gem::Version.new(rv) < Gem::Version.new('3.0.0.beta')
|
13
|
-
end
|
6
|
+
autoload :ActiveExpansions
|
7
|
+
autoload :ActiveSprites
|
14
8
|
end
|
15
|
-
|
16
|
-
require 'active_assets/rails2_support' if ActiveAssets.rails2?
|
@@ -2,23 +2,16 @@ require 'active_support'
|
|
2
2
|
|
3
3
|
module ActiveAssets
|
4
4
|
module ActiveExpansions
|
5
|
-
|
6
|
-
autoload :AssetScope, 'active_assets/active_expansions/asset_scope'
|
7
|
-
autoload :TypeInferrable, 'active_assets/active_expansions/type_inferrable'
|
8
|
-
autoload :Configurable, 'active_assets/active_expansions/configurable'
|
9
|
-
autoload :Expansion, 'active_assets/active_expansions/expansion'
|
10
|
-
autoload :Assets, 'active_assets/active_expansions/assets'
|
11
|
-
autoload :Javascripts, 'active_assets/active_expansions/javascripts'
|
12
|
-
autoload :Stylesheets, 'active_assets/active_expansions/stylesheets'
|
13
|
-
autoload :Expansions, 'active_assets/active_expansions/expansions'
|
5
|
+
extend ActiveSupport::Autoload
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
autoload :Asset
|
8
|
+
autoload :AssetScope
|
9
|
+
autoload :TypeInferrable
|
10
|
+
autoload :Configurable
|
11
|
+
autoload :Expansion
|
12
|
+
autoload :Assets
|
13
|
+
autoload :Javascripts
|
14
|
+
autoload :Stylesheets
|
15
|
+
autoload :Expansions
|
23
16
|
end
|
24
17
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ActiveAssets
|
4
|
+
module ActiveExpansions
|
5
|
+
module Configurable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
config_accessor :precache_assets
|
10
|
+
self.precache_assets = false if precache_assets.nil?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
1
3
|
module ActiveAssets
|
2
4
|
module ActiveExpansions
|
3
5
|
class Expansions
|
4
6
|
include AssetScope
|
5
7
|
include TypeInferrable
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ActiveSupport.run_load_hooks(:active_expansions, self) if ActiveSupport.respond_to?(:run_load_hooks)
|
8
|
+
include ActiveSupport::Configurable
|
9
|
+
include Configurable
|
10
|
+
ActiveSupport.run_load_hooks(:active_expansions, self)
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@expansions = Hash.new(&method(:build_expansions_hash_with_defaults))
|
@@ -71,14 +71,6 @@ module ActiveAssets
|
|
71
71
|
@expansions.clear
|
72
72
|
end
|
73
73
|
|
74
|
-
def precache_assets
|
75
|
-
@@precache_assets
|
76
|
-
end
|
77
|
-
|
78
|
-
def precache_assets=(val)
|
79
|
-
@@precache_assets = val
|
80
|
-
end
|
81
|
-
|
82
74
|
private
|
83
75
|
def defer_expansion(name, options, &blk)
|
84
76
|
@deferred_expansion_config = [name, options]
|
@@ -6,7 +6,7 @@ module ActiveAssets
|
|
6
6
|
module ActiveExpansions
|
7
7
|
class Railtie < Rails::Railtie
|
8
8
|
rake_tasks do
|
9
|
-
|
9
|
+
Dir[File.expand_path("../../../tasks/active_expansions/*.rake", __FILE__)].each {|f| load f}
|
10
10
|
end
|
11
11
|
|
12
12
|
config.active_expansions = ActiveSupport::OrderedOptions.new
|
@@ -2,21 +2,38 @@ require 'active_support'
|
|
2
2
|
|
3
3
|
module ActiveAssets
|
4
4
|
module ActiveSprites
|
5
|
-
|
6
|
-
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :SpritePiece
|
8
|
+
autoload :Sprite
|
9
|
+
autoload :Sprites
|
10
|
+
autoload :Configurable
|
11
|
+
autoload :SpriteStylesheet
|
12
|
+
autoload_under "runners" do
|
13
|
+
autoload :AbstractRunner
|
14
|
+
autoload :RmagickRunner
|
15
|
+
autoload :MiniMagickRunner
|
16
|
+
autoload :ChunkyPngRunner
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load_engine_tasks(engine_class)
|
20
|
+
desc "Generate sprites"
|
21
|
+
task :sprites do
|
22
|
+
require 'rails'
|
23
|
+
require 'rails/active_sprites'
|
24
|
+
|
18
25
|
ENV['VERBOSE'] ||= 'true'
|
19
|
-
|
26
|
+
|
27
|
+
Rails.application ||= Class.new(Rails::Application)
|
28
|
+
Rails.application.extend Rails::ActiveSprites
|
29
|
+
|
30
|
+
engine = engine_class.new
|
31
|
+
sprite_path = File.join(engine.config.paths.config.paths.first, 'sprites.rb')
|
32
|
+
|
33
|
+
if File.exists?(sprite_path)
|
34
|
+
load sprite_path
|
35
|
+
Rails.application.sprites.generate!(engine)
|
36
|
+
end
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
@@ -9,7 +9,7 @@ module ActiveAssets
|
|
9
9
|
config.active_sprites = ActiveSupport::OrderedOptions.new
|
10
10
|
|
11
11
|
rake_tasks do
|
12
|
-
|
12
|
+
Dir[File.expand_path("../../../tasks/active_sprites/*.rake", __FILE__)].each {|f| load f}
|
13
13
|
end
|
14
14
|
|
15
15
|
initializer 'active_sprites-extend-application' do
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'action_controller'
|
2
2
|
require 'action_view'
|
3
|
+
require 'rack/mount'
|
3
4
|
require 'action_view'
|
4
5
|
require 'fileutils'
|
5
6
|
|
@@ -9,14 +10,15 @@ module ActiveAssets
|
|
9
10
|
class AssetContext < ActionView::Base
|
10
11
|
end
|
11
12
|
|
12
|
-
def initialize(sprites)
|
13
|
+
def initialize(railtie, sprites)
|
14
|
+
@railtie = railtie
|
13
15
|
@sprites = if ENV['SPRITE']
|
14
16
|
sprites.select do |name, sprite|
|
15
17
|
ENV['SPRITE'].split(',').map(&:strip).any? do |sp|
|
16
18
|
# were going to be very forgiving
|
17
19
|
name == sp ||
|
18
20
|
name == sp.to_sym ||
|
19
|
-
name ==
|
21
|
+
name == ::Rack::Mount::Utils.normalize_path(sp)
|
20
22
|
end
|
21
23
|
end.map(&:last)
|
22
24
|
else
|
@@ -59,7 +61,7 @@ module ActiveAssets
|
|
59
61
|
end
|
60
62
|
|
61
63
|
stylesheet = SpriteStylesheet.new(sprite_pieces)
|
62
|
-
stylesheet_file_path = File.join(
|
64
|
+
stylesheet_file_path = File.join(@railtie.config.paths.public.to_a.first, sprite_stylesheet_path)
|
63
65
|
$stdout << "Writing stylesheet to #{stylesheet_file_path} ... " if verbose
|
64
66
|
stylesheet.write stylesheet_file_path
|
65
67
|
$stdout << "done.\n" if verbose
|
@@ -68,7 +70,7 @@ module ActiveAssets
|
|
68
70
|
create_sprite(sprite, sprite_path, sprite_pieces, image_list, width, height, orientation, verbose)
|
69
71
|
$stdout << "Success!\n" if verbose
|
70
72
|
|
71
|
-
sprite_file_path = File.join(
|
73
|
+
sprite_file_path = File.join(@railtie.config.paths.public.to_a.first, sprite_path)
|
72
74
|
$stdout << "Writing sprite to #{sprite_file_path} ... " if verbose
|
73
75
|
write sprite_file_path, sprite.quality
|
74
76
|
$stdout << "done.\n" if verbose
|
@@ -89,11 +91,13 @@ module ActiveAssets
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def image_computed_full_path(path)
|
92
|
-
File.join(
|
94
|
+
File.join(@railtie.config.paths.public.to_a.first, image_computed_path(path))
|
93
95
|
end
|
94
96
|
|
95
97
|
def stylesheet_computed_path(path)
|
96
|
-
|
98
|
+
stylesheet_full_path = @railtie.config.respond_to?(:action_controller) && @railtie.config.paths.public.stylesheets.to_a.first
|
99
|
+
stylesheet_path = stylesheet_full_path ? stylesheet_full_path[%r{public/(.*)}, 1] : 'stylesheets'
|
100
|
+
File.join(stylesheet_path, path)
|
97
101
|
end
|
98
102
|
|
99
103
|
def sanitize_asset_path(path)
|
@@ -101,25 +105,9 @@ module ActiveAssets
|
|
101
105
|
end
|
102
106
|
|
103
107
|
def sprite_url(sprite, sprite_path)
|
104
|
-
sprite.url.present? ? sprite.url : normalize_path(sprite_path)
|
108
|
+
sprite.url.present? ? sprite.url : ::Rack::Mount::Utils.normalize_path(sprite_path)
|
105
109
|
end
|
106
110
|
|
107
|
-
# Rack::Mount::Utils#normalize_path from rack-mount 0.6.13
|
108
|
-
# Normalizes URI path.
|
109
|
-
#
|
110
|
-
# Strips off trailing slash and ensures there is a leading slash.
|
111
|
-
#
|
112
|
-
# normalize_path("/foo") # => "/foo"
|
113
|
-
# normalize_path("/foo/") # => "/foo"
|
114
|
-
# normalize_path("foo") # => "/foo"
|
115
|
-
# normalize_path("") # => "/"
|
116
|
-
def normalize_path(path)
|
117
|
-
path = "/#{path}"
|
118
|
-
path.squeeze!('/')
|
119
|
-
path.sub!(%r{/+\Z}, '')
|
120
|
-
path = '/' if path == ''
|
121
|
-
path
|
122
|
-
end
|
123
111
|
end
|
124
112
|
end
|
125
113
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
1
3
|
module ActiveAssets
|
2
4
|
module ActiveSprites
|
3
5
|
class Sprites
|
4
|
-
|
6
|
+
include ActiveSupport::Configurable
|
7
|
+
include Configurable
|
8
|
+
ActiveSupport.run_load_hooks(:active_sprites, self)
|
5
9
|
|
6
10
|
def initialize
|
7
11
|
@sprites = Hash.new do |sprites, name|
|
@@ -45,39 +49,39 @@ module ActiveAssets
|
|
45
49
|
@sprites.clear
|
46
50
|
end
|
47
51
|
|
48
|
-
def generate!
|
52
|
+
def generate!(railtie = Rails.application)
|
49
53
|
begin
|
50
54
|
case sprite_backend
|
51
55
|
when :rmagick
|
52
56
|
require 'rmagick'
|
53
|
-
RmagickRunner.new(@sprites).generate!
|
57
|
+
RmagickRunner.new(railtie, @sprites).generate!
|
54
58
|
when :mini_magick
|
55
59
|
require 'mini_magick'
|
56
|
-
MiniMagickRunner.new(@sprites).generate!
|
60
|
+
MiniMagickRunner.new(railtie, @sprites).generate!
|
57
61
|
when :chunky_png, :oily_png
|
58
62
|
begin
|
59
63
|
require 'oily_png'
|
60
|
-
ChunkyPngRunner.new(@sprites).generate!
|
64
|
+
ChunkyPngRunner.new(railtie, @sprites).generate!
|
61
65
|
rescue LoadError
|
62
66
|
require 'chunky_png'
|
63
|
-
ChunkyPngRunner.new(@sprites).generate!
|
67
|
+
ChunkyPngRunner.new(railtie, @sprites).generate!
|
64
68
|
end
|
65
69
|
else
|
66
70
|
begin
|
67
71
|
require 'rmagick'
|
68
|
-
RmagickRunner.new(@sprites).generate!
|
72
|
+
RmagickRunner.new(railtie, @sprites).generate!
|
69
73
|
rescue LoadError
|
70
74
|
begin
|
71
75
|
begin
|
72
76
|
require 'oily_png'
|
73
|
-
ChunkyPngRunner.new(@sprites).generate!
|
77
|
+
ChunkyPngRunner.new(railtie, @sprites).generate!
|
74
78
|
rescue LoadError
|
75
79
|
require 'chunky_png'
|
76
|
-
ChunkyPngRunner.new(@sprites).generate!
|
80
|
+
ChunkyPngRunner.new(railtie, @sprites).generate!
|
77
81
|
end
|
78
82
|
rescue LoadError
|
79
83
|
require 'mini_magick'
|
80
|
-
MiniMagickRunner.new(@sprites).generate!
|
84
|
+
MiniMagickRunner.new(railtie, @sprites).generate!
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -89,16 +93,6 @@ module ActiveAssets
|
|
89
93
|
$stdout << msg
|
90
94
|
end
|
91
95
|
end
|
92
|
-
|
93
|
-
def sprite_backend
|
94
|
-
@@sprite_backend
|
95
|
-
end
|
96
|
-
|
97
|
-
def sprite_backend=(val)
|
98
|
-
@@sprite_backend = val
|
99
|
-
end
|
100
|
-
|
101
|
-
ActiveSupport.run_load_hooks(:active_sprites, self) if ActiveSupport.respond_to?(:run_load_hooks)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
end
|