lib/polytrix/documentation_generator.rb in polytrix-0.1.2 vs lib/polytrix/documentation_generator.rb in polytrix-0.1.3

- old
+ new

@@ -1,6 +1,7 @@ -require 'tilt' # seems to be a bug where padrino-helpers should require tilt +require 'tilt' # padrino-helpers wants you to pre-require tilt/erubis +require 'erubis' require 'padrino-helpers' module Polytrix class DocumentationGenerator [ @@ -18,26 +19,22 @@ @scenario = scenario @template_file = template_file end def process(challenges) + return nil unless File.readable? @template_file + @challenges = challenges - if File.readable? @template_file - # @template_file ||= find_file @search_path, scenario, "" - erb = ERB.new File.read(@template_file) - @result = erb.result(binding) || '' - end + erb = ERB.new File.read(@template_file) + @result = erb.result(binding) || '' end def save(target_file) - fail 'No results to write, please call process before save' if @result.nil? - if @result.empty? - # Warn: skip creating empty file - else - FileUtils.mkdir_p File.dirname(target_file) - File.open(target_file, 'wb') do |f| - f.write @result - end + fail 'No results to write, please call process before save' if @result.nil? || @result.empty? + + FileUtils.mkdir_p File.dirname(target_file) + File.open(target_file, 'wb') do |f| + f.write @result end end def code2doc(source_file, language = nil) source_code = File.read(source_file)