thorero-assets 0.9.4

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.
@@ -0,0 +1,257 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include Merb::AssetsMixin
3
+
4
+ describe "Accessing Assets" do
5
+ it "should create link to name with absolute url" do
6
+ link_to("The Merb home page", "http://www.merbivore.com/").should ==
7
+ "<a href=\"http://www.merbivore.com/\">The Merb home page</a>"
8
+ end
9
+
10
+ it "should create link to name with relative url" do
11
+ link_to("The Entry Title", "/blog/show/13").should ==
12
+ "<a href=\"/blog/show/13\">The Entry Title</a>"
13
+ end
14
+
15
+ it "should create link with attributes" do
16
+ link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'}).should match(%r{class="special"})
17
+ link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'}).should match(%r{target="blank"})
18
+ end
19
+
20
+ it "should create link with explicit href" do
21
+ link_to("The Foo home page", "http://not.foo.example.com/", :href => "http://foo.example.com").should ==
22
+ "<a href=\"http://foo.example.com\">The Foo home page</a>"
23
+ end
24
+
25
+ it "should create image tag with absolute url" do
26
+ image_tag('http://example.com/foo.gif').should ==
27
+ "<img src=\"http://example.com/foo.gif\" />"
28
+ end
29
+
30
+ it "should create image tag with relative url" do
31
+ image_tag('foo.gif').should ==
32
+ "<img src=\"/images/foo.gif\" />"
33
+ end
34
+
35
+ it "should create image tag with class" do
36
+ result = image_tag('foo.gif', :class => 'bar')
37
+ result.should match(%r{<img .*? />})
38
+ result.should match(%r{src="/images/foo.gif"})
39
+ result.should match(/class="bar"/)
40
+ end
41
+
42
+ it "should create image tag with specified path" do
43
+ image_tag('foo.gif', :path => '/files/').should ==
44
+ "<img src=\"/files/foo.gif\" />"
45
+ end
46
+
47
+ it "should create image tag without extension" do
48
+ image_tag('/dynamic/charts').should ==
49
+ "<img src=\"/dynamic/charts\" />"
50
+ end
51
+
52
+ it "should create image tag without extension and with specified path" do
53
+ image_tag('charts', :path => '/dynamic/').should ==
54
+ "<img src=\"/dynamic/charts\" />"
55
+ end
56
+
57
+ end
58
+
59
+ describe "JavaScript related functions" do
60
+ it "should escape js having quotes" do
61
+ escape_js("'Lorem ipsum!' -- Some guy").should ==
62
+ "\\'Lorem ipsum!\\' -- Some guy"
63
+ end
64
+
65
+ it "should escape js having new lines" do
66
+ escape_js("Please keep text\nlines as skinny\nas possible.").should ==
67
+ "Please keep text\\nlines as skinny\\nas possible."
68
+ end
69
+
70
+ it "should convert objects that respond to to_json to json" do
71
+ js({'user' => 'Lewis', 'page' => 'home'}).should ==
72
+ "{\"user\":\"Lewis\",\"page\":\"home\"}"
73
+ end
74
+
75
+ it "should convert objects using inspect that don't respond to_json to json" do
76
+ js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ]).should ==
77
+ "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
78
+ end
79
+ end
80
+
81
+ describe "External JavaScript and Stylesheets" do
82
+ it "should require a js file only once" do
83
+ require_js :jquery
84
+ require_js :jquery, :effects
85
+ include_required_js.scan(%r{src="/javascripts/jquery.js"}).should have(1).things
86
+ include_required_js.scan(%r{src="/javascripts/effects.js"}).should have(1).things
87
+ end
88
+
89
+ it "should require a css file only once" do
90
+ require_css :style
91
+ require_css :style, 'ie-specific'
92
+
93
+ include_required_css.scan(%r{href="/stylesheets/style.css"}).should have(1).things
94
+ include_required_css.scan(%r{href="/stylesheets/ie-specific.css"}).should have(1).things
95
+ end
96
+
97
+ it "should require included js" do
98
+ require_js 'jquery', 'effects', 'validation'
99
+ result = include_required_js
100
+ result.scan(/<script/).should have(3).things
101
+ result.should match(%r{src="/javascripts/jquery.js"})
102
+ result.should match(%r{src="/javascripts/effects.js"})
103
+ result.should match(%r{src="/javascripts/validation.js"})
104
+ end
105
+
106
+ it "should require included css" do
107
+ require_css 'style', 'ie-specific'
108
+ result = include_required_css
109
+ result.scan(/<link/).should have(2).things
110
+ result.should match(%r{href="/stylesheets/style.css"})
111
+ result.should match(%r{href="/stylesheets/ie-specific.css"})
112
+ end
113
+
114
+ it "should require included js from an absolute path" do
115
+ require_js '/other/scripts.js', '/other/utils'
116
+ result = include_required_js
117
+ result.scan(/<script/).should have(2).things
118
+ result.should match(%r{src="/other/scripts.js"})
119
+ result.should match(%r{src="/other/utils.js"})
120
+ end
121
+
122
+ it "should require included css from an absolute path" do
123
+ require_css '/styles/theme.css', '/styles/fonts'
124
+ result = include_required_css
125
+ result.scan(/<link/).should have(2).things
126
+ result.should match(%r{href="/styles/theme.css"})
127
+ result.should match(%r{href="/styles/fonts.css"})
128
+ end
129
+
130
+ it "should accept options for required javascript files" do
131
+ require_js :jquery, :effects, :bundle => 'basics'
132
+ require_js :jquery, :effects, :other
133
+ required_js.should == [[:jquery, :effects, {:bundle=>"basics"}], [:other, {}]]
134
+ end
135
+
136
+ it "should accept options for required css files" do
137
+ require_css :reset, :fonts, :bundle => 'basics'
138
+ require_css :reset, :fonts, :layout
139
+ required_css.should == [[:reset, :fonts, {:bundle=>"basics"}], [:layout, {}]]
140
+ end
141
+
142
+ it "should create a js include tag with the extension specified" do
143
+ js_include_tag('jquery.js').should ==
144
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
145
+ end
146
+
147
+ it "should create a js include tag and and the extension" do
148
+ js_include_tag('jquery').should ==
149
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
150
+ end
151
+
152
+ it "should create a js include tag for multiple includes" do
153
+ result = js_include_tag('jquery.js', :effects)
154
+ result.scan(/<script/).should have(2).things
155
+ result.should match(%r{/javascripts/jquery.js})
156
+ result.should match(%r{/javascripts/effects.js})
157
+ end
158
+
159
+ it "should create a css include tag with the extension specified" do
160
+ result = css_include_tag('style.css')
161
+ result.should match(%r{<link (.*?) />})
162
+ result.should match(/charset="utf-8"/)
163
+ result.should match(%r{type="text/css"})
164
+ result.should match(%r{href="/stylesheets/style.css"})
165
+ result.should match(%r{rel="Stylesheet"})
166
+ result.should match(%r{media="all"})
167
+ end
168
+
169
+ it "should create a css include tag and add the extension" do
170
+ result = css_include_tag('style')
171
+ result.should match(%r{<link (.*?) />})
172
+ result.should match(/charset="utf-8"/)
173
+ result.should match(%r{type="text/css"})
174
+ result.should match(%r{href="/stylesheets/style.css"})
175
+ result.should match(%r{rel="Stylesheet"})
176
+ result.should match(%r{media="all"})
177
+ end
178
+
179
+ it "should create a css include tag for multiple includes" do
180
+ result = css_include_tag('style.css', :layout)
181
+ result.scan(/<link/).should have(2).things
182
+ result.should match(%r{/stylesheets/style.css})
183
+ result.should match(%r{/stylesheets/layout.css})
184
+ end
185
+
186
+ it "should create a css include tag with the specified media" do
187
+ css_include_tag('style', :media => :print).should match(%r{media="print"})
188
+ end
189
+
190
+ it "should create a css include tag with the specified charset" do
191
+ css_include_tag('style', :charset => 'iso-8859-1').should match(%r{charset="iso-8859-1"})
192
+ end
193
+
194
+ it "should return a uniq path for a single asset" do
195
+ uniq_path("/javascripts/my.js").should ==
196
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
197
+ end
198
+
199
+ it "should return a uniq path for multiple assets" do
200
+ uniq_path("/javascripts/my.js","/javascripts/my.css").should ==
201
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
202
+ end
203
+
204
+ it "should return a uniq path for multiple assets passed as a single array" do
205
+ uniq_path(["/javascripts/my.js","/javascripts/my.css"]).should ==
206
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
207
+ end
208
+
209
+ it "should return a uniq js path for a single js file" do
210
+ uniq_js_path("my").should ==
211
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
212
+ end
213
+
214
+ it "should return a uniq js path for multiple js files" do
215
+ uniq_js_path(["admin/secrets","home/signup"]).should ==
216
+ ["http://assets1.my-awesome-domain.com/javascripts/admin/secrets.js", "http://assets2.my-awesome-domain.com/javascripts/home/signup.js"]
217
+ end
218
+
219
+ it "should return a uniq css path for a single css file" do
220
+ uniq_css_path("my").should ==
221
+ "http://assets1.my-awesome-domain.com/stylesheets/my.css"
222
+ end
223
+
224
+ it "should return a uniq css path for multiple css files" do
225
+ uniq_css_path(["admin/secrets","home/signup"]).should ==
226
+ ["http://assets4.my-awesome-domain.com/stylesheets/admin/secrets.css", "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
227
+ end
228
+
229
+ it "should create a uniq js tag for a single js file" do
230
+ uniq_js_tag("my").should ==
231
+ "<script type=\"text/javascript\" src=\"http://assets2.my-awesome-domain.com/javascripts/my.js\"></script>"
232
+ end
233
+
234
+ it "should create a uniq js tag for each js file specified" do
235
+ result = uniq_js_tag("jquery.js", :effects)
236
+ result.scan(/<script/).should have(2).things
237
+ result.should match(%r{/javascripts/jquery.js})
238
+ result.should match(%r{/javascripts/effects.js})
239
+ end
240
+
241
+ it "should create a uniq css tag for a single css file" do
242
+ result = uniq_css_tag("my")
243
+ result.should match(%r{<link (.*?) />})
244
+ result.should match(/charset="utf-8"/)
245
+ result.should match(%r{type="text/css"})
246
+ result.should match(%r{http://assets1.my-awesome-domain.com/stylesheets/my.css})
247
+ result.should match(%r{rel="Stylesheet"})
248
+ result.should match(%r{media="all"})
249
+ end
250
+
251
+ it "should create a uniq css tag for each css file specified" do
252
+ result = uniq_css_tag("style.css", :layout)
253
+ result.scan(/<link/).should have(2).things
254
+ result.should match(%r{/stylesheets/style.css})
255
+ result.should match(%r{/stylesheets/layout.css})
256
+ end
257
+ end
@@ -0,0 +1,18 @@
1
+ $TESTING=true
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "rubygems"
4
+ require "merb-core"
5
+ require "merb-assets"
6
+ # require File.dirname(__FILE__) / "controllers" / "action-args"
7
+ require "spec"
8
+
9
+ Merb.start :environment => 'test'
10
+
11
+ Merb::Plugins.config[:asset_helpers][:max_hosts] = 4
12
+ Merb::Plugins.config[:asset_helpers][:asset_domain] = "assets%d"
13
+ Merb::Plugins.config[:asset_helpers][:domain] = "my-awesome-domain.com"
14
+
15
+
16
+ Spec::Runner.configure do |config|
17
+ config.include Merb::Test::RequestHelper
18
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thorero-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4
5
+ platform: ruby
6
+ authors:
7
+ - Ezra Zygmuntowicz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-02 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.4
24
+ version:
25
+ description: Merb plugin that provides the helpers for assets and asset bundling
26
+ email: ez@engineyard.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb-assets
41
+ - lib/merb-assets/assets.rb
42
+ - lib/merb-assets/assets_mixin.rb
43
+ - lib/merb-assets.rb
44
+ - spec/merb-assets_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: true
47
+ homepage: http://merbivore.com
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: thorero
68
+ rubygems_version: 1.2.0
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Merb plugin that provides the helpers for assets and asset bundling
72
+ test_files: []
73
+