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

64 lines
1.3 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|
2011-12-29 23:37:23 +00:00
File.open(name, 'w') { |fh| fh.print template_for(files) }
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