merb-assets 0.9.2 → 0.9.3

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.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  PLUGIN = "merb-assets"
5
5
  NAME = "merb-assets"
6
- VERSION = "0.9.2"
6
+ VERSION = "0.9.3"
7
7
  AUTHOR = "Ezra Zygmuntowicz"
8
8
  EMAIL = "ez@engineyard.com"
9
9
  HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-assets/"
@@ -20,10 +20,10 @@ spec = Gem::Specification.new do |s|
20
20
  s.author = AUTHOR
21
21
  s.email = EMAIL
22
22
  s.homepage = HOMEPAGE
23
- s.add_dependency('merb-core', '>= 0.9.2')
23
+ s.add_dependency('merb-core', '>= 0.9.3')
24
24
  s.require_path = 'lib'
25
25
  s.autorequire = PLUGIN
26
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
26
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
27
27
  end
28
28
 
29
29
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -31,7 +31,7 @@ Rake::GemPackageTask.new(spec) do |pkg|
31
31
  end
32
32
 
33
33
  task :install => [:package] do
34
- sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources --no-update-sources}
34
+ sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
35
35
  end
36
36
 
37
37
  namespace :jruby do
@@ -42,10 +42,12 @@ module Merb
42
42
  # # => "public/javascripts/dingo.js"
43
43
  def asset_path(asset_type, filename, local_path = false)
44
44
  filename = filename.to_s
45
- if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/
45
+ if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/ && filename.index('?').nil?
46
46
  filename << ASSET_FILE_EXTENSIONS[asset_type]
47
47
  end
