merb-assets 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,250 @@
1
1
  merb-assets
2
2
  ===========
3
3
 
4
- A plugin for the Merb framework that provides ...
4
+ Provides extra functionality related to assets:
5
+
6
+ # Assets bundling.
7
+ # Assets hosts.
8
+ # Helpers to add asset links to views.
9
+ # Deployment-time assets processing (for instance, with YUI Compressor).
10
+
11
+ Quick overview of the API
12
+ ==============================
13
+
14
+ # asset_path generates path for asset taking type and name.
15
+ # UniqueAssetPath class handles generation of paths using subdomains.
16
+ # AbstractAssetBundler is the base asset bundlers class.
17
+
18
+ # auto_link generates conventional asset tags based on controller/action.
19
+ # link_to creates anchor tag (a tag).
20
+ # image_tag creates img tag.
21
+
22
+ # escape_js escapes JavaScript.
23
+ # js method translates object into JSON.
24
+
25
+ # require_js is smart(-er) way to do includes just once per page no matter
26
+ how many times partial use it.
27
+ # require_css is like require_js but for JavaScript.
28
+
29
+ # js_include_tag is used when you need to include script tag with bundling.
30
+ # css_include_tag works like js_include_tag but for stylesheets.
31
+ # include_required_js generates script tags for previously included files.
32
+ # include_required_css generates link tags for previously included files.
33
+
34
+ # uniq_js_path generates a script tag for path with asset subdomain.
35
+ # uniq_css_path generates a link tag for path with asset subdomain.
36
+
37
+
38
+ Examples
39
+ ===========
40
+
41
+ auto_link to include asset tags using convention:
42
+
43
+ We want all possible matches in the FileSys up to the action name
44
+ Given: controller_name = "namespace/controller"
45
+ action_name = "action"
46
+ If all files are present should generate link/script tags for:
47
+ namespace.(css|js)
48
+ namespace/controller.(css|js)
49
+ namespace/controller/action.(css|js)
50
+
51
+ link_to and image_tag to make anchor and image tags:
52
+
53
+ image_tag('foo.gif')
54
+ # => <img src='/images/foo.gif' />
55
+
56
+ image_tag('foo.gif', :class => 'bar')
57
+ # => <img src='/images/foo.gif' class='bar' />
58
+
59
+ image_tag('foo.gif', :path => '/files/')
60
+ # => <img src='/files/foo.gif' />
61
+
62
+ image_tag('http://test.com/foo.gif')
63
+ # => <img src="http://test.com/foo.gif">
64
+
65
+ image_tag('charts', :path => '/dynamic/')
66
+ or
67
+ image_tag('/dynamic/charts')
68
+ # => <img src="/dynamic/charts">
69
+
70
+ link_to("The Merb home page", "http://www.merbivore.com/")
71
+ # => <a href="http://www.merbivore.com/">The Merb home page</a>
72
+
73
+ link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'})
74
+ # => <a href="http://www.ruby-lang.org" class="special" target="blank">The Ruby home page</a>
75
+
76
+ link_to p.title, "/blog/show/#{p.id}"
77
+ # => <a href="/blog/show/13">The Entry Title</a>
78
+
79
+ uniq_css_tag and uniq_js_tag for paths with asset subdomains:
80
+
81
+ uniq_css_tag("my")
82
+ #=> <link href="http://assets2.my-awesome-domain.com/stylesheets/my.css" type="text/css" />
83
+
84
+ uniq_js_tag("my")
85
+ #=> <script type="text/javascript" src="http://assets2.my-awesome-domain.com/javascripts/my.js"></script>
86
+
87
+ uniq_js_path("my")
88
+ #=> "http://assets2.my-awesome-domain.com/javascripts/my.js"
89
+
90
+ uniq_js_path(["admin/secrets","home/signup"])
91
+ #=> ["http://assets2.my-awesome-domain.com/javascripts/admin/secrets.js",
92
+ "http://assets1.my-awesome-domain.com/javascripts/home/signup.js"]
93
+
94
+ re_js and require_css, include_required_js and include_requried_css
95
+ quire assets in parts/partials just once:
96
+
97
+
98
+ In your application layout:
99
+
100
+ js_include_tag :prototype, :lowpro, :bundle => :base
101
+
102
+ In your controller layout:
103
+
104
+ require_js :bundle => :posts
105
+
106
+ The require_js method can be used to require any JavaScript file anywhere
107
+ in your templates. Regardless of how many times a single script is
108
+ included with require_js, Merb will only include it once in the header.
109
+
110
+ # File: app/views/layouts/application.html.erb
111
+
112
+ <html>
113
+ <head>
114
+ <%= include_required_js %>
115
+ <%= include_required_css %>
116
+ </head>
117
+ <body>
118
+ <%= catch_content :layout %>
119
+ </body>
120
+ </html>
121
+
122
+ # File: app/views/whatever/_part1.herb
123
+
124
+ <% require_js 'this' -%>
125
+ <% require_css 'that', 'another_one' -%>
126
+
127
+ # File: app/views/whatever/_part2.herb
128
+
129
+ <% require_js 'this', 'something_else' -%>
130
+ <% require_css 'that' -%>
131
+
132
+ # File: app/views/whatever/index.herb
133
+
134
+ <%= partial(:part1) %>
135
+ <%= partial(:part2) %>
136
+
137
+ # Will generate the following in the final page...
138
+ <html>
139
+ <head>
140
+ <script src="/javascripts/this.js" type="text/javascript"></script>
141
+ <script src="/javascripts/something_else.js" type="text/javascript"></script>
142
+ <link href="/stylesheets/that.css" media="all" rel="Stylesheet" type="text/css"/>
143
+ <link href="/stylesheets/another_one.css" media="all" rel="Stylesheet" type="text/css"/>
144
+ </head>
145
+ .
146
+ .
147
+ .
148
+ </html>
149
+
150
+ # my_action.herb has a call to require_css 'style'
151
+ # File: layout/application.html.erb
152
+ include_required_css
153
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
154
+
155
+ # my_action.herb has a call to require_css 'style', 'ie-specific'
156
+ # File: layout/application.html.erb
157
+ include_required_css
158
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
159
+ # <link href="/stylesheets/ie-specific.css" media="all" rel="Stylesheet" type="text/css"/>
160
+
161
+ # my_action.herb has a call to require_js 'jquery'
162
+ # File: layout/application.html.erb
163
+ include_required_js
164
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
165
+
166
+ # my_action.herb has a call to require_js 'jquery', 'effects', 'validation'
167
+ # File: layout/application.html.erb
168
+ include_required_js
169
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
170
+ # <script src="/javascripts/effects.js" type="text/javascript"></script>
171
+ # <script src="/javascripts/validation.js" type="text/javascript"></script>
172
+
173
+ <% require_css('style') %>
174
+ # A subsequent call to include_required_css will render...
175
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
176
+
177
+ <% require_css('style', 'ie-specific') %>
178
+ # A subsequent call to include_required_css will render...
179
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/>
180
+ # <link href="/stylesheets/ie-specific.css" media="all" rel="Stylesheet" type="text/css"/>
181
+
182
+ <% require_js 'jquery' %>
183
+ # A subsequent call to include_required_js will render...
184
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
185
+
186
+ <% require_js 'jquery', 'effects' %>
187
+ # A subsequent call to include_required_js will render...
188
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
189
+ # <script src="/javascripts/effects.js" type="text/javascript"></script>
190
+
191
+ css_include_tag and js_include_tag that do not use asset subdomains:
192
+
193
+ css_include_tag 'style'
194
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
195
+
196
+ css_include_tag 'style.css', 'layout'
197
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
198
+ # <link href="/stylesheets/layout.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
199
+
200
+ css_include_tag :menu
201
+ # => <link href="/stylesheets/menu.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
202
+
203
+ css_include_tag :style, :screen
204
+ # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
205
+ # <link href="/stylesheets/screen.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
206
+
207
+ css_include_tag :style, :media => :print
208
+ # => <link href="/stylesheets/style.css" media="print" rel="Stylesheet" type="text/css" charset="utf-8" />
209
+
210
+ css_include_tag :style, :charset => 'iso-8859-1'
211
+ # => <link href="/stylesheets/style.css" media="print" rel="Stylesheet" type="text/css" charset="iso-8859-1" />
212
+
213
+ js_include_tag 'jquery'
214
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
215
+
216
+ js_include_tag 'moofx.js', 'upload'
217
+ # => <script src="/javascripts/moofx.js" type="text/javascript"></script>
218
+ # <script src="/javascripts/upload.js" type="text/javascript"></script>
219
+
220
+ js_include_tag :effects
221
+ # => <script src="/javascripts/effects.js" type="text/javascript"></script>
222
+
223
+ js_include_tag :jquery, :validation
224
+ # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
225
+ # <script src="/javascripts/validation.js" type="text/javascript"></script>
226
+
227
+ Utility methods examples
228
+ ==========================
229
+
230
+ uniq_css_path("my")
231
+ #=> "http://assets2.my-awesome-domain.com/stylesheets/my.css"
232
+
233
+ uniq_css_path(["admin/secrets","home/signup"])
234
+ #=> ["http://assets2.my-awesome-domain.com/stylesheets/admin/secrets.css",
235
+ "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
236
+
237
+ uniq_path("/javascripts/my.js","/javascripts/my.css")
238
+ #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets1.my-awesome-domain.com/javascripts/my.css"]
239
+
240
+ uniq_path(["/javascripts/my.js","/stylesheets/my.css"])
241
+ #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets1.my-awesome-domain.com/stylesheets/my.css"]
242
+
243
+ uniq_path(%w(/javascripts/my.js /stylesheets/my.css))
244
+ #=> ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets1.my-awesome-domain.com/stylesheets/my.css"]
245
+
246
+ uniq_path('/stylesheets/somearbitrary.css')
247
+ #=> "http://assets3.my-awesome-domain.com/stylesheets/somearbitrary.css"
248
+
249
+ uniq_path('/images/hostsexypicture.jpg')
250
+ #=>"http://assets1.my-awesome-domain.com/images/hostsexypicture.jpg"
data/Rakefile CHANGED
@@ -1,28 +1,42 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
+ require "extlib"
4
+ require 'merb-core/tasks/merb_rake_helper'
5
+ require "spec/rake/spectask"
3
6
 
