sprockets-rails 2.3.2 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{LICENSE → MIT-LICENSE} +1 -1
- data/README.md +70 -37
- data/lib/sprockets/rails/asset_url_processor.rb +17 -0
- data/lib/sprockets/rails/context.rb +48 -0
- data/lib/sprockets/rails/helper.rb +271 -128
- data/lib/sprockets/rails/quiet_assets.rb +18 -0
- data/lib/sprockets/rails/route_wrapper.rb +23 -0
- data/lib/sprockets/rails/sourcemapping_url_processor.rb +54 -0
- data/lib/sprockets/rails/task.rb +10 -15
- data/lib/sprockets/rails/utils.rb +11 -0
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +187 -75
- metadata +40 -43
- data/lib/sprockets/rails/legacy_asset_tag_helper.rb +0 -32
- data/lib/sprockets/rails/legacy_asset_url_helper.rb +0 -133
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
|
3
|
-
module Sprockets
|
4
|
-
module Rails
|
5
|
-
# Backports of AssetUrlHelper methods for Rails 2.x and 3.x.
|
6
|
-
module LegacyAssetUrlHelper
|
7
|
-
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
|
8
|
-
|
9
|
-
def asset_path(source, options = {})
|
10
|
-
source = source.to_s
|
11
|
-
return "" unless source.present?
|
12
|
-
return source if source =~ URI_REGEXP
|
13
|
-
|
14
|
-
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')
|
15
|
-
|
16
|
-
if extname = compute_asset_extname(source, options)
|
17
|
-
source = "#{source}#{extname}"
|
18
|
-
end
|
19
|
-
|
20
|
-
if source[0] != ?/
|
21
|
-
source = compute_asset_path(source, options)
|
22
|
-
end
|
23
|
-
|
24
|
-
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
|
25
|
-
if relative_url_root
|
26
|
-
source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
|
27
|
-
end
|
28
|
-
|
29
|
-
if host = compute_asset_host(source, options)
|
30
|
-
source = "#{host}#{source}"
|
31
|
-
end
|
32
|
-
|
33
|
-
"#{source}#{tail}"
|
34
|
-
end
|
35
|
-
alias_method :path_to_asset, :asset_path
|
36
|
-
|
37
|
-
def asset_url(source, options = {})
|
38
|
-
path_to_asset(source, options.merge(:protocol => :request))
|
39
|
-
end
|
40
|
-
|
41
|
-
ASSET_EXTENSIONS = {
|
42
|
-
:javascript => '.js',
|
43
|
-
:stylesheet => '.css'
|
44
|
-
}
|
45
|
-
|
46
|
-
def compute_asset_extname(source, options = {})
|
47
|
-
return if options[:extname] == false
|
48
|
-
extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
|
49
|
-
extname if extname && File.extname(source) != extname
|
50
|
-
end
|
51
|
-
|
52
|
-
ASSET_PUBLIC_DIRECTORIES = {
|
53
|
-
:audio => '/audios',
|
54
|
-
:font => '/fonts',
|
55
|
-
:image => '/images',
|
56
|
-
:javascript => '/javascripts',
|
57
|
-
:stylesheet => '/stylesheets',
|
58
|
-
:video => '/videos'
|
59
|
-
}
|
60
|
-
|
61
|
-
def compute_asset_path(source, options = {})
|
62
|
-
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
|
63
|
-
File.join(dir, source)
|
64
|
-
end
|
65
|
-
|
66
|
-
def compute_asset_host(source = "", options = {})
|
67
|
-
request = self.request if respond_to?(:request)
|
68
|
-
|
69
|
-
if defined? config
|
70
|
-
host = config.asset_host
|
71
|
-
elsif defined? ActionController::Base.asset_host
|
72
|
-
host = ActionController::Base.asset_host
|
73
|
-
end
|
74
|
-
|
75
|
-
host ||= request.base_url if request && options[:protocol] == :request
|
76
|
-
return unless host
|
77
|
-
|
78
|
-
if host.respond_to?(:call)
|
79
|
-
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
|
80
|
-
args = [source]
|
81
|
-
args << request if request && (arity > 1 || arity < 0)
|
82
|
-
host = host.call(*args)
|
83
|
-
elsif host =~ /%d/
|
84
|
-
host = host % (Zlib.crc32(source) % 4)
|
85
|
-
end
|
86
|
-
|
87
|
-
if host =~ URI_REGEXP
|
88
|
-
host
|
89
|
-
else
|
90
|
-
protocol = options[:protocol] || (request ? :request : :relative)
|
91
|
-
case protocol
|
92
|
-
when :relative
|
93
|
-
"//#{host}"
|
94
|
-
when :request
|
95
|
-
"#{request.protocol}#{host}"
|
96
|
-
else
|
97
|
-
"#{protocol}://#{host}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def javascript_path(source, options = {})
|
103
|
-
path_to_asset(source, {:type => :javascript}.merge(options))
|
104
|
-
end
|
105
|
-
alias_method :path_to_javascript, :javascript_path
|
106
|
-
|
107
|
-
def stylesheet_path(source, options = {})
|
108
|
-
path_to_asset(source, {:type => :stylesheet}.merge(options))
|
109
|
-
end
|
110
|
-
alias_method :path_to_stylesheet, :stylesheet_path
|
111
|
-
|
112
|
-
def image_path(source, options = {})
|
113
|
-
path_to_asset(source, {:type => :image}.merge(options))
|
114
|
-
end
|
115
|
-
alias_method :path_to_image, :image_path
|
116
|
-
|
117
|
-
def video_path(source, options = {})
|
118
|
-
path_to_asset(source, {:type => :video}.merge(options))
|
119
|
-
end
|
120
|
-
alias_method :path_to_video, :video_path
|
121
|
-
|
122
|
-
def audio_path(source, options = {})
|
123
|
-
path_to_asset(source, {:type => :audio}.merge(options))
|
124
|
-
end
|
125
|
-
alias_method :path_to_audio, :audio_path
|
126
|
-
|
127
|
-
def font_path(source, options = {})
|
128
|
-
path_to_asset(source, {:type => :font}.merge(options))
|
129
|
-
end
|
130
|
-
alias_method :path_to_font, :font_path
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|