48
- filename = "/#{asset_type}s/#{filename}"
48
+ if filename !~ %r{^https?://}
49
+ filename = "/#{asset_type}s/#{filename}"
50
+ end
49
51
  if local_path
50
52
  return "public#{filename}"
51
53
  else
@@ -59,8 +61,6 @@ module Merb
59
61
  # for downloading static files (css, js, images...)
60
62
  class UniqueAssetPath
61
63
  class << self
62
- @@config = Merb::Plugins.config[:asset_helpers]
63
-
64
64
  # Builds the path to the file based on the name
65
65
  #
66
66
  # ==== Parameters
@@ -74,9 +74,10 @@ module Merb
74
74
  # # => "https://assets5.my-awesome-domain.com/javascripts/my_fancy_script.js"
75
75
  #
76
76
  def build(filename)
77
- #%{#{(USE_SSL ? 'https' : 'http')}://#{sprintf(@@config[:asset_domain],self.calculate_host_id(file))}.#{@@config[:domain]}/#{filename}}
78
- path = @@config[:use_ssl] ? 'https://' : 'http://'
79
- path << sprintf(@@config[:asset_domain],self.calculate_host_id(filename)) << ".#{@@config[:domain]}"
77
+ config = Merb::Plugins.config[:asset_helpers]
78
+ #%{#{(USE_SSL ? 'https' : 'http')}://#{sprintf(config[:asset_domain],self.calculate_host_id(file))}.#{config[:domain]}/#{filename}}
79
+ path = config[:use_ssl] ? 'https://' : 'http://'
80
+ path << sprintf(config[:asset_domain],self.calculate_host_id(filename)) << ".#{config[:domain]}"
80
81
  path << "/" if filename.index('/') != 0
81
82
  path << filename
82
83
  end
@@ -89,15 +90,48 @@ module Merb
89
90
  filename.each_byte {|byte|
90
91
  ascii_total += byte
91
92
  }
92
- (ascii_total % @@config[:max_hosts] + 1)
93
+ (ascii_total % Merb::Plugins.config[:asset_helpers][:max_hosts] + 1)
93
94
  end
94
95
  end
95
96
  end
96
97
 
97
98
  # An abstract class for bundling text assets into single files.
98
99
  class AbstractAssetBundler
100
+
101
+ class_inheritable_array :cached_bundles
102
+ self.cached_bundles ||= []
103
+
99
104
  class << self
100
105
 
106
+ # Mark a bundle as cached.
107
+ #
108
+ # ==== Parameters
109
+ # name<~to_s>:: Name of the bundle
110
+ #
111
+ def cache_bundle(name)
112
+ cached_bundles.push(name.to_s)
113
+ end
114
+
115
+ # Purge a bundle from the cache.
116
+ #
117
+ # ==== Parameters
118
+ # name<~to_s>:: Name of the bundle
119
+ #
120
+ def purge_bundle(name)
121
+ cached_bundles.delete(name.to_s)
122
+ end
123
+
124
+ # Test if a bundle has been cached.
125
+ #
126
+ # ==== Parameters
127
+ # name<~to_s>:: Name of the bundle
128
+ #
129
+ # ==== Returns
130
+ # Boolean:: Whether the bundle has been cached or not.
131
+ def cached_bundle?(name)
132
+ cached_bundles.include?(name.to_s)
133
+ end
134
+
101
135
  # ==== Parameters
102
136
  # &block:: A block to add as a post-bundle callback.
103
137
  #
@@ -145,10 +179,19 @@ module Merb
145
179
  # ==== Returns
146
180
  # Symbol:: Name of the bundle.
147
181
  def bundle!
148
- # TODO: Move this file check out into an in-memory cache. Also, push it out to the helper level so we don't have to create the helper object.
149
- unless File.exist?(@bundle_filename)
182
+ # TODO: push it out to the helper level so we don't have to create the helper object.
183
+ unless self.class.cached_bundle?(@bundle_name)
184
+ # skip regeneration of new bundled files - preventing multiple merb apps stepping on eachother
185
+ # file needs to be older than 60 seconds to be regenerated
186
+ if File.exist?(@bundle_filename) && File.mtime(@bundle_filename) >= Time.now - 60
187
+ return @bundle_name # serve the old file for now - to be regenerated later
188
+ end
150
189
  bundle_files(@bundle_filename, *@files)
151
- self.class.callbacks.each { |c| c.call(@bundle_filename) }
190
+ if File.exist?(@bundle_filename)
191
+ self.class.callbacks.each { |c| c.call(@bundle_filename) }
192
+ Merb.logger.info("Assets: bundled :#{@bundle_name} into #{File.basename(@bundle_filename)}")
193
+ self.class.cache_bundle(@bundle_name)
194
+ end
152
195
  end
153
196
  return @bundle_name
154
197
  end
@@ -164,7 +207,9 @@ module Merb
164
207
  # *files<String>:: Filenames to be bundled.
165
208
  def bundle_files(filename, *files)
166
209
  File.open(filename, "w") do |f|
210
+ f.flock(File::LOCK_EX)
167
211
  files.each { |file| f.puts(File.read(file)) }
212
+ f.flock(File::LOCK_UN)
168
213
  end
169
214
  end
170
215
 
@@ -7,6 +7,47 @@ module Merb
7
7
  # Merb provides views with convenience methods for links images and other
8
8
  # assets.
9
9
 
10
+
11
+ # ==== Parameters
12
+ # none
13
+ #
14
+ # ==== Returns
15
+ # html<String>
16
+ #
17
+ # ==== Examples
18
+ # We want all possible matches in the FileSys up to the action name
19
+ # Given: controller_name = "namespace/controller"
20
+ # action_name = "action"
21
+ # If all files are present should generate link/script tags for:
22
+ # namespace.(css|js)
23
+ # namespace/controller.(css|js)
24
+ # namespace/controller/action.(css|js)
25
+ #
26
+ def auto_link
27
+ html = ""
28
+ prefix = ""
29
+ (controller_name / action_name).split("/").each do |path|
30
+ path = prefix + path
31
+
32
+ css_path = path + ".css"
33
+ if File.exists? Merb.root / "public" / "stylesheets" / css_path
34
+ html << %{<link rel="stylesheet" type="text/css" href="/stylesheets/#{css_path}" /> }
35
+ end
36
+
37
+ js_path = path + ".js"
38
+ if File.exists? Merb.root / "public" / "javascripts" / js_path
39
+ html << %{<script type="text/javascript" language="javascript" src="/javascripts/#{js_path}"></script>}
40
+ end
41
+
42
+ #Update the prefix for the next iteration
43
+ prefix += path / ""
44
+ end
45
+
46
+ #Return the generated HTML
47
+ html
48
+ end
49
+
50
+
10
51
  # ==== Parameters
11
52
  # name<~to_s>:: The text of the link.
12
53
  # url<~to_s>:: The URL to link to. Defaults to an empty string.
@@ -20,7 +61,7 @@ module Merb
20
61
  # # => <a href="http://www.ruby-lang.org" class="special" target="blank">The Ruby home page</a>
21
62
  #
22
63
  # link_to p.title, "/blog/show/#{p.id}"
23
- # # => <a href="blog/show/13">The Entry Title</a>
64
+ # # => <a href="/blog/show/13">The Entry Title</a>
24
65
  #
25
66
  def link_to(name, url='', opts={})
26
67
  opts[:href] ||= url
@@ -102,7 +143,7 @@ module Merb
102
143
  # link_to_function('Add to cart', "item_total += 1; alert('Item added!');")
103
144
  # # => <a href="#" onclick="item_total += 1; alert('Item added!'); return false;">Add to cart</a>
104
145
  def link_to_function(name, function)
105
- %{<a href="#" onclick="#{function}; return false;">#{name}</a>}
146
+ %{<a href="#" onclick="#{function.chomp(";")}; return false;">#{name}</a>}
106
147
  end
107
148
 
108
149
  # ==== Parameters
@@ -265,7 +306,7 @@ module Merb
265
306
  #
266
307
  def require_js(*js)
267
308
  @required_js ||= []
268
- @required_js |= js
309
+ @required_js << js
269
310
  end
270
311
 
271
312
  # The require_css method can be used to require any CSS file anywhere in
@@ -287,7 +328,7 @@ module Merb
287
328
  #
288
329
  def require_css(*css)
289
330
  @required_css ||= []
290
- @required_css |= css
331
+ @required_css << css
291
332
  end
292
333
 
293
334
  # A method used in the layout of an application to create +<script>+ tags
@@ -296,6 +337,10 @@ module Merb
296
337
  #
297
338
  # ==== Parameters
298
339
  # options<Hash>:: Options to pass to js_include_tag.
340
+ #
341
+ # ==== Options
342
+ # :bundle<~to_s>::
343
+ # The name of the bundle the scripts should be combined into.
299
344
  #
300
345
  # ==== Returns
301
346
  # String:: The JavaScript tag.
@@ -314,8 +359,14 @@ module Merb
314
359
  # # <script src="/javascripts/validation.js" type="text/javascript"></script>
315
360
  #
316
361
  def include_required_js(options = {})
317
- return '' if @required_js.nil?
318
- js_include_tag(*(@required_js + [options]))
362
+ return '' if @required_js.nil? || @required_js.empty?
363
+ @required_js.map do |req_js|
364
+ if req_js.last.is_a?(Hash)
365
+ js_include_tag(*(req_js[0..-2] + [options.merge(req_js.last)]))
366
+ else
367
+ js_include_tag(*(req_js + [options]))
368
+ end
369
+ end.join
319
370
  end
320
371
 
321
372
  # A method used in the layout of an application to create +<link>+ tags for
@@ -327,6 +378,12 @@ module Merb
327
378
  #
328
379
  # ==== Returns
329
380
  # String:: The CSS tag.
381
+ #
382
+ # ==== Options
383
+ # :bundle<~to_s>::
384
+ # The name of the bundle the stylesheets should be combined into.
385
+ # :media<~to_s>::
386
+ # The media attribute for the generated link element. Defaults to :all.
330
387
  #
331
388
  # ==== Examples
332
389
  # # my_action.herb has a call to require_css 'style'
@@ -334,15 +391,21 @@ module Merb
334
391
  # include_required_css
335
392
  # # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
336
393
  #
337
- # # my_action.herb has a call to require_js 'style', 'ie-specific'
394
+ # # my_action.herb has a call to require_css 'style', 'ie-specific'
338
395
  # # File: layout/application.html.erb
339
396
  # include_required_css
340
397
  # # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
341
398
  # # <link href="/stylesheets/ie-specific.css" media="all" rel="Stylesheet" type="text/css"/>
342
399
  #
343
400
  def include_required_css(options = {})
344
- return '' if @required_css.nil?
345
- css_include_tag(*(@required_css + [options]))
401
+ return '' if @required_css.nil? || @required_css.empty?
402
+ @required_css.map do |req_css|
403
+ if req_css.last.is_a?(Hash)
404
+ css_include_tag(*(req_css[0..-2] + [options.merge(req_css.last)]))
405
+ else
406
+ css_include_tag(*(req_css + [options]))
407
+ end
408
+ end.join
346
409
  end
347
410
 
348
411
  # ==== Parameters
@@ -466,7 +529,7 @@ module Merb
466
529
  # String:: if only a single path is requested
467
530
  # ==== Examples
468
531
  # uniq_path("/javascripts/my.js","/javascripts/my.css")
469
- # #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
532
+ # #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets1.my-awesome-domain.com/javascripts/my.css"]
470
533
  #
471
534
  # uniq_path(["/javascripts/my.js","/stylesheets/my.css"])
472
535
  # #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets1.my-awesome-domain.com/stylesheets/my.css"]
@@ -482,7 +545,7 @@ module Merb
482
545
  def uniq_path(*assets)
483
546
  paths = []
484
547
  assets.collect.flatten.each do |filename|
485
- paths.push(UniqueAssetPath.build(filename))
548
+ paths.push(Merb::Assets::UniqueAssetPath.build(filename))
486
549
  end
487
550
  paths.length > 1 ? paths : paths.first
488
551
  end
@@ -504,7 +567,7 @@ module Merb
504
567
  def uniq_js_path(*assets)
505
568
  paths = []
506
569
  assets.collect.flatten.each do |filename|
507
- paths.push(UniqueAssetPath.build(asset_path(:javascript,filename,true)))
570
+ paths.push(Merb::Assets::UniqueAssetPath.build(asset_path(:javascript,filename)))
508
571
  end
509
572
  paths.length > 1 ? paths : paths.first
510
573
  end
@@ -526,7 +589,7 @@ module Merb
526
589
  def uniq_css_path(*assets)
527
590
  paths = []
528
591
  assets.collect.flatten.each do |filename|
529
- paths.push(UniqueAssetPath.build(asset_path(:stylesheet,filename,true)))
592
+ paths.push(Merb::Assets::UniqueAssetPath.build(asset_path(:stylesheet,filename)))
530
593
  end
531
594
  paths.length > 1 ? paths : paths.first
532
595
  end
@@ -542,7 +605,7 @@ module Merb
542
605
  # uniq_js_tag("my")
543
606
  # #=> <script type="text/javascript" src="http://assets2.my-awesome-domain.com/javascripts/my.js"></script>
544
607
  def uniq_js_tag(*assets)
545
- js_include_tag(uniq_js_path(assets))
608
+ js_include_tag(*uniq_js_path(assets))
546
609
  end
547
610
 
548
611
  # ==== Parameters
@@ -556,7 +619,7 @@ module Merb
556
619
  # uniq_css_tag("my")
557
620
  # #=> <link href="http://assets2.my-awesome-domain.com/stylesheets/my.css" type="text/css" />
558
621
  def uniq_css_tag(*assets)
559
- css_include_tag(uniq_css_path(assets))
622
+ css_include_tag(*uniq_css_path(assets))
560
623
  end
561
624
  end
562
625
  end
@@ -0,0 +1,240 @@
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 ==
17
+ "<a class=\"special\" href=\"http://www.ruby-lang.org\" target=\"blank\">The Ruby home page</a>"
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 create link to a function" do
71
+ link_to_function('Click me', "alert('hi!')").should ==
72
+ "<a href=\"#\" onclick=\"alert('hi!'); return false;\">Click me</a>"
73
+ end
74
+
75
+ it "should create a link to a function having multiple statements" do
76
+ link_to_function('Add to cart', "item_total += 1; alert('Item added!');").should ==
77
+ "<a href=\"#\" onclick=\"item_total += 1; alert('Item added!'); return false;\">Add to cart</a>"
78
+ end
79
+
80
+ it "should convert objects that respond to to_json to json" do
81
+ js({'user' => 'Lewis', 'page' => 'home'}).should ==
82
+ "{\"user\":\"Lewis\",\"page\":\"home\"}"
83
+ end
84
+
85
+ it "should convert objects using inspect that don't respond to_json to json" do
86
+ js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ]).should ==
87
+ "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
88
+ end
89
+ end
90
+
91
+ describe "External JavaScript and Stylesheets" do
92
+ it "should require a js file only once" do
93
+ require_js 'jquery'
94
+ require_js 'jquery', 'effects'
95
+
96
+ include_required_js.scan(%r{/javascripts/jquery.js}).should have(1).things
97
+ include_required_js.scan(%r{/javascripts/effects.js}).should have(1).things
98
+ end
99
+
100
+ it "should require a css file only once" do
101
+ require_css('style')
102
+ require_css('style', 'ie-specific')
103
+
104
+ include_required_css.scan(%r{/stylesheets/style.css}).should have(1).things
105
+ include_required_css.scan(%r{/stylesheets/ie-specific.css}).should have(1).things
106
+ end
107
+
108
+ it "should require included js" do
109
+ require_js 'jquery', 'effects', 'validation'
110
+ result = include_required_js
111
+ result.scan(/<script/).should have(3).things
112
+ result.should match(%r{/javascripts/jquery.js})
113
+ result.should match(%r{/javascripts/effects.js})
114
+ result.should match(%r{/javascripts/validation.js})
115
+ end
116
+
117
+ it "should require included css" do
118
+ require_css 'style', 'ie-specific'
119
+ result = include_required_css
120
+ result.scan(/<link/).should have(2).things
121
+ result.should match(%r{/stylesheets/style.css})
122
+ result.should match(%r{/stylesheets/ie-specific.css})
123
+ end
124
+
125
+ it "should create a js include tag with the extension specified" do
126
+ js_include_tag('jquery.js').should ==
127
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
128
+ end
129
+
130
+ it "should create a js include tag and and the extension" do
131
+ js_include_tag('jquery').should ==
132
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
133
+ end
134
+
135
+ it "should create a js include tag for multiple includes" do
136
+ result = js_include_tag('jquery.js', :effects)
137
+ result.scan(/<script/).should have(2).things
138
+ result.should match(%r{/javascripts/jquery.js})
139
+ result.should match(%r{/javascripts/effects.js})
140
+ end
141
+
142
+ it "should create a css include tag with the extension specified" do
143
+ result = css_include_tag('style.css')
144
+ result.should match(%r{<link (.*?) />})
145
+ result.should match(/charset="utf-8"/)
146
+ result.should match(%r{type="text/css"})
147
+ result.should match(%r{href="/stylesheets/style.css"})
148
+ result.should match(%r{rel="Stylesheet"})
149
+ result.should match(%r{media="all"})
150
+ end
151
+
152
+ it "should create a css include tag and add the extension" do
153
+ result = css_include_tag('style')
154
+ result.should match(%r{<link (.*?) />})
155
+ result.should match(/charset="utf-8"/)
156
+ result.should match(%r{type="text/css"})
157
+ result.should match(%r{href="/stylesheets/style.css"})
158
+ result.should match(%r{rel="Stylesheet"})
159
+ result.should match(%r{media="all"})
160
+ end
161
+
162
+ it "should create a css include tag for multiple includes" do
163
+ result = css_include_tag('style.css', :layout)
164
+ result.scan(/<link/).should have(2).things
165
+ result.should match(%r{/stylesheets/style.css})
166
+ result.should match(%r{/stylesheets/layout.css})
167
+ end
168
+
169
+ it "should create a css include tag with the specified media" do
170
+ css_include_tag('style', :media => :print).should match(%r{media="print"})
171
+ end
172
+
173
+ it "should create a css include tag with the specified charset" do
174
+ css_include_tag('style', :charset => 'iso-8859-1').should match(%r{charset="iso-8859-1"})
175
+ end
176
+
177
+ it "should return a uniq path for a single asset" do
178
+ uniq_path("/javascripts/my.js").should ==
179
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
180
+ end
181
+
182
+ it "should return a uniq path for multiple assets" do
183
+ uniq_path("/javascripts/my.js","/javascripts/my.css").should ==
184
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
185
+ end
186
+
187
+ it "should return a uniq path for multiple assets passed as a single array" do
188
+ uniq_path(["/javascripts/my.js","/javascripts/my.css"]).should ==
189
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
190
+ end
191
+
192
+ it "should return a uniq js path for a single js file" do
193
+ uniq_js_path("my").should ==
194
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
195
+ end
196
+
197
+ it "should return a uniq js path for multiple js files" do
198
+ uniq_js_path(["admin/secrets","home/signup"]).should ==
199
+ ["http://assets1.my-awesome-domain.com/javascripts/admin/secrets.js", "http://assets2.my-awesome-domain.com/javascripts/home/signup.js"]
200
+ end
201
+
202
+ it "should return a uniq css path for a single css file" do
203
+ uniq_css_path("my").should ==
204
+ "http://assets1.my-awesome-domain.com/stylesheets/my.css"
205
+ end
206
+
207
+ it "should return a uniq css path for multiple css files" do
208
+ uniq_css_path(["admin/secrets","home/signup"]).should ==
209
+ ["http://assets4.my-awesome-domain.com/stylesheets/admin/secrets.css", "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
210
+ end
211
+
212
+ it "should create a uniq js tag for a single js file" do
213
+ uniq_js_tag("my").should ==
214
+ "<script type=\"text/javascript\" src=\"http://assets2.my-awesome-domain.com/javascripts/my.js\"></script>"
215
+ end
216
+
217
+ it "should create a uniq js tag for each js file specified" do
218
+ result = uniq_js_tag("jquery.js", :effects)
219
+ result.scan(/<script/).should have(2).things
220
+ result.should match(%r{/javascripts/jquery.js})
221
+ result.should match(%r{/javascripts/effects.js})
222
+ end
223
+
224
+ it "should create a uniq css tag for a single css file" do
225
+ result = uniq_css_tag("my")
226
+ result.should match(%r{<link (.*?) />})
227
+ result.should match(/charset="utf-8"/)
228
+ result.should match(%r{type="text/css"})
229
+ result.should match(%r{http://assets1.my-awesome-domain.com/stylesheets/my.css})
230
+ result.should match(%r{rel="Stylesheet"})
231
+ result.should match(%r{media="all"})
232
+ end
233
+
234
+ it "should create a uniq css tag for each css file specified" do
235
+ result = uniq_css_tag("style.css", :layout)
236
+ result.scan(/<link/).should have(2).things
237
+ result.should match(%r{/stylesheets/style.css})
238
+ result.should match(%r{/stylesheets/layout.css})
239
+ end
240
+ end
@@ -0,0 +1,13 @@
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
+ Spec::Runner.configure do |config|
12
+ config.include Merb::Test::RequestHelper
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire: merb-assets
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-24 00:00:00 -05:00
12
+ date: 2008-05-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.9.2
22
+ version: 0.9.3
23
23
  version:
24
24
  description: Merb plugin that provides the helpers for assets and asset bundling
25
25
  email: ez@engineyard.com
@@ -40,6 +40,8 @@ files:
40
40
  - lib/merb-assets/assets.rb
41
41
  - lib/merb-assets/assets_mixin.rb
42
42
  - lib/merb-assets.rb
43
+ - spec/merb-assets_spec.rb
44
+ - spec/spec_helper.rb
43
45
  has_rdoc: true
44
46
  homepage: http://merb-plugins.rubyforge.org/merb-assets/
45
47
  post_install_message: