active_assets 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/active_assets.gemspec +1 -1
- data/lib/active_assets/active_expansions.rb +33 -0
- data/lib/active_assets/active_expansions/assets.rb +5 -1
- data/lib/active_assets/active_expansions/configurable.rb +2 -1
- data/lib/active_assets/active_expansions/railtie.rb +11 -22
- data/lib/active_assets/active_expansions/reload.rb +14 -0
- data/test/fixtures/rails_root/app/controllers/application_controller.rb +7 -0
- data/test/fixtures/rails_root/config/application.rb +10 -1
- data/test/fixtures/rails_root/config/new.rb +5 -0
- data/test/fixtures/rails_root/config/routes.rb +3 -0
- data/test/fixtures/rails_root/test/functional/application_controller_test.rb +52 -0
- data/test/fixtures/rails_root/test/test_helper.rb +6 -0
- data/test/helper.rb +0 -2
- metadata +23 -12
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
Active Assets
|
2
2
|
=============
|
3
3
|
|
4
|
+
### Known issue with current versions of ChunkyPng and OliyPng
|
5
|
+
|
6
|
+
__In your Rails App's gemfile, if you are using ChunkyPng or ChunkyPng with OilyPng, lock down the version to ChunkyPng(0.12.0), OilyPng(0.3.0)__
|
7
|
+
|
4
8
|
If you are looking to use Active Assets with rails 2.3.x, click [here](https://github.com/shwoodard/active_assets/tree/0-3).
|
5
9
|
|
6
10
|
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:
|
data/Rakefile
CHANGED
data/active_assets.gemspec
CHANGED
@@ -13,5 +13,38 @@ module ActiveAssets
|
|
13
13
|
autoload :Javascripts
|
14
14
|
autoload :Stylesheets
|
15
15
|
autoload :Expansions
|
16
|
+
|
17
|
+
def self.load_active_expansions(root)
|
18
|
+
if File.exists?(File.join(root, 'config/assets.rb'))
|
19
|
+
load File.join(root, 'config/assets.rb')
|
20
|
+
elsif File.directory?(File.join(root, 'config/assets'))
|
21
|
+
Dir[File.join(root, 'config/assets/*.rb')].each do |f|
|
22
|
+
load f
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.load_expansions_and_register
|
28
|
+
ActiveExpansions.load_active_expansions(Rails.root)
|
29
|
+
Rails.application.railties.engines.each {|e| ActiveExpansions.load_active_expansions(e.root) }
|
30
|
+
Rails.application.expansions.javascripts.register!
|
31
|
+
Rails.application.expansions.stylesheets.register!
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.remove_active_expansions
|
35
|
+
Rails.application.expansions.javascripts.expansion_names.each do |expansion|
|
36
|
+
Rails.application.expansions.javascripts.remove(expansion)
|
37
|
+
if ActionView::Helpers::AssetTagHelper.javascript_expansions.has_key?(expansion)
|
38
|
+
ActionView::Helpers::AssetTagHelper.javascript_expansions.delete(expansion)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Rails.application.expansions.stylesheets.expansion_names.each do |expansion|
|
43
|
+
Rails.application.expansions.stylesheets.remove(expansion)
|
44
|
+
if ActionView::Helpers::AssetTagHelper.stylesheet_expansions.has_key?(expansion)
|
45
|
+
ActionView::Helpers::AssetTagHelper.stylesheet_expansions.delete(expansion)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
16
49
|
end
|
17
50
|
end
|
@@ -14,7 +14,7 @@ module ActiveAssets
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def expansion_names
|
17
|
-
@
|
17
|
+
@expansions.keys
|
18
18
|
end
|
19
19
|
|
20
20
|
def [](expansion_name)
|
@@ -30,6 +30,10 @@ module ActiveAssets
|
|
30
30
|
self[expansion_name].assets.map(&:path)
|
31
31
|
end
|
32
32
|
|
33
|
+
def remove(expansion_name)
|
34
|
+
@expansions.delete(expansion_name)
|
35
|
+
end
|
36
|
+
|
33
37
|
def asset_type
|
34
38
|
raise NoMethodError
|
35
39
|
end
|
@@ -6,8 +6,9 @@ module ActiveAssets
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
config_accessor :precache_assets
|
9
|
+
config_accessor :precache_assets, :reload_expansions
|
10
10
|
self.precache_assets = false if precache_assets.nil?
|
11
|
+
self.reload_expansions = false if reload_expansions.nil?
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "rails/active_expansions"
|
3
3
|
require 'active_support/ordered_options'
|
4
|
+
require 'active_assets/active_expansions/reload'
|
4
5
|
|
5
6
|
module ActiveAssets
|
6
7
|
module ActiveExpansions
|
@@ -15,16 +16,6 @@ module ActiveAssets
|
|
15
16
|
Rails.application.extend(Rails::ActiveExpansions)
|
16
17
|
end
|
17
18
|
|
18
|
-
initializer 'active_expansions-load-definitons' do
|
19
|
-
load_active_assets(Rails.root)
|
20
|
-
Rails.application.railties.engines.each {|e| load_active_assets(e.root) }
|
21
|
-
end
|
22
|
-
|
23
|
-
initializer 'active_expansions-register' do
|
24
|
-
Rails.application.expansions.javascripts.register!
|
25
|
-
Rails.application.expansions.stylesheets.register!
|
26
|
-
end
|
27
|
-
|
28
19
|
initializer 'active_expansions-set-configs' do
|
29
20
|
options = config.active_expansions
|
30
21
|
ActiveSupport.on_load(:active_expansions) do
|
@@ -32,22 +23,20 @@ module ActiveAssets
|
|
32
23
|
end
|
33
24
|
end
|
34
25
|
|
35
|
-
initializer 'active_expansions-
|
36
|
-
|
37
|
-
|
26
|
+
initializer 'active_expansions-load-definitions-and-register' do
|
27
|
+
ActiveExpansions.load_expansions_and_register
|
28
|
+
|
29
|
+
if ActiveAssets::ActiveExpansions::Expansions.reload_expansions
|
30
|
+
ActionController::Base.extend(Reload)
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
elsif File.directory?(File.join(root, 'config/assets'))
|
46
|
-
Dir[File.join(root, 'config/assets/*.rb')].each do |f|
|
47
|
-
load f
|
48
|
-
end
|
49
|
-
end
|
34
|
+
initializer 'active_expansions-cache' do
|
35
|
+
if Expansions.precache_assets
|
36
|
+
Rails.application.expansions.javascripts.cache!
|
37
|
+
Rails.application.expansions.stylesheets.cache!
|
50
38
|
end
|
39
|
+
end
|
51
40
|
end
|
52
41
|
end
|
53
42
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveAssets
|
2
|
+
module ActiveExpansions
|
3
|
+
module Reload
|
4
|
+
|
5
|
+
def self.extended(controller)
|
6
|
+
controller.before_filter do
|
7
|
+
ActiveAssets::ActiveExpansions.remove_active_expansions
|
8
|
+
ActiveAssets::ActiveExpansions.load_expansions_and_register
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,18 @@
|
|
1
|
-
|
1
|
+
# Pick the frameworks you want:
|
2
|
+
# require 'rails/all'
|
3
|
+
# require "active_record/railtie"
|
4
|
+
require "action_controller/railtie"
|
5
|
+
# require "action_mailer/railtie"
|
6
|
+
# require "active_resource/railtie"
|
7
|
+
# require "active_model/railtie"
|
8
|
+
require "rails/test_unit/railtie"
|
2
9
|
require 'active_assets/railtie'
|
3
10
|
|
4
11
|
module ActiveAssetsTest
|
5
12
|
class Application < Rails::Application
|
6
13
|
config.root = File.expand_path('../..', __FILE__)
|
14
|
+
config.cache_classes = false
|
15
|
+
# config.active_expansions.reload_expansions = true
|
7
16
|
end
|
8
17
|
end
|
9
18
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class ApplicationControllerTest < ActionController::TestCase
|
5
|
+
include FileUtils
|
6
|
+
|
7
|
+
def new_assets
|
8
|
+
File.expand_path('../../../config/assets/new.rb', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_new_assets
|
12
|
+
File.open(new_assets, 'w+') do |io|
|
13
|
+
io.puts <<-EOF
|
14
|
+
Rails.application.expansions do
|
15
|
+
expansion :new do
|
16
|
+
_'foo.js'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
EOF
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
rm_rf new_assets
|
25
|
+
ActionView::Helpers::AssetTagHelper.javascript_expansions.delete(:new)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_index
|
29
|
+
get :index
|
30
|
+
assert response.success?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_expansions
|
34
|
+
assert ActionView::Helpers::AssetTagHelper.javascript_expansions.any? {|k, v| k == :basfoo}
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_can_add_expansion
|
38
|
+
assert !ActionView::Helpers::AssetTagHelper.javascript_expansions.any? {|k, v| k == :new}
|
39
|
+
get :index
|
40
|
+
write_new_assets
|
41
|
+
get :index
|
42
|
+
assert ActionView::Helpers::AssetTagHelper.javascript_expansions.any? {|k, v| k == :new}
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_can_remove_expansion
|
46
|
+
test_can_add_expansion
|
47
|
+
rm_rf new_assets
|
48
|
+
get :index
|
49
|
+
|
50
|
+
assert !ActionView::Helpers::AssetTagHelper.javascript_expansions.any? {|k, v| k == :new}
|
51
|
+
end
|
52
|
+
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Woodard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -28,10 +28,10 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
|
-
name: oily_png
|
32
31
|
prerelease: false
|
33
32
|
type: :development
|
34
33
|
requirement: *id001
|
34
|
+
name: oily_png
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
@@ -42,10 +42,10 @@ dependencies:
|
|
42
42
|
segments:
|
43
43
|
- 0
|
44
44
|
version: "0"
|
45
|
-
name: chunky_png
|
46
45
|
prerelease: false
|
47
46
|
type: :development
|
48
47
|
requirement: *id002
|
48
|
+
name: chunky_png
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
segments:
|
57
57
|
- 0
|
58
58
|
version: "0"
|
59
|
-
name: rmagick
|
60
59
|
prerelease: false
|
61
60
|
type: :development
|
62
61
|
requirement: *id003
|
62
|
+
name: rmagick
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
@@ -70,10 +70,10 @@ dependencies:
|
|
70
70
|
segments:
|
71
71
|
- 0
|
72
72
|
version: "0"
|
73
|
-
name: mini_magick
|
74
73
|
prerelease: false
|
75
74
|
type: :development
|
76
75
|
requirement: *id004
|
76
|
+
name: mini_magick
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
@@ -86,10 +86,10 @@ dependencies:
|
|
86
86
|
- 1
|
87
87
|
- 5
|
88
88
|
version: 1.1.5
|
89
|
-
name: css_parser
|
90
89
|
prerelease: false
|
91
90
|
type: :development
|
92
91
|
requirement: *id005
|
92
|
+
name: css_parser
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
@@ -102,10 +102,10 @@ dependencies:
|
|
102
102
|
- 0
|
103
103
|
- 3
|
104
104
|
version: 3.0.3
|
105
|
-
name: rails
|
106
105
|
prerelease: false
|
107
106
|
type: :development
|
108
107
|
requirement: *id006
|
108
|
+
name: rails
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
@@ -117,10 +117,10 @@ dependencies:
|
|
117
117
|
- 2
|
118
118
|
- 0
|
119
119
|
version: "2.0"
|
120
|
-
name: test-unit
|
121
120
|
prerelease: false
|
122
121
|
type: :development
|
123
122
|
requirement: *id007
|
123
|
+
name: test-unit
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
@@ -133,10 +133,10 @@ dependencies:
|
|
133
133
|
- 4
|
134
134
|
- 2
|
135
135
|
version: 4.4.2
|
136
|
-
name: ZenTest
|
137
136
|
prerelease: false
|
138
137
|
type: :development
|
139
138
|
requirement: *id008
|
139
|
+
name: ZenTest
|
140
140
|
description: 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
|
141
141
|
email:
|
142
142
|
- sam@wildfireapp.com
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/active_assets/active_expansions/expansions.rb
|
165
165
|
- lib/active_assets/active_expansions/javascripts.rb
|
166
166
|
- lib/active_assets/active_expansions/railtie.rb
|
167
|
+
- lib/active_assets/active_expansions/reload.rb
|
167
168
|
- lib/active_assets/active_expansions/stylesheets.rb
|
168
169
|
- lib/active_assets/active_expansions/type_inferrable.rb
|
169
170
|
- lib/active_assets/active_sprites.rb
|
@@ -193,9 +194,12 @@ files:
|
|
193
194
|
- test/active_assets/active_sprites/sprite_test.rb
|
194
195
|
- test/active_assets/active_sprites/sprites_test.rb
|
195
196
|
- test/autocolor.rb
|
197
|
+
- test/fixtures/rails_root/app/controllers/application_controller.rb
|
196
198
|
- test/fixtures/rails_root/config/application.rb
|
197
199
|
- test/fixtures/rails_root/config/assets/assets.rb
|
198
200
|
- test/fixtures/rails_root/config/environment.rb
|
201
|
+
- test/fixtures/rails_root/config/new.rb
|
202
|
+
- test/fixtures/rails_root/config/routes.rb
|
199
203
|
- test/fixtures/rails_root/config/sprites.rb
|
200
204
|
- test/fixtures/rails_root/public/images/sprite_images/sprite3/1.png
|
201
205
|
- test/fixtures/rails_root/public/images/sprite_images/sprite3/2.png
|
@@ -253,6 +257,8 @@ files:
|
|
253
257
|
- test/fixtures/rails_root/public/javascripts/bas/bar.js
|
254
258
|
- test/fixtures/rails_root/public/stylesheets/bar/bas.css
|
255
259
|
- test/fixtures/rails_root/public/stylesheets/bas/bar.css
|
260
|
+
- test/fixtures/rails_root/test/functional/application_controller_test.rb
|
261
|
+
- test/fixtures/rails_root/test/test_helper.rb
|
256
262
|
- test/helper.rb
|
257
263
|
- test/support/abstract_runner.rb
|
258
264
|
- test/support/rails_helper.rb
|
@@ -300,9 +306,12 @@ test_files:
|
|
300
306
|
- test/active_assets/active_sprites/sprite_test.rb
|
301
307
|
- test/active_assets/active_sprites/sprites_test.rb
|
302
308
|
- test/autocolor.rb
|
309
|
+
- test/fixtures/rails_root/app/controllers/application_controller.rb
|
303
310
|
- test/fixtures/rails_root/config/application.rb
|
304
311
|
- test/fixtures/rails_root/config/assets/assets.rb
|
305
312
|
- test/fixtures/rails_root/config/environment.rb
|
313
|
+
- test/fixtures/rails_root/config/new.rb
|
314
|
+
- test/fixtures/rails_root/config/routes.rb
|
306
315
|
- test/fixtures/rails_root/config/sprites.rb
|
307
316
|
- test/fixtures/rails_root/public/images/sprite_images/sprite3/1.png
|
308
317
|
- test/fixtures/rails_root/public/images/sprite_images/sprite3/2.png
|
@@ -360,6 +369,8 @@ test_files:
|
|
360
369
|
- test/fixtures/rails_root/public/javascripts/bas/bar.js
|
361
370
|
- test/fixtures/rails_root/public/stylesheets/bar/bas.css
|
362
371
|
- test/fixtures/rails_root/public/stylesheets/bas/bar.css
|
372
|
+
- test/fixtures/rails_root/test/functional/application_controller_test.rb
|
373
|
+
- test/fixtures/rails_root/test/test_helper.rb
|
363
374
|
- test/helper.rb
|
364
375
|
- test/support/abstract_runner.rb
|
365
376
|
- test/support/rails_helper.rb
|