assets_booster 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,9 +21,8 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "rails", "~>3.0.5"
23
23
  s.add_dependency "rainpress", "~>1.0"
24
- s.add_dependency "yui-compressor", "~>0.9.4"
25
- s.add_dependency "yui-compressor", ">=0.9.6"
24
+ s.add_dependency "yui-compressor", "~>0.9.6"
26
25
 
27
26
  s.add_development_dependency "rspec", "~>2.5.0"
27
+ s.add_development_dependency "rspec-rails", "~>2.5.0"
28
28
  end
29
-
@@ -51,9 +51,8 @@ module AssetsBooster
51
51
  save(code)
52
52
  end
53
53
 
54
- def view_helper(packager)
55
- sources = packager.boosted_environment? ? [name] : assets
56
- [view_helper_method, sources]
54
+ def view_helper_sources
55
+ AssetsBooster::Railtie.packager.boosted_environment? ? [name] : assets
57
56
  end
58
57
 
59
58
  private
@@ -11,8 +11,12 @@ module AssetsBooster
11
11
  path = File.join(path, name+".js") if name
12
12
  end
13
13
 
14
- def view_helper_method
15
- :javascript_include_tag
14
+ def view_helper(view, options)
15
+ if options[:inline]
16
+ view.javascript_tag(read(assets))
17
+ else
18
+ view.javascript_include_tag(view_helper_sources, options)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -11,8 +11,12 @@ module AssetsBooster
11
11
  path = File.join(path, name+".css") if name
12
12
  end
13
13
 
14
- def view_helper_method
15
- :stylesheet_link_tag
14
+ def view_helper(view, options)
15
+ if options[:inline]
16
+ view.style_tag(read(assets))
17
+ else
18
+ view.stylesheet_link_tag(view_helper_sources, options)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module AssetsBooster
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,12 +1,14 @@
1
1
  module AssetsBooster
2
2
  module ViewHelper
3
+ def style_tag(css)
4
+ content_tag(:style, css, :type => Mime::CSS)
5
+ end
6
+
3
7
  def assets_booster_tag(type, *names)
4
8
  options = names.extract_options!
5
- packager = AssetsBooster::Railtie.packager
6
- packages = packager.packages[type]
9
+ packages = AssetsBooster::Railtie.packager.packages[type]
7
10
  html = names.map do |name|
8
- methode, sources = packages[name].view_helper(packager)
9
- send(methode, sources, options)
11
+ packages[name].view_helper(self, options)
10
12
  end*"\n"
11
13
  html.html_safe
12
14
  end
data/spec/package/base.rb CHANGED
@@ -15,9 +15,19 @@ module AssetsBooster
15
15
  end
16
16
  end
17
17
 
18
- describe "view_helper_method" do
19
- it "should return a symbol" do
20
- subject.view_helper_method.should be_an_instance_of(Symbol)
18
+ describe "view_helper_sources" do
19
+ before do
20
+ AssetsBooster::Railtie.packager = double("Packager")
21
+ end
22
+
23
+ it "should return a the package if running in a boosted environment" do
24
+ AssetsBooster::Railtie.packager.should_receive(:boosted_environment?).and_return(true)
25
+ subject.view_helper_sources.should == [subject.name]
26
+ end
27
+
28
+ it "should return the package's sources if running in a non-boosted environment" do
29
+ AssetsBooster::Railtie.packager.should_receive(:boosted_environment?).and_return(false)
30
+ subject.view_helper_sources.should == subject.assets
21
31
  end
22
32
  end
23
33
  end
@@ -9,6 +9,32 @@ module AssetsBooster
9
9
  subject.asset_path("lala").should match(/javascripts\/lala\.js/)
10
10
  end
11
11
  end
12
+
13
+ describe "view_helper" do
14
+ before do
15
+ @view = double("View")
16
+ end
17
+
18
+ describe "with the inline option enabled" do
19
+ it "should return a javascript tag with inline javascript" do
20
+ assets = ["a.js", "b.js", "c.js"]
21
+ subject.stub(:assets).and_return(assets)
22
+ subject.should_receive(:read).with(assets).and_return("javascript code")
23
+ @view.should_receive(:javascript_tag).with("javascript code")
24
+ subject.view_helper(@view, :inline => true)
25
+ end
26
+ end
27
+
28
+ describe "with no options" do
29
+ it "should return html tags" do
30
+ options = {}
31
+ sources = ["source1.js", "source2.js"]
32
+ subject.should_receive(:view_helper_sources).and_return(sources)
33
+ @view.should_receive(:javascript_include_tag).with(sources, options)
34
+ subject.view_helper(@view, options)
35
+ end
36
+ end
37
+ end
12
38
  end
13
39
  end
14
40
  end
@@ -9,6 +9,32 @@ module AssetsBooster
9
9
  subject.asset_path("lala").should match(/stylesheets\/lala\.css/)
10
10
  end
11
11
  end
12
+
13
+ describe "view_helper" do
14
+ before do
15
+ @view = double("View")
16
+ end
17
+
18
+ describe "with the inline option enabled" do
19
+ it "should return a style tag with inline css" do
20
+ assets = ["a.css", "b.css", "c.css"]
21
+ subject.stub(:assets).and_return(assets)
22
+ subject.should_receive(:read).with(assets).and_return("css code")
23
+ @view.should_receive(:style_tag).with("css code")
24
+ subject.view_helper(@view, :inline => true)
25
+ end
26
+ end
27
+
28
+ describe "with no options" do
29
+ it "should return html tags" do
30
+ options = {}
31
+ sources = ["source1.css", "source2.css"]
32
+ subject.should_receive(:view_helper_sources).and_return(sources)
33
+ @view.should_receive(:stylesheet_link_tag).with(sources, options)
34
+ subject.view_helper(@view, options)
35
+ end
36
+ end
37
+ end
12
38
  end