4
- PLUGIN = "merb-assets"
5
- NAME = "merb-assets"
6
- VERSION = "0.9.3"
7
- AUTHOR = "Ezra Zygmuntowicz"
8
- EMAIL = "ez@engineyard.com"
9
- HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-assets/"
10
- SUMMARY = "Merb plugin that provides the helpers for assets and asset bundling"
7
+ ##############################################################################
8
+ # Package && release
9
+ ##############################################################################
10
+ RUBY_FORGE_PROJECT = "merb"
11
+ PROJECT_URL = "http://merbivore.com"
12
+ PROJECT_SUMMARY = "Merb plugin that provides the helpers for assets and asset bundling"
13
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
14
+
15
+ GEM_AUTHOR = "Ezra Zygmuntowicz"
16
+ GEM_EMAIL = "ez@engineyard.com"
17
+
18
+ GEM_NAME = "merb-assets"
19
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
21
+
22
+ RELEASE_NAME = "REL #{GEM_VERSION}"
23
+
24
+ require "extlib/tasks/release"
11
25
 
12
26
  spec = Gem::Specification.new do |s|
13
- s.name = NAME
14
- s.version = VERSION
27
+ s.rubyforge_project = RUBY_FORGE_PROJECT
28
+ s.name = GEM_NAME
29
+ s.version = GEM_VERSION
15
30
  s.platform = Gem::Platform::RUBY
