Sha256: 603ba865c529fc97412374c311080b9be89b1e2fda0dccf2a09ad34ef0fa475d
Contents?: true
Size: 1.63 KB
Versions: 42
Compression:
Stored size: 1.63 KB
Contents
require 'thor' require 'thor/actions' require 'fileutils' require 'singleton' class Thor module Actions def template_directory(source, *args, &block) config = args.last.is_a?(Hash) ? args.pop : {} destination = args.first || source action TemplateDirectory.new(self, source, destination || source, config, &block) end class TemplateDirectory < Directory module DSL class Support include Thor::Actions include Singleton def initialize super nil, options, config end end def project_config yield(Thor::Util.escape_globs(destination), config) end def support Support.instance end end include DSL protected def execute! super lookup = Thor::Util.escape_globs(destination) lookup = file_level_lookup(lookup) files(lookup).select{|f| f =~ /~template_config.rb/ }.each do |file_source| conf = File.open(file_source, 'r:utf-8') { |f| f.read } # Work around for Rubinius incomplete encoding in 1.9 mode if conf.respond_to?(:encoding) && conf.encoding.name != "UTF-8" conf.encode!('UTF-8') end base.shell.say_status :executing, "configuration file: #{base.relative_to_original_destination_root(file_source)}", :green begin eval(conf, binding, file_source) FileUtils.rm file_source rescue Exception => e raise Thor::Error, "Invalid `#{file_source}` file: #{e.message}", e.backtrace end end end end end end
Version data entries
42 entries across 42 versions & 1 rubygems