jasmine-headless-webkit/lib/jasmine/headless/template_writer.rb

66 lines
1.4 KiB
Ruby
Raw Normal View History

require 'multi_json'
require 'erb'
require 'tempfile'
2011-12-29 23:37:23 +00:00
require 'forwardable'
module Jasmine::Headless
class TemplateWriter
attr_reader :runner
2011-12-29 23:37:23 +00:00
extend Forwardable
def_delegators :runner, :files_list, :options
def_delegators :options, :reporters
def initialize(runner)
@runner = runner
end
2011-12-29 23:37:23 +00:00
def write
output = [
[ all_tests_filename, files_list.files_to_html ]
]
2011-12-29 23:37:23 +00:00
output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered?
output.each do |name, files|
template = template_for(files)
File.open(name, 'wb') { |fh| fh.print template }
end
output.collect(&:first)
end
def all_tests_filename
runner.runner_filename || "jhw.#{$$}.html"
end
def filtered_tests_filename
all_tests_filename.gsub(%r{\.html$}, '.filter.html')
end
2011-12-29 23:37:23 +00:00
def render
template_for(all_files)
end
def all_files
files_list.files_to_html
end
def jhw_reporters
reporters.collect do |reporter, output|
%{jasmine.getEnv().addReporter(new jasmine.HeadlessReporter.#{reporter}("#{output}"));}
2011-12-29 23:37:23 +00:00
end.join("\n")
end
private
2011-12-29 23:37:23 +00:00
def template_for(files)
spec_lines = files_list.spec_file_line_numbers
ERB.new(Jasmine::Headless.root.join('skel/template.html.erb').read).result(binding)
end
end
end