dynamic_assets 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,25 +2,27 @@
2
2
  module DynamicAssetsHelpers
3
3
 
4
4
  def stylesheet_asset_tag(group_key, options = {})
5
+ html_options, path_options = separate_options(options)
5
6
  DynamicAssets::Manager.asset_references_for_group_key(:stylesheets, group_key).map do |asset_ref|
6
7
 
7
8
  tag :link, {
8
9
  :type => "text/css",
9
10
  :rel => "stylesheet",
10
11
  :media => "screen",
11
- :href => asset_url(asset_ref, options.delete(:token))
12
- }.merge!(options)
12
+ :href => asset_url(asset_ref, path_options)
13
+ }.merge!(html_options)
13
14
 
14
15
  end.join.html_safe
15
16
  end
16
17
 
17
18
  def javascript_asset_tag(group_key, options = {})
19
+ html_options, path_options = separate_options(options)
18
20
  DynamicAssets::Manager.asset_references_for_group_key(:javascripts, group_key).map do |asset_ref|
19
21
 
20
22
  content_tag :script, "", {
21
23
  :type => "text/javascript",
22
- :src => asset_url(asset_ref, options.delete(:token))
23
- }.merge!(options)
24
+ :src => asset_url(asset_ref, path_options)
25
+ }.merge!(html_options)
24
26
 
25
27
  end.join.html_safe
26
28
  end
@@ -28,26 +30,31 @@ module DynamicAssetsHelpers
28
30
 
29
31
  protected
30
32
 
31
- def asset_path(asset_ref, token = nil)
32
- path_args = []
33
- path_args << asset_ref.name
34
-
35
- signature = asset_ref.signature DynamicAssets::ViewContext.get(controller)
36
- path_args << { :signature => signature, :token => token } if signature.present?
33
+ def asset_path(asset_ref, options = {})
34
+ # Omit signature if we see an explicit :signature => false option.
35
+ signature = (options[:signature] == false) ? nil :
36
+ asset_ref.signature(DynamicAssets::ViewContext.get(controller))
37
+ options = options.reverse_merge :name => asset_ref.name, :signature => signature
37
38
 
38
39
  case asset_ref
39
- when DynamicAssets::StylesheetReference then stylesheet_asset_path *path_args
40
- when DynamicAssets::JavascriptReference then javascript_asset_path *path_args
40
+ when DynamicAssets::StylesheetReference then stylesheet_asset_path options
41
+ when DynamicAssets::JavascriptReference then javascript_asset_path options
41
42
  else raise "Unknown asset type: #{asset_ref}"
42
43
  end
43
44
  end
44
45
 
45
- def asset_url(asset_ref, token = nil)
46
- path = asset_path asset_ref, token
46
+ def asset_url(asset_ref, options = {})
47
+ path = asset_path asset_ref, options
47
48
  path = "/" + path unless path[0,1] == "/"
48
49
 
49
- host = compute_asset_host path
50
- host ? "#{host}#{path}" : path
50
+ host = options[:host].presence || compute_asset_host(path)
51
+
52
+ # Like Rails, add the protocol if the host lacks it.
53
+ if controller.respond_to?(:request) && host.present? && !is_uri?(host)
54
+ host = "#{controller.request.protocol}#{host}"
55
+ end
56
+
57
+ host.present? ? "#{host}#{path}" : path
51
58
  end
52
59
 
53
60
  # Extracted from Rails' AssetTagHelper, where it's private
@@ -66,4 +73,17 @@ protected
66
73
  end
67
74
  end
68
75
  end
76
+
77
+ def is_uri?(path)
78
+ path =~ %r{^[-a-z]+://|^cid:}
79
+ end
80
+
81
+ def separate_options(options)
82
+ path_options = {}
83
+ [:token, :signature, :name, :host, :protocol, :port].each do |key|
84
+ path_options[key] = options.delete(key) if options.has_key?(key)
85
+ end
86
+ [options, path_options]
87
+ end
88
+
69
89
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynamic_assets
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.2
5
+ version: 0.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Davis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-19 00:00:00 -05:00
13
+ date: 2011-06-20 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- hash: -36479005061281220
131
+ hash: -3479676629565861754
132
132
  segments:
133
133
  - 0
134
134
  version: "0"