13
39
  end
14
40
  end
@@ -33,12 +33,12 @@ module AssetsBooster
33
33
  it "should compile all assets of all packages" do
34
34
  YAML.should_receive(:load_file).with(subject.configuration_filename).and_return(
35
35
  'packages' => {
36
- 'javascript' => {
37
- 'base' => %w(jquery rails),
38
- },
39
36
  'stylesheet' => {
40
37
  'base' => %w(screen),
41
38
  },
39
+ 'javascript' => {
40
+ 'base' => %w(jquery rails),
41
+ },
42
42
  },
43
43
  'options' => {
44
44
  'javascript' => {
@@ -1,10 +1,22 @@
1
1
  require 'spec_helper'
2
2
  require 'assets_booster/view_helper'
3
3
  module AssetsBooster
4
- describe ViewHelper do
4
+ describe ViewHelper, :type => :helper do
5
+ describe "style_tag" do
6
+ it "should return a style tag with inline css" do
7
+ pending "don't know how to write view helper specs"
8
+ puts helper.style_tag("body{background:#ff0}")
9
+ helper.style_tag("body{background:#ff0}").should == <<-EOT
10
+ <style type="text/css">
11
+ body{background:#ff0}
12
+ </style>
13
+ EOT
14
+ end
15
+ end
16
+
5
17
  describe "assets_booster_tag" do
6
18
  it "should return html tags" do
7
- pending
19
+ pending "don't know how to write view helper specs"
8
20
  end
9
21
  end
10
22
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assets_booster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
5
+ version: 0.0.7
11
6
  platform: ruby
12
7
  authors:
13
8
  - Corin Langosch
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-04 00:00:00 +02:00
19
- default_executable:
13
+ date: 2011-04-13 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: rails
@@ -26,11 +20,6 @@ dependencies:
26
20
  requirements:
27
21
  - - ~>
28
22
  - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 3
32
- - 0
33
- - 5
34
23
  version: 3.0.5
35
24
  type: :runtime
36
25
  version_requirements: *id001
@@ -42,10 +31,6 @@ dependencies:
42
31
  requirements:
43
32
  - - ~>
44
33
  - !ruby/object:Gem::Version
45
- hash: 15
46
- segments:
47
- - 1
48
- - 0
49
34
  version: "1.0"
50
35
  type: :runtime
51
36
  version_requirements: *id002
@@ -57,43 +42,28 @@ dependencies:
57
42
  requirements:
58
43
  - - ~>
59
44
  - !ruby/object:Gem::Version
60
- hash: 51
61
- segments:
62
- - 0
63
- - 9
64
- - 4
65
- version: 0.9.4
45
+ version: 0.9.6
66
46
  type: :runtime
67
47
  version_requirements: *id003
68
48
  - !ruby/object:Gem::Dependency
69
- name: yui-compressor
49
+ name: rspec
70
50
  prerelease: false
71
51
  requirement: &id004 !ruby/object:Gem::Requirement
72
52
  none: false
73
53
  requirements:
74
- - - ">="
54
+ - - ~>
75
55
  - !ruby/object:Gem::Version
76
- hash: 55
77
- segments:
78
- - 0
79
- - 9
80
- - 6
81
- version: 0.9.6
82
- type: :runtime
56
+ version: 2.5.0
57
+ type: :development
83
58
  version_requirements: *id004
84
59
  - !ruby/object:Gem::Dependency
85
- name: rspec
60
+ name: rspec-rails
86
61
  prerelease: false
87
62
  requirement: &id005 !ruby/object:Gem::Requirement
88
63
  none: false
89
64
  requirements:
90
65
  - - ~>
91
66
  - !ruby/object:Gem::Version
92
- hash: 27
93
- segments:
94
- - 2
95
- - 5
96
- - 0
97
67
  version: 2.5.0
98
68
  type: :development
99
69
  version_requirements: *id005
@@ -153,7 +123,6 @@ files:
153
123
  - spec/packager_spec.rb
154
124
  - spec/spec_helper.rb
155
125
  - spec/view_helper_spec.rb
156
- has_rdoc: true
157
126
  homepage: http://github.com/gucki/assets_booster
158
127
  licenses: []
159
128
 
@@ -167,23 +136,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
136
  requirements:
168
137
  - - ">="
169
138
  - !ruby/object:Gem::Version
170
- hash: 3
171
- segments:
172
- - 0
173
139
  version: "0"
174
140
  required_rubygems_version: !ruby/object:Gem::Requirement
175
141
  none: false
176
142
  requirements:
177
143
  - - ">="
178
144
  - !ruby/object:Gem::Version
179
- hash: 3
180
- segments:
181
- - 0
182
145
  version: "0"
183
146
  requirements: []
184
147
 
185
148
  rubyforge_project: assets_booster
186
- rubygems_version: 1.5.3
149
+ rubygems_version: 1.7.2
187
150
  signing_key:
188
151
  specification_version: 3
189
152
  summary: Assets (javascripts, css) compression for rails applications