Skip to content

Commit

Permalink
Allow certain assets to be stubbed
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 28, 2013
1 parent e1cdd73 commit a1e149d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/opal/sprockets/processor.rb
@@ -1,3 +1,4 @@
require 'set'
require 'sprockets'

$OPAL_SOURCE_MAPS = {}
Expand Down Expand Up @@ -49,6 +50,14 @@ class << self
self.source_map_enabled = true
self.irb_enabled = false

def self.stub_file(name)
stubbed_files << name.to_s
end

def self.stubbed_files
@stubbed_files ||= Set.new
end

def initialize_engine
require_template_library 'opal'
end
Expand All @@ -73,6 +82,7 @@ def evaluate(context, locals, &block)
result = compiler.compile data, options

compiler.requires.each do |r|
next if stubbed_file? r
path = find_opal_require context.environment, r
context.require_asset path
end
Expand All @@ -85,6 +95,10 @@ def evaluate(context, locals, &block)
end
end

def stubbed_file?(name)
self.class.stubbed_files.include? name
end

def find_opal_require(environment, r)
path = environment.paths.find do |p|
File.exist?(File.join(p, "#{r}.rb"))
Expand Down

0 comments on commit a1e149d

Please sign in to comment.