sprockets-rails 2.3.3 → 3.0.0
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.
- checksums.yaml +4 -4
- data/README.md +43 -31
- data/lib/sprockets/rails/context.rb +48 -0
- data/lib/sprockets/rails/helper.rb +249 -128
- data/lib/sprockets/rails/route_wrapper.rb +23 -0
- data/lib/sprockets/rails/task.rb +10 -14
- data/lib/sprockets/rails/utils.rb +11 -0
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +125 -76
- metadata +15 -22
- data/LICENSE +0 -20
- data/lib/sprockets/rails/legacy_asset_tag_helper.rb +0 -32
- data/lib/sprockets/rails/legacy_asset_url_helper.rb +0 -133
data/lib/sprockets/railtie.rb
CHANGED
@@ -2,9 +2,13 @@ require 'rails'
|
|
2
2
|
require 'rails/railtie'
|
3
3
|
require 'action_controller/railtie'
|
4
4
|
require 'active_support/core_ext/module/remove_method'
|
5
|
+
require 'active_support/core_ext/numeric/bytes'
|
5
6
|
require 'sprockets'
|
7
|
+
require 'sprockets/rails/context'
|
6
8
|
require 'sprockets/rails/helper'
|
9
|
+
require 'sprockets/rails/route_wrapper'
|
7
10
|
require 'sprockets/rails/version'
|
11
|
+
require 'set'
|
8
12
|
|
9
13
|
module Rails
|
10
14
|
class Application
|
@@ -19,37 +23,32 @@ module Rails
|
|
19
23
|
remove_possible_method :assets=
|
20
24
|
|
21
25
|
# Returns Sprockets::Environment for app config.
|
22
|
-
|
23
|
-
@assets ||= Sprockets::Environment.new(root.to_s) do |env|
|
24
|
-
env.version = ::Rails.env
|
26
|
+
attr_accessor :assets
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
# Returns Sprockets::Manifest for app config.
|
29
|
+
attr_accessor :assets_manifest
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
# Called from asset helpers to alert you if you reference an asset URL that
|
32
|
+
# isn't precompiled and hence won't be available in production.
|
33
|
+
def asset_precompiled?(logical_path)
|
34
|
+
precompiled_assets.include? logical_path
|
33
35
|
end
|
34
|
-
attr_writer :assets
|
35
36
|
|
36
|
-
#
|
37
|
-
|
37
|
+
# Lazy-load the precompile list so we don't cause asset compilation at app
|
38
|
+
# boot time, but ensure we cache the list so we don't recompute it for each
|
39
|
+
# request or test case.
|
40
|
+
def precompiled_assets
|
41
|
+
@precompiled_assets ||= assets_manifest.find(config.assets.precompile).map(&:logical_path).to_set
|
42
|
+
end
|
38
43
|
end
|
39
44
|
|
40
45
|
class Engine < Railtie
|
41
46
|
# Skip defining append_assets_path on Rails <= 4.2
|
42
47
|
unless initializers.find { |init| init.name == :append_assets_path }
|
43
48
|
initializer :append_assets_path, :group => :all do |app|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
|
48
|
-
else
|
49
|
-
app.config.assets.paths.unshift(*paths["vendor/assets"].paths.select { |d| File.directory?(d) })
|
50
|
-
app.config.assets.paths.unshift(*paths["lib/assets"].paths.select { |d| File.directory?(d) })
|
51
|
-
app.config.assets.paths.unshift(*paths["app/assets"].paths.select { |d| File.directory?(d) })
|
52
|
-
end
|
49
|
+
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
|
50
|
+
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
|
51
|
+
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -57,8 +56,11 @@ end
|
|
57
56
|
|
58
57
|
module Sprockets
|
59
58
|
class Railtie < ::Rails::Railtie
|
60
|
-
|
61
|
-
|
59
|
+
include Sprockets::Rails::Utils
|
60
|
+
|
61
|
+
LOOSE_APP_ASSETS = lambda do |logical_path, filename|
|
62
|
+
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
|
63
|
+
!%w(.js .css).include?(File.extname(logical_path))
|
62
64
|
end
|
63
65
|
|
64
66
|
class OrderedOptions < ActiveSupport::OrderedOptions
|
@@ -68,92 +70,139 @@ module Sprockets
|
|
68
70
|
end
|
69
71
|
|
70
72
|
config.assets = OrderedOptions.new
|
71
|
-
config.assets._blocks
|
72
|
-
config.assets.paths
|
73
|
-
config.assets.prefix
|
74
|
-
config.assets.manifest
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
config.assets._blocks = []
|
74
|
+
config.assets.paths = []
|
75
|
+
config.assets.prefix = "/assets"
|
76
|
+
config.assets.manifest = nil
|
77
|
+
if using_sprockets4?
|
78
|
+
config.assets.precompile = %w( manifest.js )
|
79
|
+
else
|
80
|
+
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
|
81
|
+
end
|
82
|
+
config.assets.version = ""
|
83
|
+
config.assets.debug = false
|
84
|
+
config.assets.compile = true
|
85
|
+
config.assets.digest = true
|
86
|
+
config.assets.cache_limit = 50.megabytes
|
87
|
+
|
88
|
+
config.assets.configure do |env|
|
89
|
+
config.assets.paths.each { |path| env.append_path(path) }
|
90
|
+
end
|
91
|
+
|
92
|
+
config.assets.configure do |env|
|
93
|
+
env.context_class.send :include, ::Sprockets::Rails::Context
|
94
|
+
env.context_class.assets_prefix = config.assets.prefix
|
95
|
+
env.context_class.digest_assets = config.assets.digest
|
96
|
+
env.context_class.config = config.action_controller
|
97
|
+
end
|
98
|
+
|
99
|
+
config.assets.configure do |env|
|
100
|
+
env.cache = Sprockets::Cache::FileStore.new(
|
101
|
+
"#{env.root}/tmp/cache",
|
102
|
+
config.assets.cache_limit,
|
103
|
+
env.logger
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
Sprockets.register_dependency_resolver 'rails-env' do
|
108
|
+
::Rails.env
|
109
|
+
end
|
110
|
+
config.assets.configure do |env|
|
111
|
+
env.depend_on 'environment-version'
|
112
|
+
end
|
113
|
+
|
114
|
+
config.assets.configure do |env|
|
115
|
+
env.version = config.assets.version
|
116
|
+
end
|
80
117
|
|
81
118
|
rake_tasks do |app|
|
82
119
|
require 'sprockets/rails/task'
|
83
120
|
Sprockets::Rails::Task.new(app)
|
84
121
|
end
|
85
122
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# the Sprockets cache when changed.
|
91
|
-
app.assets.version = [
|
92
|
-
app.assets.version,
|
93
|
-
config.assets.version,
|
94
|
-
config.action_controller.relative_url_root,
|
95
|
-
(config.action_controller.asset_host unless config.action_controller.asset_host.respond_to?(:call)),
|
96
|
-
Sprockets::Rails::VERSION
|
97
|
-
].compact.join('-')
|
98
|
-
|
99
|
-
# Copy config.assets.paths to Sprockets
|
100
|
-
config.assets.paths.each do |path|
|
101
|
-
app.assets.append_path path
|
123
|
+
def build_environment(app, initialized = nil)
|
124
|
+
initialized = app.initialized? if initialized.nil?
|
125
|
+
unless initialized
|
126
|
+
::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
|
102
127
|
end
|
103
128
|
|
129
|
+
env = Sprockets::Environment.new(app.root.to_s)
|
130
|
+
|
131
|
+
config = app.config
|
132
|
+
|
104
133
|
# Run app.assets.configure blocks
|
105
134
|
config.assets._blocks.each do |block|
|
106
|
-
block.call
|
135
|
+
block.call(env)
|
107
136
|
end
|
108
137
|
|
109
138
|
# Set compressors after the configure blocks since they can
|
110
139
|
# define new compressors and we only accept existent compressors.
|
111
|
-
|
112
|
-
|
140
|
+
env.js_compressor = config.assets.js_compressor
|
141
|
+
env.css_compressor = config.assets.css_compressor
|
113
142
|
|
114
143
|
# No more configuration changes at this point.
|
115
144
|
# With cache classes on, Sprockets won't check the FS when files
|
116
145
|
# change. Preferable in production when the FS only changes on
|
117
146
|
# deploys when the app restarts.
|
118
147
|
if config.cache_classes
|
119
|
-
|
148
|
+
env = env.cached
|
120
149
|
end
|
121
150
|
|
122
|
-
|
151
|
+
env
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.build_manifest(app)
|
155
|
+
config = app.config
|
156
|
+
path = File.join(config.paths['public'].first, config.assets.prefix)
|
157
|
+
Sprockets::Manifest.new(app.assets, path, config.assets.manifest)
|
158
|
+
end
|
159
|
+
|
160
|
+
config.after_initialize do |app|
|
161
|
+
config = app.config
|
162
|
+
|
123
163
|
if config.assets.compile
|
124
|
-
app.
|
125
|
-
|
126
|
-
|
164
|
+
app.assets = self.build_environment(app, true)
|
165
|
+
app.routes.prepend do
|
166
|
+
mount app.assets => config.assets.prefix
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
app.assets_manifest = build_manifest(app)
|
171
|
+
|
172
|
+
if config.assets.resolve_with.nil?
|
173
|
+
config.assets.resolve_with = []
|
174
|
+
config.assets.resolve_with << :manifest if config.assets.digest && !config.assets.debug
|
175
|
+
config.assets.resolve_with << :environment if config.assets.compile
|
176
|
+
end
|
177
|
+
|
178
|
+
ActionDispatch::Routing::RouteWrapper.class_eval do
|
179
|
+
class_attribute :assets_prefix
|
180
|
+
|
181
|
+
if defined?(prepend) && ::Rails.version >= '4'
|
182
|
+
prepend Sprockets::Rails::RouteWrapper
|
183
|
+
else
|
184
|
+
include Sprockets::Rails::RouteWrapper
|
185
|
+
end
|
186
|
+
|
187
|
+
self.assets_prefix = config.assets.prefix
|
127
188
|
end
|
128
189
|
|
129
190
|
ActiveSupport.on_load(:action_view) do
|
130
191
|
include Sprockets::Rails::Helper
|
131
192
|
|
132
193
|
# Copy relevant config to AV context
|
133
|
-
self.debug_assets
|
134
|
-
self.digest_assets
|
135
|
-
self.assets_prefix
|
136
|
-
|
137
|
-
# Copy over to Sprockets as well
|
138
|
-
context = app.assets.context_class
|
139
|
-
context.assets_prefix = config.assets.prefix
|
140
|
-
context.digest_assets = config.assets.digest
|
141
|
-
context.config = config.action_controller
|
194
|
+
self.debug_assets = config.assets.debug
|
195
|
+
self.digest_assets = config.assets.digest
|
196
|
+
self.assets_prefix = config.assets.prefix
|
197
|
+
self.assets_precompile = config.assets.precompile
|
142
198
|
|
143
|
-
self.assets_environment = app.assets
|
199
|
+
self.assets_environment = app.assets
|
144
200
|
self.assets_manifest = app.assets_manifest
|
145
|
-
end
|
146
201
|
|
147
|
-
|
148
|
-
Sprockets::Rails::Helper.assets ||= app.assets
|
149
|
-
Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors
|
202
|
+
self.resolve_assets_with = config.assets.resolve_with
|
150
203
|
|
151
|
-
|
152
|
-
|
153
|
-
app.routes.prepend do
|
154
|
-
mount app.assets => config.assets.prefix
|
155
|
-
end
|
156
|
-
end
|
204
|
+
# Expose the app precompiled asset check to the view
|
205
|
+
self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }
|
157
206
|
end
|
158
207
|
end
|
159
208
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -16,62 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '4.0'
|
19
|
+
version: 3.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '4.0'
|
26
|
+
version: 3.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: actionpack
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
33
|
+
version: '4.0'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
40
|
+
version: '4.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: activesupport
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '4.0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
54
|
+
version: '4.0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: railties
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
59
|
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
61
|
+
version: '4.0'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
68
|
+
version: '4.0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: rake
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,13 +114,13 @@ executables: []
|
|
120
114
|
extensions: []
|
121
115
|
extra_rdoc_files: []
|
122
116
|
files:
|
123
|
-
- LICENSE
|
124
117
|
- README.md
|
125
118
|
- lib/sprockets/rails.rb
|
119
|
+
- lib/sprockets/rails/context.rb
|
126
120
|
- lib/sprockets/rails/helper.rb
|
127
|
-
- lib/sprockets/rails/
|
128
|
-
- lib/sprockets/rails/legacy_asset_url_helper.rb
|
121
|
+
- lib/sprockets/rails/route_wrapper.rb
|
129
122
|
- lib/sprockets/rails/task.rb
|
123
|
+
- lib/sprockets/rails/utils.rb
|
130
124
|
- lib/sprockets/rails/version.rb
|
131
125
|
- lib/sprockets/railtie.rb
|
132
126
|
homepage: https://github.com/rails/sprockets-rails
|
@@ -141,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
135
|
requirements:
|
142
136
|
- - ">="
|
143
137
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
138
|
+
version: 1.9.3
|
145
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
140
|
requirements:
|
147
141
|
- - ">="
|
@@ -149,9 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
143
|
version: '0'
|
150
144
|
requirements: []
|
151
145
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.4.
|
146
|
+
rubygems_version: 2.4.5.1
|
153
147
|
signing_key:
|
154
148
|
specification_version: 4
|
155
149
|
summary: Sprockets Rails integration
|
156
150
|
test_files: []
|
157
|
-
has_rdoc:
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Joshua Peek
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
|
3
|
-
module Sprockets
|
4
|
-
module Rails
|
5
|
-
# Backports of AssetTagHelper methods for Rails 2.x and 3.x.
|
6
|
-
module LegacyAssetTagHelper
|
7
|
-
include ActionView::Helpers::TagHelper
|
8
|
-
|
9
|
-
def javascript_include_tag(*sources)
|
10
|
-
options = sources.extract_options!.stringify_keys
|
11
|
-
sources.uniq.map { |source|
|
12
|
-
tag_options = {
|
13
|
-
"src" => path_to_javascript(source)
|
14
|
-
}.merge(options)
|
15
|
-
content_tag(:script, "", tag_options)
|
16
|
-
}.join("\n").html_safe
|
17
|
-
end
|
18
|
-
|
19
|
-
def stylesheet_link_tag(*sources)
|
20
|
-
options = sources.extract_options!.stringify_keys
|
21
|
-
sources.uniq.map { |source|
|
22
|
-
tag_options = {
|
23
|
-
"rel" => "stylesheet",
|
24
|
-
"media" => "screen",
|
25
|
-
"href" => path_to_stylesheet(source)
|
26
|
-
}.merge(options)
|
27
|
-
tag(:link, tag_options)
|
28
|
-
}.join("\n").html_safe
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -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
|