16
31
  s.has_rdoc = true
17
32
  s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
18
- s.summary = SUMMARY
19
- s.description = s.summary
20
- s.author = AUTHOR
21
- s.email = EMAIL
22
- s.homepage = HOMEPAGE
23
- s.add_dependency('merb-core', '>= 0.9.3')
33
+ s.summary = PROJECT_SUMMARY
34
+ s.description = PROJECT_DESCRIPTION
35
+ s.author = GEM_AUTHOR
36
+ s.email = GEM_EMAIL
37
+ s.homepage = PROJECT_URL
38
+ s.add_dependency('merb-core', '>= 0.9.4')
24
39
  s.require_path = 'lib'
25
- s.autorequire = PLUGIN
26
40
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
27
41
  end
28
42
 
@@ -30,15 +44,22 @@ Rake::GemPackageTask.new(spec) do |pkg|
30
44
  pkg.gem_spec = spec
31
45
  end
32
46
 
47
+ desc "Install the gem"
33
48
  task :install => [:package] do
34
- sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
49
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
35
50
  end
36
51
 
37
52
  namespace :jruby do
38
53
 
39
54
  desc "Run :package and install the resulting .gem with jruby"
40
55
  task :install => :package do
41
- sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
56
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
42
57
  end
43
-
58
+
59
+ end
60
+
61
+ desc "Run all specs"
62
+ Spec::Rake::SpecTask.new("specs") do |t|
63
+ t.spec_opts = ["--format", "specdoc", "--colour"]
64
+ t.spec_files = Dir["spec/**/*_spec.rb"].sort
44
65
  end
@@ -14,7 +14,6 @@ module Merb
14
14
 
15
15
  # Helpers for handling asset files.
16
16
  module AssetHelpers
