Skip to content

Commit af213da

Browse files
committedNov 23, 2014
get specs nearly passing again
1 parent d5c94ec commit af213da

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed
 

‎lib/opal/builder.rb

+20-23
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def build(path, options = {})
7575
self
7676
end
7777

78+
def build_str(source, filename, options = {})
79+
process_string(source, filename, options)
80+
end
81+
82+
def build_require(path, options = {})
83+
process_require(path, options)
84+
end
85+
7886
def process_string(source, filename, options)
7987
fname = path_reader.expand(filename).to_s
8088
asset = processor_for(source, filename, fname, requirable: false)
@@ -84,6 +92,7 @@ def process_string(source, filename, options)
8492
end
8593

8694
def process_require(filename, options)
95+
return if prerequired.include?(filename)
8796
return if processed.include? filename
8897
processed << filename
8998

@@ -105,7 +114,16 @@ def find_asset(path)
105114
if asset = cached_asset(path)
106115
asset
107116
else
108-
source = read path
117+
source = stub?(path) ? '' : read(path)
118+
119+
if source.nil?
120+
message = "can't find file: #{filename.inspect}"
121+
case @compiler_options[:dynamic_require_severity]
122+
when :error then raise LoadError, message
123+
when :warning then warn "can't find file: #{filename.inspect}"
124+
end
125+
end
126+
109127
fname = path_reader.expand(path).to_s
110128
asset = processor_for(source, path, fname, requirable: true)
111129
end
@@ -119,27 +137,6 @@ def cached_asset(path)
119137
end
120138
end
121139

122-
def build_str source, filename, options = {}
123-
#if cached = cache_store.retrieve(filename) and
124-
# puts "CACHED: #{filename}"
125-
# process_requires cached.requires, options
126-
# processed << cached
127-
128-
# return self
129-
#end
130-
131-
path = path_reader.expand(filename).to_s unless stub?(filename)
132-
asset = processor_for(source, filename, path, options)
133-
requires = preload + asset.requires + tree_requires(asset, path)
134-
requires.map { |r| process_require(r, options) }
135-
processed << asset
136-
self
137-
end
138-
139-
def build_require(path, options = {})
140-
process_require(path, options)
141-
end
142-
143140
def to_s
144141
assets.map(&:to_s).join("\n")
145142
end
@@ -148,7 +145,7 @@ def source_map
148145
assets.map(&:source_map).reduce(:+).as_json.to_json
149146
end
150147

151-
attr_reader :processed
148+
attr_reader :assets
152149

153150
attr_accessor :processors, :default_processor, :path_reader,
154151
:compiler_options, :stubs, :prerequired, :preload

‎lib/opal/sprockets/processor.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ def evaluate(context, locals, &block)
7070
path = context.logical_path
7171
prerequired = []
7272

73-
puts "here"
7473
builder = self.class.new_builder(context)
75-
builder.build(path)
74+
builder.build(path, :prerequired => prerequired)
7675

77-
if self.class.source_map_enabled and false
78-
register_source_map(context.logical_path, result.source_map.to_s)
79-
"#{result.to_s}\n//# sourceMappingURL=#{File.basename(context.logical_path)}.map\n"
76+
if self.class.source_map_enabled
77+
register_source_map(context.logical_path, builder.source_map.to_s)
78+
"#{builder.to_s}\n//# sourceMappingURL=#{File.basename(context.logical_path)}.map\n"
8079
else
8180
builder.to_s
8281
end

0 commit comments

Comments
 (0)
Please sign in to comment.