Sha256: 5d5e13c3a576fed5cfdbed2c2c338932825dc0c84e46e6a1dd4510084c27ee19
Contents?: true
Size: 1.43 KB
Versions: 15
Compression:
Stored size: 1.43 KB
Contents
require "pathname" require "thor" module Dry module Web module Roda class Generate TEMPLATES_DIR = "templates".freeze SOURCE_DIR = Pathname(__FILE__).dirname.join(TEMPLATES_DIR) attr_reader :target_dir, :template_scope, :template_files, :processor def initialize(target_dir, template_scope) @target_dir = target_dir @template_scope = template_scope @template_files = Dir[SOURCE_DIR.join('**/{.,}*')] @processor = Class.new(Thor) do include Thor::Actions end.new @processor.class.source_root SOURCE_DIR end def call(source, target) source = Pathname(source) aboslute_source_path = source.expand_path(SOURCE_DIR) target_file = get_target_file(target) template_file = template_files.find { |f| f == aboslute_source_path.to_s } or raise "missing template file +#{source}+" template_file = Pathname(template_file) processor.template template_file, target_file, template_scope create_executable(target_file) if executable?(template_file) end private def get_target_file(target) Pathname.getwd.join(target_dir, target) end def create_executable(file) FileUtils.chmod "a+x", file end def executable?(file) file.file? && file.executable? end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems