Sha256: 271ad4e8754805293b85b0e3fe899e17d78c649fa069d073b18e03b5903100af

Contents?: true

Size: 1000 Bytes

Versions: 2

Compression:

Stored size: 1000 Bytes

Contents

# encoding: utf-8
require 'colorize'

# this is the generator base class
class EasyHtmlGenerator::Generator::Base
  attr_reader :config

  def initialize(project, config)
    @project = project
    @config  = config
  end

  def enabled?
    !!@config[:enabled]
  end

  def generate
    return unless enabled?

    log_running

    tasks.each do |task|
      generate! @config.merge(task)
    end
  end

  def generate!(_config)
    fail NotImplementedError.new "#{self.class.name} is an abstract class."
  end

  def repetitive?
    @config.key? :repetitive
  end

  def tasks
    return [@config] unless repetitive?

    @config[:repetitive]
  end

  def log_running
    log "#{self.class.name.yellow}"
  end

  def log(msg)
    STDERR.puts "  | #{msg.sub(@project.src_path, '')
      .sub('EasyHtmlGenerator::', '')}"
  end

  def file_changed?(file)
    EasyHtmlGenerator::Checksum.file_changed? file
  end

  def store_file_hash(file)
    EasyHtmlGenerator::Checksum.store_file(file)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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