17
- # :nodoc:
18
17
  ASSET_FILE_EXTENSIONS = {
19
18
  :javascript => ".js",
20
19
  :stylesheet => ".css"
@@ -43,9 +42,9 @@ module Merb
43
42
  def asset_path(asset_type, filename, local_path = false)
44
43
  filename = filename.to_s
45
44
  if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/ && filename.index('?').nil?
46
- filename << ASSET_FILE_EXTENSIONS[asset_type]
45
+ filename = "#{filename}#{ASSET_FILE_EXTENSIONS[asset_type]}" # don't modify receiver
47
46
  end
48
- if filename !~ %r{^https?://}
47
+ if filename !~ %r{^(/|https?://)}
49
48
  filename = "/#{asset_type}s/#{filename}"
50
49
  end
51
50
  if local_path
@@ -98,7 +97,7 @@ module Merb
98
97
  # An abstract class for bundling text assets into single files.
99
98
  class AbstractAssetBundler
100
99
 
101
- class_inheritable_array :cached_bundles
100
+ class_inheritable_accessor :cached_bundles
102
101
  self.cached_bundles ||= []
103
102
 
104
103
  class << self
@@ -13,7 +13,7 @@ module Merb
13
13
  #
14
14
  # ==== Returns
15
15
  # html<String>
16
- #
16
+ #
17
17
  # ==== Examples
18
18
  # We want all possible matches in the FileSys up to the action name
19
19
  # Given: controller_name = "namespace/controller"
@@ -24,7 +24,7 @@ module Merb
24
24
  # namespace/controller/action.(css|js)
25
25
  #
26
26
  def auto_link
27
- html = ""
27
+ html = ""
28
28
  prefix = ""
29
29
  (controller_name / action_name).split("/").each do |path|
30
30
  path = prefix + path
@@ -52,7 +52,7 @@ module Merb
52
52
  # name<~to_s>:: The text of the link.
53
53
  # url<~to_s>:: The URL to link to. Defaults to an empty string.
54
54
  # opts<Hash>:: Additional HTML options for the link.
55
- #
55
+ #
56
56
  # ==== Examples
57
57
  # link_to("The Merb home page", "http://www.merbivore.com/")
58
58
  # # => <a href="http://www.merbivore.com/">The Merb home page</a>
@@ -67,7 +67,7 @@ module Merb
67
67
  opts[:href] ||= url
68
68
  %{<a #{ opts.to_xml_attributes }>#{name}</a>}
69
69
  end
70
-
70
+
71
71
  # ==== Parameters
72
72
  # img<~to_s>:: The image path.
73
73
  # opts<Hash>:: Additional options for the image tag (see below).
@@ -77,31 +77,31 @@ module Merb
77
77
  # Sets the path prefix for the image. Defaults to "/images/" or whatever
78
78
  # is specified in Merb::Config. This is ignored if img is an absolute
79
79
  # path or full URL.
80
- #
80
+ #
81
81
  # All other options set HTML attributes on the tag.
82
82
  #
83
83
  # ==== Examples
84
- # image_tag('foo.gif')
84
+ # image_tag('foo.gif')
85
85
  # # => <img src='/images/foo.gif' />
86
- #
87
- # image_tag('foo.gif', :class => 'bar')
86
+ #
87
+ # image_tag('foo.gif', :class => 'bar')
88
88
  # # => <img src='/images/foo.gif' class='bar' />
89
89
  #
90
- # image_tag('foo.gif', :path => '/files/')
90
+ # image_tag('foo.gif', :path => '/files/')
91
91
  # # => <img src='/files/foo.gif' />
92
92
  #
93
93
  # image_tag('http://test.com/foo.gif')
94
94
  # # => <img src="http://test.com/foo.gif">
95
95
  #
96
96
  # image_tag('charts', :path => '/dynamic/')
97
- # or
97
+ # or
98
98
  # image_tag('/dynamic/charts')
99
99
  # # => <img src="/dynamic/charts">
100
100
  def image_tag(img, opts={})
101
101
  if img[0].chr == '/'
102
102
  opts[:src] = img
103
103
  else
104
- opts[:path] ||=
104
+ opts[:path] ||=
105
105
  if img =~ %r{^https?://}
106
106
  ''
107
107
  else
@@ -113,12 +113,12 @@ module Merb
113
113
  end
114
114
  opts[:src] ||= opts.delete(:path) + img
115
115
  end
116
- %{<img #{ opts.to_xml_attributes } />}
116
+ %{<img #{ opts.to_xml_attributes } />}
117
117
  end
118
118
 
119
119
  # :section: JavaScript related functions
120
120
  #
121
-
121
+
122
122
  # ==== Parameters
123
123
  # javascript<String>:: Text to escape for use in JavaScript.
124
124
  #
@@ -131,21 +131,7 @@ module Merb
131
131
  def escape_js(javascript)
132
132
  (javascript || '').gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
133
133
  end
134
-
135
- # ==== Parameters
136
- # name<~to_s>:: The text in the link.
137
- # function<~to_s>:: The onClick event in JavaScript.
138
- #
139
- # ==== Examples
140
- # link_to_function('Click me', "alert('hi!')")
141
- # # => <a href="#" onclick="alert('hi!'); return false;">Click me</a>
142
- #
143
- # link_to_function('Add to cart', "item_total += 1; alert('Item added!');")
144
- # # => <a href="#" onclick="item_total += 1; alert('Item added!'); return false;">Add to cart</a>
145
- def link_to_function(name, function)
146
- %{<a href="#" onclick="#{function.chomp(";")}; return false;">#{name}</a>}
147
- end
148
-
134
+
149
135
  # ==== Parameters
150
136
  # data<Object>::
151
137
  # Object to translate into JSON. If the object does not respond to
@@ -164,7 +150,7 @@ module Merb
164
150
  data.inspect.to_json
165
151
  end
166
152
  end
167
-
153
+
168
154
  # :section: External JavaScript and Stylesheets
169
155
  #
170
156
  # You can use require_js(:prototype) or require_css(:shinystyles)
@@ -185,12 +171,12 @@ module Merb
185
171
  # <%= catch_content :layout %>
186
172
  # </body>
187
173
  # </html>
188
- #
174
+ #
189
175
  # # File: app/views/whatever/_part1.herb
190
176
  #
191
177
  # <% require_js 'this' -%>
192
178
  # <% require_css 'that', 'another_one' -%>
193
- #
179
+ #
194
180
  # # File: app/views/whatever/_part2.herb
195
181
  #
196
182
  # <% require_js 'this', 'something_else' -%>
@@ -215,78 +201,78 @@ module Merb
215
201
  # </html>
216
202
  #
217
203
  # See each method's documentation for more information.
218
-
204
+
219
205
  # :section: Bundling Asset Files
220
- #
206
+ #
221
207
  # The key to making a fast web application is to reduce both the amount of
222
208
  # data transfered and the number of client-server interactions. While having
223
209
  # many small, module Javascript or stylesheet files aids in the development
224
210
  # process, your web application will benefit from bundling those assets in
225
211
  # the production environment.
226
- #
212
+ #
227
213
  # An asset bundle is a set of asset files which are combined into a single
228
214
  # file. This reduces the number of requests required to render a page, and
229
215
  # can reduce the amount of data transfer required if you're using gzip
230
216
  # encoding.
231
- #
217
+ #
232
218
  # Asset bundling is always enabled in production mode, and can be optionally
233
219
  # enabled in all environments by setting the <tt>:bundle_assets</tt> value
234
220
  # in <tt>config/merb.yml</tt> to +true+.
235
- #
221
+ #
236
222
  # ==== Examples
237
- #
223
+ #
238
224
  # In the development environment, this:
239
- #
225
+ #
240
226
  # js_include_tag :prototype, :lowpro, :bundle => true
241
- #
227
+ #
242
228
  # will produce two <script> elements. In the production mode, however, the
243
229
  # two files will be concatenated in the order given into a single file,
244
230
  # <tt>all.js</tt>, in the <tt>public/javascripts</tt> directory.
245
- #
231
+ #
246
232
  # To specify a different bundle name:
247
- #
233
+ #
248
234
  # css_include_tag :typography, :whitespace, :bundle => :base
249
235
  # css_include_tag :header, :footer, :bundle => "content"
250
236
  # css_include_tag :lightbox, :images, :bundle => "lb.css"
251
- #
237
+ #
252
238
  # (<tt>base.css</tt>, <tt>content.css</tt>, and <tt>lb.css</tt> will all be
253
239
  # created in the <tt>public/stylesheets</tt> directory.)
254
- #
240
+ #
255
241
  # == Callbacks
256
- #
242
+ #
257
243
  # To use a Javascript or CSS compressor, like JSMin or YUI Compressor:
258
- #
244
+ #
259
245
  # Merb::Assets::JavascriptAssetBundler.add_callback do |filename|
260
246
  # system("/usr/local/bin/yui-compress #{filename}")
261
247
  # end
262
- #
248
+ #
263
249
  # Merb::Assets::StylesheetAssetBundler.add_callback do |filename|
264
250
  # system("/usr/local/bin/css-min #{filename}")
265
251
  # end
266
- #
252
+ #
267
253
  # These blocks will be run after a bundle is created.
268
- #
254
+ #
269
255
  # == Bundling Required Assets
270
- #
256
+ #
271
257
  # Combining the +require_css+ and +require_js+ helpers with bundling can be
272
258
  # problematic. You may want to separate out the common assets for your
273
259
  # application -- Javascript frameworks, common CSS, etc. -- and bundle those
274
260
  # in a "base" bundle. Then, for each section of your site, bundle the
275
261
  # required assets into a section-specific bundle.
276
- #
262
+ #
277
263
  # <b>N.B.: If you bundle an inconsistent set of assets with the same name,
278
264
  # you will have inconsistent results. Be thorough and test often.</b>
279
- #
265
+ #
280
266
  # ==== Example
281
- #
267
+ #
282
268
  # In your application layout:
283
- #
269
+ #
284
270
  # js_include_tag :prototype, :lowpro, :bundle => :base
285
- #
271
+ #
286
272
  # In your controller layout:
287
- #
273
+ #
288
274
  # require_js :bundle => :posts
289
-
275
+
290
276
  # The require_js method can be used to require any JavaScript file anywhere
291
277
  # in your templates. Regardless of how many times a single script is
292
278
  # included with require_js, Merb will only include it once in the header.
@@ -309,6 +295,14 @@ module Merb
309
295
  @required_js << js
310
296
  end
311
297
 
298
+ # All javascript files to include, without duplicates.
299
+ #
300
+ # ==== Parameters
301
+ # options<Hash>:: Default options to pass to js_include_tag.
302
+ def required_js(options = {})
303
+ extract_required_files(@required_js, options)
304
+ end
305
+
312
306
  # The require_css method can be used to require any CSS file anywhere in
313
307
  # your templates. Regardless of how many times a single stylesheet is
314
308
  # included with require_css, Merb will only include it once in the header.
@@ -331,17 +325,25 @@ module Merb
331
325
  @required_css << css
332
326
  end
333
327
 
328
+ # All css files to include, without duplicates.
329
+ #
330
+ # ==== Parameters
331
+ # options<Hash>:: Default options to pass to css_include_tag.
332
+ def required_css(options = {})
333
+ extract_required_files(@required_css, options)
334
+ end
335
+
334
336
  # A method used in the layout of an application to create +<script>+ tags
335
337
  # to include JavaScripts required in in templates and subtemplates using
336
338
  # require_js.
337
- #
339
+ #
338
340
  # ==== Parameters
339
341
  # options<Hash>:: Options to pass to js_include_tag.
340
342
  #
341
343
  # ==== Options
342
344
  # :bundle<~to_s>::
343
345
  # The name of the bundle the scripts should be combined into.
344
- #
346
+ #
345
347
  # ==== Returns
346
348
  # String:: The JavaScript tag.
347
349
  #
@@ -359,23 +361,16 @@ module Merb
359
361
  # # <script src="/javascripts/validation.js" type="text/javascript"></script>
360
362
  #
361
363
  def include_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
364
+ required_js(options).map { |req_js| js_include_tag(*req_js) }.join
370
365
  end
371
-
366
+
372
367
  # A method used in the layout of an application to create +<link>+ tags for
373
368
  # CSS stylesheets required in in templates and subtemplates using
374
369
  # require_css.
375
- #
370
+ #
376
371
  # ==== Parameters
377
372
  # options<Hash>:: Options to pass to css_include_tag.
378
- #
373
+ #
379
374
  # ==== Returns
380
375
  # String:: The CSS tag.
381
376
  #
@@ -384,7 +379,7 @@ module Merb
384
379
  # The name of the bundle the stylesheets should be combined into.
385
380
  # :media<~to_s>::
386
381
  # The media attribute for the generated link element. Defaults to :all.
387
- #
382
+ #
388
383
  # ==== Examples
389
384
  # # my_action.herb has a call to require_css 'style'
390
385
  # # File: layout/application.html.erb
@@ -398,16 +393,9 @@ module Merb
398
393
  # # <link href="/stylesheets/ie-specific.css" media="all" rel="Stylesheet" type="text/css"/>
399
394
  #
400
395
  def include_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
396
+ required_css(options).map { |req_js| css_include_tag(*req_js) }.join
409
397
  end
410
-
398
+
411
399
  # ==== Parameters
412
400
  # *scripts::
413
401
  # The scripts to include. If the last element is a Hash, it will be used
@@ -439,7 +427,7 @@ module Merb
439
427
  def js_include_tag(*scripts)
440
428
  options = scripts.last.is_a?(Hash) ? scripts.pop : {}
441
429
  return nil if scripts.empty?
442
-
430
+
443
431
  if (bundle_name = options[:bundle]) && Merb::Assets.bundle? && scripts.size > 1
444
432
  bundler = Merb::Assets::JavascriptAssetBundler.new(bundle_name, *scripts)
445
433
  bundled_asset = bundler.bundle!
@@ -458,7 +446,7 @@ module Merb
458
446
 
459
447
  return tags
460
448
  end
461
-
449
+
462
450
  # ==== Parameters
463
451
  # *stylesheets::
464
452
  # The stylesheets to include. If the last element is a Hash, it will be
@@ -488,7 +476,7 @@ module Merb
488
476
  # css_include_tag :style, :screen
489
477
  # # => <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
490
478
  # # <link href="/stylesheets/screen.css" media="all" rel="Stylesheet" type="text/css" charset="utf-8" />
491
- #
479
+ #
492
480
  # css_include_tag :style, :media => :print
493
481
  # # => <link href="/stylesheets/style.css" media="print" rel="Stylesheet" type="text/css" charset="utf-8" />
494
482
  #
@@ -497,7 +485,7 @@ module Merb
497
485
  def css_include_tag(*stylesheets)
498
486
  options = stylesheets.last.is_a?(Hash) ? stylesheets.pop : {}
499
487
  return nil if stylesheets.empty?
500
-
488
+
501
489
  if (bundle_name = options[:bundle]) && Merb::Assets.bundle? && stylesheets.size > 1
502
490
  bundler = Merb::Assets::StylesheetAssetBundler.new(bundle_name, *stylesheets)
503
491
  bundled_asset = bundler.bundle!
@@ -519,7 +507,7 @@ module Merb
519
507
 
520
508
  return tags
521
509
  end
522
-
510
+
523
511
  # ==== Parameters
524
512
  # *assets::
525
513
  # The assets to include. These should be the full paths to any static served file
@@ -542,14 +530,14 @@ module Merb
542
530
  #
543
531
  # uniq_path('/images/hostsexypicture.jpg')
544
532
  # #=>"http://assets1.my-awesome-domain.com/images/hostsexypicture.jpg"
545
- def uniq_path(*assets)
533
+ def uniq_path(*assets)
546
534
  paths = []
547
535
  assets.collect.flatten.each do |filename|
548
536
  paths.push(Merb::Assets::UniqueAssetPath.build(filename))
549
537
  end
550
538
  paths.length > 1 ? paths : paths.first
551
539
  end
552
-
540
+
553
541
  # ==== Parameters
554
542
  # *assets::
555
543
  # Creates unique paths for javascript files (prepends "/javascripts" and appends ".js")
@@ -562,7 +550,7 @@ module Merb
562
550
  # #=> "http://assets2.my-awesome-domain.com/javascripts/my.js"
563
551
  #
564
552
  # uniq_js_path(["admin/secrets","home/signup"])
565
- # #=> ["http://assets2.my-awesome-domain.com/javascripts/admin/secrets.js",
553
+ # #=> ["http://assets2.my-awesome-domain.com/javascripts/admin/secrets.js",
566
554
  # "http://assets1.my-awesome-domain.com/javascripts/home/signup.js"]
567
555
  def uniq_js_path(*assets)
568
556
  paths = []
@@ -571,7 +559,7 @@ module Merb
571
559
  end
572
560
  paths.length > 1 ? paths : paths.first
573
561
  end
574
-
562
+
575
563
  # ==== Parameters
576
564
  # *assets::
577
565
  # Creates unique paths for stylesheet files (prepends "/stylesheets" and appends ".css")
@@ -584,7 +572,7 @@ module Merb
584
572
  # #=> "http://assets2.my-awesome-domain.com/stylesheets/my.css"
585
573
  #
586
574
  # uniq_css_path(["admin/secrets","home/signup"])
587
- # #=> ["http://assets2.my-awesome-domain.com/stylesheets/admin/secrets.css",
575
+ # #=> ["http://assets2.my-awesome-domain.com/stylesheets/admin/secrets.css",
588
576
  # "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
589
577
  def uniq_css_path(*assets)
590
578
  paths = []
@@ -593,7 +581,7 @@ module Merb
593
581
  end
594
582
  paths.length > 1 ? paths : paths.first
595
583
  end
596
-
584
+
597
585
  # ==== Parameters
598
586
  # *assets::
599
587
  # As js_include_tag but has unique path
@@ -607,7 +595,7 @@ module Merb
607
595
  def uniq_js_tag(*assets)
608
596
  js_include_tag(*uniq_js_path(assets))
609
597
  end
610
-
598
+
611
599
  # ==== Parameters
612
600
  # *assets::
613
601
  # As uniq_css_tag but has unique path
@@ -621,5 +609,27 @@ module Merb
621
609
  def uniq_css_tag(*assets)
622
610
  css_include_tag(*uniq_css_path(assets))
623
611
  end
612
+
613
+ private
614
+
615
+ # Helper method to filter out duplicate files.
616
+ #
617
+ # ==== Parameters
618
+ # options<Hash>:: Options to pass to include tag methods.
619
+ def extract_required_files(files, options = {})
620
+ return [] if files.nil? || files.empty?
621
+ seen = []
622
+ files.inject([]) do |extracted, req_js|
623
+ include_files, include_options = if req_js.last.is_a?(Hash)
624
+ [req_js[0..-2], options.merge(req_js.last)]
625
+ else
626
+ [req_js, options]
627
+ end
628
+ seen += (includes = include_files - seen)
629
+ extracted << (includes + [include_options]) unless includes.empty?
630
+ extracted
631
+ end
632
+ end
633
+
624
634
  end
625
635
  end
@@ -3,57 +3,57 @@ include Merb::AssetsMixin
3
3
 
4
4
  describe "Accessing Assets" do
5
5
  it "should create link to name with absolute url" do
6
- link_to("The Merb home page", "http://www.merbivore.com/").should ==
6
+ link_to("The Merb home page", "http://www.merbivore.com/").should ==
7
7
  "<a href=\"http://www.merbivore.com/\">The Merb home page</a>"
8
8
  end
9
-
9
+
10
10
  it "should create link to name with relative url" do
11
- link_to("The Entry Title", "/blog/show/13").should ==
11
+ link_to("The Entry Title", "/blog/show/13").should ==
12
12
  "<a href=\"/blog/show/13\">The Entry Title</a>"
13
13
  end
14
-
14
+
15
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>"
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
18
  end
19
-
19
+
20
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 ==
21
+ link_to("The Foo home page", "http://not.foo.example.com/", :href => "http://foo.example.com").should ==
22
22
  "<a href=\"http://foo.example.com\">The Foo home page</a>"
23
23
  end
24
-
24
+
25
25
  it "should create image tag with absolute url" do
26
26
  image_tag('http://example.com/foo.gif').should ==
27
27
  "<img src=\"http://example.com/foo.gif\" />"
28
28
  end
29
-
29
+
30
30
  it "should create image tag with relative url" do
31
31
  image_tag('foo.gif').should ==
32
32
  "<img src=\"/images/foo.gif\" />"
33
33
  end
34
-
34
+
35
35
  it "should create image tag with class" do
36
36
  result = image_tag('foo.gif', :class => 'bar')
37
37
  result.should match(%r{<img .*? />})
38
38
  result.should match(%r{src="/images/foo.gif"})
39
39
  result.should match(/class="bar"/)
40
40
  end
41
-
41
+
42
42
  it "should create image tag with specified path" do
43
43
  image_tag('foo.gif', :path => '/files/').should ==
44
44
  "<img src=\"/files/foo.gif\" />"
45
45
  end
46
-
46
+
47
47
  it "should create image tag without extension" do
48
48
  image_tag('/dynamic/charts').should ==
49
49
  "<img src=\"/dynamic/charts\" />"
50
50
  end
51
-
51
+
52
52
  it "should create image tag without extension and with specified path" do
53
53
  image_tag('charts', :path => '/dynamic/').should ==
54
54
  "<img src=\"/dynamic/charts\" />"
55
55
  end
56
-
56
+
57
57
  end
58
58
 
59
59
  describe "JavaScript related functions" do
@@ -61,27 +61,17 @@ describe "JavaScript related functions" do
61
61
  escape_js("'Lorem ipsum!' -- Some guy").should ==
62
62
  "\\'Lorem ipsum!\\' -- Some guy"
63
63
  end
64
-
64
+
65
65
  it "should escape js having new lines" do
66
66
  escape_js("Please keep text\nlines as skinny\nas possible.").should ==
67
67
  "Please keep text\\nlines as skinny\\nas possible."
68
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
-
69
+
80
70
  it "should convert objects that respond to to_json to json" do
81
71
  js({'user' => 'Lewis', 'page' => 'home'}).should ==
82
72
  "{\"user\":\"Lewis\",\"page\":\"home\"}"
83
73
  end
84
-
74
+
85
75
  it "should convert objects using inspect that don't respond to_json to json" do
86
76
  js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ]).should ==
87
77
  "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
@@ -90,55 +80,82 @@ end
90
80
 
91
81
  describe "External JavaScript and Stylesheets" do
92
82
  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
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
98
87
  end
99
-
88
+
100
89
  it "should require a css file only once" do
101
- require_css('style')
102
- require_css('style', 'ie-specific')
90
+ require_css :style
91
+ require_css :style, 'ie-specific'
103
92
 
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
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
106
95
  end
107
-
96
+
108
97
  it "should require included js" do
109
98
  require_js 'jquery', 'effects', 'validation'
110
99
  result = include_required_js
111
100
  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})
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"})
115
104
  end
116
-
105
+
117
106
  it "should require included css" do
118
107
  require_css 'style', 'ie-specific'
119
108
  result = include_required_css
120
109
  result.scan(/<link/).should have(2).things
121
- result.should match(%r{/stylesheets/style.css})
122
- result.should match(%r{/stylesheets/ie-specific.css})
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, {}]]
123
134
  end
124
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
+
125
142
  it "should create a js include tag with the extension specified" do
126
143
  js_include_tag('jquery.js').should ==
127
144
  "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
128
145
  end
129
-
146
+
130
147
  it "should create a js include tag and and the extension" do
131
148
  js_include_tag('jquery').should ==
132
149
  "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
133
150
  end
134
-
151
+
135
152
  it "should create a js include tag for multiple includes" do
136
153
  result = js_include_tag('jquery.js', :effects)
137
154
  result.scan(/<script/).should have(2).things
138
155
  result.should match(%r{/javascripts/jquery.js})
139
156
  result.should match(%r{/javascripts/effects.js})
140
157
  end
141
-
158
+
142
159
  it "should create a css include tag with the extension specified" do
143
160
  result = css_include_tag('style.css')
144
161
  result.should match(%r{<link (.*?) />})
@@ -148,7 +165,7 @@ describe "External JavaScript and Stylesheets" do
148
165
  result.should match(%r{rel="Stylesheet"})
149
166
  result.should match(%r{media="all"})
150
167
  end
151
-
168
+
152
169
  it "should create a css include tag and add the extension" do
153
170
  result = css_include_tag('style')
154
171
  result.should match(%r{<link (.*?) />})
@@ -158,69 +175,69 @@ describe "External JavaScript and Stylesheets" do
158
175
  result.should match(%r{rel="Stylesheet"})
159
176
  result.should match(%r{media="all"})
160
177
  end
161
-
178
+
162
179
  it "should create a css include tag for multiple includes" do
163
180
  result = css_include_tag('style.css', :layout)
164
181
  result.scan(/<link/).should have(2).things
165
182
  result.should match(%r{/stylesheets/style.css})
166
183
  result.should match(%r{/stylesheets/layout.css})
167
184
  end
168
-
185
+
169
186
  it "should create a css include tag with the specified media" do
170
187
  css_include_tag('style', :media => :print).should match(%r{media="print"})
171
188
  end
172
-
189
+
173
190
  it "should create a css include tag with the specified charset" do
174
191
  css_include_tag('style', :charset => 'iso-8859-1').should match(%r{charset="iso-8859-1"})
175
192
  end
176
-
193
+
177
194
  it "should return a uniq path for a single asset" do
178
- uniq_path("/javascripts/my.js").should ==
195
+ uniq_path("/javascripts/my.js").should ==
179
196
  "http://assets2.my-awesome-domain.com/javascripts/my.js"
180
197
  end
181
-
198
+
182
199
  it "should return a uniq path for multiple assets" do
183
- uniq_path("/javascripts/my.js","/javascripts/my.css").should ==
200
+ uniq_path("/javascripts/my.js","/javascripts/my.css").should ==
184
201
  ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
185
202
  end
186
-
203
+
187
204
  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 ==
205
+ uniq_path(["/javascripts/my.js","/javascripts/my.css"]).should ==
189
206
  ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
190
207
  end
191
-
208
+
192
209
  it "should return a uniq js path for a single js file" do
193
- uniq_js_path("my").should ==
210
+ uniq_js_path("my").should ==
194
211
  "http://assets2.my-awesome-domain.com/javascripts/my.js"
195
212
  end
196
-
213
+
197
214
  it "should return a uniq js path for multiple js files" do
198
- uniq_js_path(["admin/secrets","home/signup"]).should ==
215
+ uniq_js_path(["admin/secrets","home/signup"]).should ==
199
216
  ["http://assets1.my-awesome-domain.com/javascripts/admin/secrets.js", "http://assets2.my-awesome-domain.com/javascripts/home/signup.js"]
200
217
  end
201
-
218
+
202
219
  it "should return a uniq css path for a single css file" do
203
- uniq_css_path("my").should ==
220
+ uniq_css_path("my").should ==
204
221
  "http://assets1.my-awesome-domain.com/stylesheets/my.css"
205
222
  end
206
-
223
+
207
224
  it "should return a uniq css path for multiple css files" do
208
- uniq_css_path(["admin/secrets","home/signup"]).should ==
225
+ uniq_css_path(["admin/secrets","home/signup"]).should ==
209
226
  ["http://assets4.my-awesome-domain.com/stylesheets/admin/secrets.css", "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
210
227
  end
211
-
228
+
212
229
  it "should create a uniq js tag for a single js file" do
213
230
  uniq_js_tag("my").should ==
214
231
  "<script type=\"text/javascript\" src=\"http://assets2.my-awesome-domain.com/javascripts/my.js\"></script>"
215
232
  end
216
-
233
+
217
234
  it "should create a uniq js tag for each js file specified" do
218
235
  result = uniq_js_tag("jquery.js", :effects)
219
236
  result.scan(/<script/).should have(2).things
220
237
  result.should match(%r{/javascripts/jquery.js})
221
238
  result.should match(%r{/javascripts/effects.js})
222
239
  end
223
-
240
+
224
241
  it "should create a uniq css tag for a single css file" do
225
242
  result = uniq_css_tag("my")
226
243
  result.should match(%r{<link (.*?) />})
@@ -230,7 +247,7 @@ describe "External JavaScript and Stylesheets" do
230
247
  result.should match(%r{rel="Stylesheet"})
231
248
  result.should match(%r{media="all"})
232
249
  end
233
-
250
+
234
251
  it "should create a uniq css tag for each css file specified" do
235
252
  result = uniq_css_tag("style.css", :layout)
236
253
  result.scan(/<link/).should have(2).things
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,11 @@ require "spec"
8
8
 
9
9
  Merb.start :environment => 'test'
10
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
+
11
16
  Spec::Runner.configure do |config|
12
17
  config.include Merb::Test::RequestHelper
13
18
  end
metadata CHANGED
@@ -1,25 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
8
- autorequire: merb-assets
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-04 00:00:00 -05:00
12
+ date: 2008-08-13 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: merb-core
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.9.3
23
+ version: 0.9.4
23
24
  version:
24
25
  description: Merb plugin that provides the helpers for assets and asset bundling
25
26
  email: ez@engineyard.com
@@ -43,7 +44,7 @@ files:
43
44
  - spec/merb-assets_spec.rb
44
45
  - spec/spec_helper.rb
45
46
  has_rdoc: true
46
- homepage: http://merb-plugins.rubyforge.org/merb-assets/
47
+ homepage: http://merbivore.com
47
48
  post_install_message:
48
49
  rdoc_options: []
49
50
 
@@ -63,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  version:
64
65
  requirements: []
65
66
 
66
- rubyforge_project:
67
- rubygems_version: 1.0.1
67
+ rubyforge_project: merb
68
+ rubygems_version: 1.2.0
68
69
  signing_key:
69
70
  specification_version: 2
70
71
  summary: Merb plugin that provides the helpers for assets and asset bundling