Skip to content

Commit

Permalink
Improve compiling infrastructure, and restore a bit of duplication in…
Browse files Browse the repository at this point in the history
… spec_helper to make debugging easier in test failures
  • Loading branch information
wycats committed Dec 12, 2010
1 parent 35b4d9f commit fdc8e42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -35,7 +35,7 @@ minimal_deps.unshift "dist"
debug_deps.unshift "dist"

def build_for_task(task)
FileUtils.rm_rf("dist")
FileUtils.rm_rf("dist/*") if File.directory?("dist")
FileUtils.mkdir_p("dist")

contents = ["var Handlebars = {};"]
Expand Down
22 changes: 21 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -37,9 +37,29 @@ def self.js_backtrace(context)
end
end

def self.remove_exports(string)
match = string.match(%r{^// BEGIN\(BROWSER\)\n(.*)\n^// END\(BROWSER\)}m)
match ? match[1] : string
end

def self.js_load(file)
str = File.read(file)
CONTEXT.eval(remove_exports(str), file)
end

CONTEXT = V8::Context.new
CONTEXT.instance_eval do |context|
context.load('dist/handlebars.debug.js')
context["exports"] = nil
context["Handlebars"] = {}

Handlebars::Spec.js_load('lib/handlebars/ast.js');
Handlebars::Spec.js_load('lib/handlebars/jison_ext.js');
Handlebars::Spec.js_load('lib/handlebars/handlebars_lexer.js')
Handlebars::Spec.js_load('lib/handlebars/printer.js')
Handlebars::Spec.js_load('lib/handlebars/parser.js')
Handlebars::Spec.js_load('lib/handlebars/runtime.js')
Handlebars::Spec.js_load('lib/handlebars/utils.js')
Handlebars::Spec.js_load('lib/handlebars.js')

context["p"] = proc do |val|
p val
Expand Down

0 comments on commit fdc8e42

Please sign in to comment.