dynamic_assets 0.1.0

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.
Files changed (38) hide show
  1. data/README.rdoc +225 -0
  2. data/app/controllers/assets_controller.rb +4 -0
  3. data/app/helpers/dynamic_assets_helpers.rb +63 -0
  4. data/config/routes.rb +12 -0
  5. data/lib/dynamic_assets/config.rb +109 -0
  6. data/lib/dynamic_assets/controller.rb +40 -0
  7. data/lib/dynamic_assets/core_extensions.rb +29 -0
  8. data/lib/dynamic_assets/engine.rb +11 -0
  9. data/lib/dynamic_assets/manager.rb +10 -0
  10. data/lib/dynamic_assets/reference/javascript_reference.rb +19 -0
  11. data/lib/dynamic_assets/reference/stylesheet_reference.rb +84 -0
  12. data/lib/dynamic_assets/reference.rb +118 -0
  13. data/lib/dynamic_assets.rb +12 -0
  14. data/spec/dummy_rails_app/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy_rails_app/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy_rails_app/config/application.rb +42 -0
  17. data/spec/dummy_rails_app/config/boot.rb +6 -0
  18. data/spec/dummy_rails_app/config/environment.rb +5 -0
  19. data/spec/dummy_rails_app/config/environments/development.rb +26 -0
  20. data/spec/dummy_rails_app/config/environments/production.rb +49 -0
  21. data/spec/dummy_rails_app/config/environments/test.rb +35 -0
  22. data/spec/dummy_rails_app/config/initializers/backtrace_silencers.rb +7 -0
  23. data/spec/dummy_rails_app/config/initializers/inflections.rb +10 -0
  24. data/spec/dummy_rails_app/config/initializers/mime_types.rb +5 -0
  25. data/spec/dummy_rails_app/config/initializers/secret_token.rb +7 -0
  26. data/spec/dummy_rails_app/config/initializers/session_store.rb +8 -0
  27. data/spec/dummy_rails_app/config/routes.rb +58 -0
  28. data/spec/dummy_rails_app/db/seeds.rb +7 -0
  29. data/spec/dummy_rails_app/spec/spec_helper.rb +27 -0
  30. data/spec/dummy_rails_app/test/performance/browsing_test.rb +9 -0
  31. data/spec/dummy_rails_app/test/test_helper.rb +13 -0
  32. data/spec/helpers/dynamic_assets_helpers_spec.rb +69 -0
  33. data/spec/lib/dynamic_assets/config_spec.rb +148 -0
  34. data/spec/lib/dynamic_assets/manager_spec.rb +9 -0
  35. data/spec/lib/dynamic_assets/stylesheet_reference_spec.rb +58 -0
  36. data/spec/spec_helper.rb +26 -0
  37. data/spec/support/matchers/string_matchers.rb +61 -0
  38. metadata +219 -0
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicAssets::Config do
4
+ subject { Object.new.extend(DynamicAssets::Config).tap { |m| m.init yml_path } }
5
+ let(:yml_path) { "/yml/path" }
6
+
7
+
8
+ context "when the yml file does not exist" do
9
+ before { File.stub(:exists?).with(yml_path).and_return false }
10
+
11
+ it "#asset_references_for_group_key works but returns nil" do
12
+ subject.asset_references_for_group_key(:stylesheets, :base).should be_nil
13
+ end
14
+
15
+ it "#asset_reference_for_name works but returns nil" do
16
+ subject.asset_reference_for_name(:stylesheets, "sheet1").should be_nil
17
+ end
18
+ end
19
+
20
+
21
+ context "when the yml file exists" do
22
+ let(:yml) { {} }
23
+ before do
24
+ File.stub(:exists?).with(yml_path).and_return true
25
+ YAML.stub(:load_file).with(yml_path).and_return yml
26
+ end
27
+
28
+ context "and contains no config vars" do
29
+ its(:combine_asset_groups?) { should be_true }
30
+ its(:minify?) { should be_true }
31
+ its(:cache?) { should be_true }
32
+
33
+ context "and contains one group of two stylesheets" do
34
+ before { yml["stylesheets"] = [{ "base" => ["sheet1", "sheet2"] }] }
35
+
36
+ it "instantiates one StylesheetReference" do
37
+ DynamicAssets::StylesheetReference.should_receive(:new).once.and_return "a Style Ref"
38
+ subject
39
+ end
40
+
41
+ it "#asset_references_for_group_key returns one stylesheet reference for the group" do
42
+ subject.asset_references_for_group_key(:stylesheets, :base).length.should == 1
43
+ end
44
+
45
+ it "#asset_reference_for_name returns one stylesheet reference for the grouped sheet" do
46
+ subject.asset_reference_for_name(:stylesheets, "base").should_not be_nil
47
+ end
48
+
49
+ it "#asset_reference_for_name returns no stylesheet reference for an individual sheet" do
50
+ subject.asset_reference_for_name(:stylesheets, "sheet1").should be_nil
51
+ end
52
+
53
+ context "and contains one group of three javascripts" do
54
+ before { yml["javascripts"] = [{ "base" => ["script1", "script2", "script3"] }] }
55
+
56
+ it "instantiates one JavascriptReference" do
57
+ DynamicAssets::JavascriptReference.should_receive(:new).once.and_return "a JavaScript Ref"
58
+ subject
59
+ end
60
+
61
+ it "#asset_references_for_group_key returns one javascript reference for the group" do
62
+ subject.asset_references_for_group_key(:javascripts, :base).length.should == 1
63
+ end
64
+
65
+ it "#asset_reference_for_name returns one javascript reference for the grouped script" do
66
+ subject.asset_reference_for_name(:javascripts, "base").should_not be_nil
67
+ end
68
+
69
+ it "#asset_reference_for_name returns no javascript reference for an individual script" do
70
+ subject.asset_reference_for_name(:javascripts, "script2").should be_nil
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ context "when the yml file contains config vars that set minify to false" do
79
+ let(:yml) { { "config" => { Rails.env => { "minify" => false } } } }
80
+
81
+ its(:combine_asset_groups?) { should be_true }
82
+ its(:minify?) { should be_false }
83
+ its(:cache?) { should be_true }
84
+ end
85
+
86
+ context "when the yml file contains config vars that set cache to false" do
87
+ let(:yml) { { "config" => { Rails.env => { "cache" => false } } } }
88
+
89
+ its(:combine_asset_groups?) { should be_true }
90
+ its(:minify?) { should be_true }
91
+ its(:cache?) { should be_false }
92
+ end
93
+
94
+ context "when the yml file contains config vars that set combine_asset_groups to false" do
95
+ let(:yml) { { "config" => { Rails.env => { "combine_asset_groups" => false } } } }
96
+
97
+ its(:combine_asset_groups?) { should be_false }
98
+ its(:minify?) { should be_true }
99
+ its(:cache?) { should be_true }
100
+
101
+ context "and contains one group of two stylesheets" do
102
+ before { yml["stylesheets"] = [{ "base" => ["sheet1", "sheet2"] }] }
103
+
104
+ it "instantiates two StylesheetReferences" do
105
+ DynamicAssets::StylesheetReference.should_receive(:new).twice.and_return "a Style Ref"
106
+ subject
107
+ end
108
+
109
+ it "#asset_references_for_group_key returns two stylesheet references for the group" do
110
+ subject.asset_references_for_group_key(:stylesheets, :base).length.should == 2
111
+ end
112
+
113
+ it "#asset_reference_for_name returns no stylesheet reference for the grouped sheet" do
114
+ subject.asset_reference_for_name(:stylesheets, "base").should be_nil
115
+ end
116
+
117
+ it "#asset_reference_for_name returns a stylesheet reference for an individual sheet" do
118
+ subject.asset_reference_for_name(:stylesheets, "sheet1").should_not be_nil
119
+ end
120
+
121
+ context "and contains one group of three javascripts" do
122
+ before { yml["javascripts"] = [{ "base" => ["script1", "script2", "script3"] }] }
123
+
124
+ it "instantiates three JavascriptReferences" do
125
+ DynamicAssets::JavascriptReference.should_receive(:new).exactly(3).times.
126
+ and_return "a JavaScript Ref"
127
+ subject
128
+ end
129
+
130
+ it "#asset_references_for_group_key returns three javascript references for the group" do
131
+ subject.asset_references_for_group_key(:javascripts, :base).length.should == 3
132
+ end
133
+
134
+ it "#asset_reference_for_name returns no javascript reference for the grouped script" do
135
+ subject.asset_reference_for_name(:javascripts, "base").should be_nil
136
+ end
137
+
138
+ it "#asset_reference_for_name returns a javascript reference for an individual script" do
139
+ subject.asset_reference_for_name(:javascripts, "script2").should_not be_nil
140
+ end
141
+ end
142
+
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe DynamicAssets::Manager do
4
+
5
+ it "contains config methods, like a singleton" do
6
+ expect { DynamicAssets::Manager.combine_asset_groups? }.not_to raise_error
7
+ end
8
+
9
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ module DynamicAssets
4
+ describe StylesheetReference do
5
+
6
+ describe "#content" do
7
+ subject { reference.content }
8
+ let(:reference) { StylesheetReference.new :name => "thing" }
9
+
10
+ context "when a css file with the given reference name exists" do
11
+ before do
12
+ reference.stub(:path_for_member_name).with("thing").and_return "/foo/thing.css"
13
+ reference.stub(:raw_content_exists?).and_return false
14
+ reference.stub(:raw_content_exists?).with("/foo/thing.css").and_return true
15
+ reference.stub(:get_raw_content).with("/foo/thing.css").and_return content
16
+ end
17
+
18
+ context "and the file is blank" do
19
+ let(:content) { "" }
20
+ it { should be_blank }
21
+ end
22
+
23
+ context "and the file contains URLs relative to the stylesheet" do
24
+ let(:content) { "body { background: url(background.gif); }" }
25
+
26
+ it "makes the URLs relative to RELATIVE_URL_ROOT and the member name" do
27
+ should contain_string "url(#{StylesheetReference::RELATIVE_URL_ROOT}/thing/background.gif)"
28
+ end
29
+ end
30
+
31
+ context "and the file contains URLs within directories relative to the stylesheet" do
32
+ let(:content) { "body { background: url(a/b/background.gif); }" }
33
+
34
+ it "makes the URLs relative to RELATIVE_URL_ROOT and the member name" do
35
+ should contain_string "url(#{StylesheetReference::RELATIVE_URL_ROOT}/thing/a/b/background.gif)"
36
+ end
37
+ end
38
+
39
+ context "and the file contains URLs with dots, relative to the stylesheet" do
40
+ let(:content) { "body { background: url(../a/b/background.gif); }" }
41
+
42
+ it "makes the URLs relative to RELATIVE_URL_ROOT and the member name, ignoring leading dots" do
43
+ should contain_string "url(#{StylesheetReference::RELATIVE_URL_ROOT}/thing/a/b/background.gif)"
44
+ end
45
+ end
46
+
47
+ context "and the file contains full URLs with hosts" do
48
+ let(:content) { "body { background: url(http://www.example.com/background.gif); }" }
49
+
50
+ it "leaves the URLs unchanged" do
51
+ should contain_string "url(http://www.example.com/background.gif)"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,26 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require 'dummy_rails_app/config/environment'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
8
+ require 'rspec/rails'
9
+
10
+ require "capybara/rails"
11
+ Capybara.default_driver = :rack_test
12
+ Capybara.default_selector = :css
13
+
14
+ require 'dynamic_assets'
15
+
16
+ # PENDING: not sure why these aren't auto-required
17
+ require 'app/helpers/dynamic_assets_helpers'
18
+ require 'config/routes'
19
+
20
+ # Requires supporting files with custom matchers and macros, etc,
21
+ # in ./support/ and its subdirectories.
22
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
23
+
24
+ RSpec.configure do |config|
25
+
26
+ end
@@ -0,0 +1,61 @@
1
+
2
+ #
3
+ # Makes sure a string contains a given substring. The difference between these two:
4
+ #
5
+ # my_string.should =~ /something/ # Using a regex
6
+ # my_string.should contain_string "something" # Using this matcher
7
+ #
8
+ # is that this matcher will escape the string for you, so you can search for .*?%^ASQ
9
+ # and not get weird results.
10
+ #
11
+ RSpec::Matchers.define :contain_string do |expected|
12
+
13
+ match do |actual|
14
+ raise "Expected value has an unexpected type. It's #{expected.class} but should be String." unless
15
+ expected.is_a?(String)
16
+ raise "Actual value has an unexpected type. It's #{actual.class} but should be String." unless
17
+ actual.is_a?(String)
18
+
19
+ actual =~ /#{Regexp.escape(expected)}/
20
+ end
21
+
22
+ failure_message_for_should do |actual|
23
+ "expected that \"#{actual}\" would contain \"#{expected}\""
24
+ end
25
+
26
+ failure_message_for_should_not do |actual|
27
+ "expected that \"#{actual}\" would not contain \"#{expected}\""
28
+ end
29
+
30
+ description do
31
+ "contain \"#{expected}\""
32
+ end
33
+
34
+ end
35
+
36
+
37
+ #
38
+ # Example: my_string.should start_with "ABCDE"
39
+ #
40
+ RSpec::Matchers.define :start_with do |expected|
41
+
42
+ match do |actual|
43
+ raise "Actual value has an unexpected type. It's #{actual.class} but should be String." unless
44
+ actual.is_a?(String)
45
+
46
+ actual =~ /^#{Regexp.escape("#{expected}")}/
47
+ end
48
+
49
+ failure_message_for_should do |actual|
50
+ "expected that \"#{actual}\" would start with \"#{expected}\""
51
+ end
52
+
53
+ failure_message_for_should_not do |actual|
54
+ "expected that \"#{actual}\" would not start with \"#{expected}\""
55
+ end
56
+
57
+ description do
58
+ "start with \"#{expected}\""
59
+ end
60
+
61
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynamic_assets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Robert Davis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-15 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ name: rails
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ version: "3.0"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ type: :development
39
+ name: bundler
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ prerelease: false
54
+ type: :development
55
+ name: jeweler
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 2
66
+ version: 1.5.2
67
+ requirement: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ prerelease: false
70
+ type: :development
71
+ name: capybara
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 111
78
+ segments:
79
+ - 0
80
+ - 4
81
+ - 1
82
+ - 2
83
+ version: 0.4.1.2
84
+ requirement: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ type: :development
88
+ name: rspec-rails
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ hash: 27
95
+ segments:
96
+ - 2
97
+ - 5
98
+ - 0
99
+ version: 2.5.0
100
+ requirement: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ prerelease: false
103
+ type: :development
104
+ name: sqlite3
105
+ version_requirements: &id006 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirement: *id006
115
+ description: Make your Rails 3 app process css and js assets on the fly with erb, sass, or scss
116
+ email: davis@coaster.com
117
+ executables: []
118
+
119
+ extensions: []
120
+
121
+ extra_rdoc_files:
122
+ - README.rdoc
123
+ files:
124
+ - app/controllers/assets_controller.rb
125
+ - app/helpers/dynamic_assets_helpers.rb
126
+ - config/routes.rb
127
+ - lib/dynamic_assets.rb
128
+ - lib/dynamic_assets/config.rb
129
+ - lib/dynamic_assets/controller.rb
130
+ - lib/dynamic_assets/core_extensions.rb
131
+ - lib/dynamic_assets/engine.rb
132
+ - lib/dynamic_assets/manager.rb
133
+ - lib/dynamic_assets/reference.rb
134
+ - lib/dynamic_assets/reference/javascript_reference.rb
135
+ - lib/dynamic_assets/reference/stylesheet_reference.rb
136
+ - README.rdoc
137
+ - spec/dummy_rails_app/app/controllers/application_controller.rb
138
+ - spec/dummy_rails_app/app/helpers/application_helper.rb
139
+ - spec/dummy_rails_app/config/application.rb
140
+ - spec/dummy_rails_app/config/boot.rb
141
+ - spec/dummy_rails_app/config/environment.rb
142
+ - spec/dummy_rails_app/config/environments/development.rb
143
+ - spec/dummy_rails_app/config/environments/production.rb
144
+ - spec/dummy_rails_app/config/environments/test.rb
145
+ - spec/dummy_rails_app/config/initializers/backtrace_silencers.rb
146
+ - spec/dummy_rails_app/config/initializers/inflections.rb
147
+ - spec/dummy_rails_app/config/initializers/mime_types.rb
148
+ - spec/dummy_rails_app/config/initializers/secret_token.rb
149
+ - spec/dummy_rails_app/config/initializers/session_store.rb
150
+ - spec/dummy_rails_app/config/routes.rb
151
+ - spec/dummy_rails_app/db/seeds.rb
152
+ - spec/dummy_rails_app/spec/spec_helper.rb
153
+ - spec/dummy_rails_app/test/performance/browsing_test.rb
154
+ - spec/dummy_rails_app/test/test_helper.rb
155
+ - spec/helpers/dynamic_assets_helpers_spec.rb
156
+ - spec/lib/dynamic_assets/config_spec.rb
157
+ - spec/lib/dynamic_assets/manager_spec.rb
158
+ - spec/lib/dynamic_assets/stylesheet_reference_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/matchers/string_matchers.rb
161
+ has_rdoc: true
162
+ homepage: http://github.com/davisre/dynamic_assets
163
+ licenses:
164
+ - MIT
165
+ post_install_message:
166
+ rdoc_options: []
167
+
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ hash: 3
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ hash: 3
185
+ segments:
186
+ - 0
187
+ version: "0"
188
+ requirements: []
189
+
190
+ rubyforge_project:
191
+ rubygems_version: 1.3.7
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: Make your Rails 3 app process css and js assets on the fly with erb, sass, or scss
195
+ test_files:
196
+ - spec/dummy_rails_app/app/controllers/application_controller.rb
197
+ - spec/dummy_rails_app/app/helpers/application_helper.rb
198
+ - spec/dummy_rails_app/config/application.rb
199
+ - spec/dummy_rails_app/config/boot.rb
200
+ - spec/dummy_rails_app/config/environment.rb
201
+ - spec/dummy_rails_app/config/environments/development.rb
202
+ - spec/dummy_rails_app/config/environments/production.rb
203
+ - spec/dummy_rails_app/config/environments/test.rb
204
+ - spec/dummy_rails_app/config/initializers/backtrace_silencers.rb
205
+ - spec/dummy_rails_app/config/initializers/inflections.rb
206
+ - spec/dummy_rails_app/config/initializers/mime_types.rb
207
+ - spec/dummy_rails_app/config/initializers/secret_token.rb
208
+ - spec/dummy_rails_app/config/initializers/session_store.rb
209
+ - spec/dummy_rails_app/config/routes.rb
210
+ - spec/dummy_rails_app/db/seeds.rb
211
+ - spec/dummy_rails_app/spec/spec_helper.rb
212
+ - spec/dummy_rails_app/test/performance/browsing_test.rb
213
+ - spec/dummy_rails_app/test/test_helper.rb
214
+ - spec/helpers/dynamic_assets_helpers_spec.rb
215
+ - spec/lib/dynamic_assets/config_spec.rb
216
+ - spec/lib/dynamic_assets/manager_spec.rb
217
+ - spec/lib/dynamic_assets/stylesheet_reference_spec.rb
218
+ - spec/spec_helper.rb
219
+ - spec/support/matchers/string_matchers.rb