Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit d25d105

Browse files
committed
Merge pull request #217 from koenpunt/sprockets-3
Sprockets 3 support
2 parents dd10bdb + 65744e3 commit d25d105

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

lib/requirejs/rails/builder.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ def build
1414
@config.tmp_dir
1515
end
1616

17-
def digest_for(path)
18-
if !::Rails.application.assets.file_digest(path).nil?
19-
::Rails.application.assets.file_digest(path).hexdigest
20-
else
21-
raise Requirejs::BuildError, "Cannot compute digest for missing asset: #{path}"
22-
end
23-
end
24-
2517
def generate_rjs_driver
2618
templ = Erubis::Eruby.new(@config.driver_template_path.read)
2719
@config.driver_path.open('w') do |f|

lib/tasks/requirejs-rails_tasks.rake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ OS X Homebrew users can use 'brew install node'.
8989
task prepare_source: ["requirejs:setup",
9090
"requirejs:clean"] do
9191
bower_json_pattern = Regexp.new("\\A(.*)/bower\\.json\\z")
92-
js_ext = requirejs.env.extension_for_mime_type("application/javascript")
92+
93+
js_ext = if requirejs.env.respond_to?(:extension_for_mime_type)
94+
requirejs.env.extension_for_mime_type("application/javascript")
95+
else
96+
requirejs.env.mime_types["application/javascript"][:extensions].first
97+
end
9398

9499
requirejs.config.source_dir.mkpath
95100

@@ -101,18 +106,14 @@ OS X Homebrew users can use 'brew install node'.
101106
original_cache = requirejs.env.cache
102107
requirejs.env.cache = nil
103108

104-
requirejs.env.each_logical_path do |logical_path|
105-
m = bower_json_pattern.match(logical_path)
106-
bower_logical_path = m && "#{m[1]}#{js_ext}"
109+
requirejs.env.logical_paths do |logical_path|
107110

108-
next \
109-
if !(requirejs.config.asset_allowed?(logical_path) || bower_logical_path)
111+
next if ! requirejs.config.asset_allowed?(logical_path)
110112

111113
asset = requirejs.env.find_asset(logical_path)
112114

113115
if asset
114-
# If a `bower.json` was found, then substitute the logical path with the parsed module name.
115-
filename = requirejs.config.source_dir.join(bower_logical_path || asset.logical_path)
116+
filename = requirejs.config.source_dir.join(asset.logical_path)
116117
filename.dirname.mkpath
117118
asset.write_to(filename)
118119
end
@@ -144,8 +145,10 @@ OS X Homebrew users can use 'brew install node'.
144145
task digestify_and_compress: ["requirejs:setup"] do
145146
requirejs.config.build_config['modules'].each do |m|
146147
asset_name = "#{requirejs.config.module_name_for(m)}.js"
148+
asset = requirejs.env.find_asset(asset_name)
149+
147150
built_asset_path = requirejs.config.build_dir.join(asset_name)
148-
digest_name = asset_name.sub(/\.(\w+)$/) { |ext| "-#{requirejs.builder.digest_for(built_asset_path)}#{ext}" }
151+
digest_name = asset.digest_path
149152
digest_asset_path = requirejs.config.target_dir + digest_name
150153

151154
# Ensure that the parent directory `a/b` for modules with names like `a/b/c` exist.

0 commit comments

Comments
 (0)