# encoding: utf-8 require 'colorize' # this is the generator base class class EasyHtmlGenerator::Generator::Compile::Base < EasyHtmlGenerator::Generator::Base def generate!(config) walk_files(config) do |input_file, output_file| next unless file_changed? input_file do_file(input_file, output_file, config) end end def walk_files(config) selector = File.join(config.source, config.selector) Dir[selector].each do |input_file| output_file = input_to_output_file(input_file, config) yield(input_file, output_file) end end def watch_files(config) Dir["#{config.source}/**/*"] end def input_to_output_file(input_file, config) input_file.sub(config.source, config.target) end def do_input!(_input, _input_file) fail NotImplementedError.new "#{self.class.name} is an abstract class." end def do_file(input_file, output_file, config) return unless File.exist?(input_file) && File.file?(input_file) log "-> do_file #{input_file.sub(@project.src_path, '').green}" FileUtils.mkdir_p File.dirname(output_file) input_content = File.read(input_file) output_content = do_input!(input_content, input_file, output_file, config) store_file_hash(input_file) return unless output_content File.write(output_file, output_content) end end