Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f4120f50aea2
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 199d5733f538
Choose a head ref
  • 5 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 19, 2015

  1. Copy the full SHA
    9608dbb View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    ff0b890 View commit details
  3. fixup! 9608dbb

    elia committed Mar 19, 2015
    Copy the full SHA
    f1f64d4 View commit details
  4. Copy the full SHA
    9c1704a View commit details
  5. Copy the full SHA
    199d573 View commit details
Showing with 34 additions and 24 deletions.
  1. +21 −0 lib/opal/sprockets/processor.rb
  2. +13 −24 lib/opal/sprockets/server.rb
21 changes: 21 additions & 0 deletions lib/opal/sprockets/processor.rb
Original file line number Diff line number Diff line change
@@ -85,6 +85,27 @@ def evaluate(context, locals, &block)
result.to_s
end

def self.load_asset_code(sprockets, name)
asset = sprockets[name]
module_name = -> asset { asset.logical_path.sub(/\.js$/, '').inspect }

non_opal_assets = ([asset]+asset.dependencies).reject do |a|
asset_attributes = ::Sprockets::AssetAttributes.new(sprockets, a.pathname)
asset_attributes.engines.include?(::Opal::Processor)
end

mark_as_loaded = non_opal_assets.map do |asset|
"Opal.mark_as_loaded(#{module_name[asset]});"
end

<<-JS
if (typeof(Opal) !== 'undefined') {
#{mark_as_loaded.join(";")};
Opal.load(#{module_name[asset]});
}
JS
end

def self.stubbed_files
@stubbed_files ||= []
end
37 changes: 13 additions & 24 deletions lib/opal/sprockets/server.rb
Original file line number Diff line number Diff line change
@@ -113,35 +113,24 @@ def html
end
end

def javascript_include_tag source
def javascript_include_tag name
sprockets = @server.sprockets
asset = sprockets[source]

mark_as_loaded = asset.dependencies.reject do |a|
::Sprockets::AssetAttributes.new(sprockets, a.pathname).engines.include?(::Opal::Processor)
end.map do |asset|
path = asset.logical_path.gsub(/\.js$/, '')
"Opal.mark_as_loaded(Opal.normalize_loadable_path(#{path.inspect}));"
end.join("\n")
prefix = @server.prefix
asset = sprockets[name]
raise "Cannot find asset: #{name}" if asset.nil?
scripts = []

if @server.debug
assets = asset.to_a

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

scripts = assets.map do |a|
%Q{<script src="/assets/#{ a.logical_path }?body=1"></script>}
asset.to_a.map do |dependency|
scripts << %Q{<script src="#{prefix}/#{dependency.logical_path}?body=1"></script>}
end

scripts.join "\n"
else
"<script src=\"/assets/#{source}.js\"></script>"
end + <<-HTML
<script>
#{mark_as_loaded}
Opal.load(#{source.inspect});
</script>
HTML
scripts << "<script src=\"#{prefix}/#{name}.js\"></script>"
end

scripts << "<script>#{Opal::Processor.load_asset_code(sprockets, name)}</script>"

scripts.join "\n"
end

SOURCE = <<-HTML