Skip to content

Commit

Permalink
Allow opal-repl to require files from stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Aug 20, 2013
1 parent 20ea6ec commit 6262085
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/opal-repl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Opal
end

def eval_ruby(str)
code = Opal.parse str, :irb => true
code = @builder.build_str str, :irb => true
@v8.eval "var $_result = #{code} $_result.$inspect();"
rescue => e
puts "#{e.message}\n\t#{e.backtrace.join("\n\t")}"
Expand Down
14 changes: 12 additions & 2 deletions lib/opal/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def build(path)
@segments.join
end

def build_str(str, options = {})
@segments = []
@segments << compile_ruby(str, options)
@segments.join
end

def require_asset(path)
location = find_asset path

Expand Down Expand Up @@ -62,9 +68,9 @@ def build_asset(path)
@segments << __send__(builder, path)
end

def build_ruby(path)
def compile_ruby(str, options={})
parser = RequireParser.new
result = parser.parse File.read(path)
result = parser.parse str, options

parser.requires.each do |r|
require_asset r
Expand All @@ -73,6 +79,10 @@ def build_ruby(path)
result
end

def build_ruby(path)
compile_ruby File.read(path)
end

def build_js(path)
File.read(path)
end
Expand Down

0 comments on commit 6262085

Please sign in to comment.