Refactor of standalone build tasks; Better templating of the core runner.html and the example SpecRunner.html

This commit is contained in:
Davis W. Frank
2011-06-15 09:15:40 -07:00
parent e59171935f
commit 6b2e45eab5
10 changed files with 189 additions and 61 deletions

View File

@@ -1,16 +1,43 @@
require 'ostruct'
desc "build the browser spec runner.html based on current tree"
desc "build the browser spec for Jasmine core based on current tree"
task :build_runner_html do
template = Tilt.new('spec/templates/runner.html.erb')
File.open('spec/runner.html', 'w+') do |f|
scope = OpenStruct.new(:source_tags => other_source_file_tags,
scope = OpenStruct.new(:title => "Jasmine Spec Runner: Jasmine Core",
:favicon => favicon,
:jasmine_tags => core_jasmine_tags,
:source_tags => other_source_file_tags,
:spec_file_tags => spec_file_tags)
f << template.render(scope)
end
end
def favicon
<<HTML
<link rel="shortcut icon" type="image/png" href="../images/jasmine_favicon.png">
HTML
end
def core_jasmine_tags
tags = %Q{<link href="../lib/jasmine.css" rel="stylesheet"/>}
tags << "\n "
tags << script_tags_for("../lib/jasmine.js")
tags << "\n "
tags << undefined_catch
tags
end
def undefined_catch
<<HTML
<script type="text/javascript">
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
undefined = "diz be undefined yo";
</script>
HTML
end
def other_source_file_tags
other_files = html_sources + console_sources
script_tags_for other_files.collect { |f| "../#{f}" }
@@ -21,12 +48,3 @@ def spec_file_tags
script_tags_for spec_files.collect { |f| "../#{f}" }
end
def script_tags_for(files)
script_tag = Tilt::new('spec/templates/script_tag.html.erb')
files.inject([]) do |tags, f|
scope = OpenStruct.new :file => f
tags << script_tag.render(scope)
tags
end.join("\n ")
end