Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f4120f5

Browse files
committedMar 18, 2015
YOLO!
1 parent 6de7f9f commit f4120f5

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed
 

Diff for: ‎lib/opal/sprockets/processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def evaluate(context, locals, &block)
7878
# result = builder.build_str(data, path, :prerequired => prerequired)
7979

8080
if self.class.source_map_enabled
81-
map_contents = compiler.source_map.to_s
81+
map_contents = compiler.source_map.as_json.to_json
8282
::Opal::SourceMapServer.set_map_cache(context.environment, path, map_contents)
8383
end
8484

Diff for: ‎lib/opal/sprockets/server.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,18 @@ def html
114114
end
115115

116116
def javascript_include_tag source
117+
sprockets = @server.sprockets
118+
asset = sprockets[source]
119+
120+
mark_as_loaded = asset.dependencies.reject do |a|
121+
::Sprockets::AssetAttributes.new(sprockets, a.pathname).engines.include?(::Opal::Processor)
122+
end.map do |asset|
123+
path = asset.logical_path.gsub(/\.js$/, '')
124+
"Opal.mark_as_loaded(Opal.normalize_loadable_path(#{path.inspect}));"
125+
end.join("\n")
126+
117127
if @server.debug
118-
assets = @server.sprockets[source].to_a
128+
assets = asset.to_a
119129

120130
raise "Cannot find asset: #{source}" if assets.empty?
121131

@@ -126,7 +136,12 @@ def javascript_include_tag source
126136
scripts.join "\n"
127137
else
128138
"<script src=\"/assets/#{source}.js\"></script>"
129-
end
139+
end + <<-HTML
140+
<script>
141+
#{mark_as_loaded}
142+
Opal.load(#{source.inspect});
143+
</script>
144+
HTML
130145
end
131146

132147
SOURCE = <<-HTML

Diff for: ‎lib/opal/sprockets/source_map_server.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ def cache_set(key, value)
4444
end
4545
end
4646

47+
def self.logger
48+
@logger ||= defined?(::Rails) ? Rails.logger : Logger.new($stdout)
49+
end
50+
4751
def self.get_map_cache(sprockets, logical_path)
4852
logical_path = logical_path.gsub(/\.js$/, '')
49-
::Rails.logger.info "get_map_cache #{logical_path}"
53+
logger.info "get_map_cache #{logical_path}"
5054
cache_key = cache_key_for_path(logical_path+'.map')
5155
cache(sprockets).cache_get(cache_key)
5256
end

0 commit comments

Comments
 (0)
Please sign in to comment.