Sha256: 85a6cfcf22ab5fde4d2abb7639c1db8c23a96d9d455cc29529640b64085f2acf

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy_html_generator-1.0.6 lib/easy_html_generator/generator/compile/base.rb