Sha256: db422bda2acb7df55dedd33ed751e6f8ef45076d57c0ff3791e82949f77a0ff1
Contents?: true
Size: 1.26 KB
Versions: 4
Compression:
Stored size: 1.26 KB
Contents
module Skellington class Template def initialize name, generator @name = name @generator = generator end def outpath @outpath ||= begin subs = @generator.files[@name]['outpath'].split '/' @outpath = "#{@generator.path}/#{@generator.send(subs[1].to_sym)}/#{@name.gsub(subs[0], @generator.send(subs[1].to_sym))}" rescue NoMethodError @outpath = "#{@generator.path}/#{@generator.wormname}/#{@name}" end end def common_templates File.join File.dirname(__FILE__), '..', 'common', 'templates' end def templates_dir File.join File.dirname(__FILE__), '..', @generator.framework, 'templates' end def write print "Generating #{Skellington.unslash outpath}..." FileUtils.mkdir_p File.dirname outpath File.open outpath, 'w' do |f| f.write self end puts 'done' end def path [ "#{templates_dir}/#{@name}", "#{common_templates}/#{@generator.files.dig(@name, 'common')}", "#{common_templates}/#{@name}" ].each do |maybe_path| return File.read(File.open(maybe_path)) if File.file? maybe_path end '' end def to_s Erubis::Eruby.new(path).evaluate(gen: @generator) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
skellington-0.8.7 | lib/skellington/template.rb |
skellington-0.8.6 | lib/skellington/template.rb |
skellington-0.8.5 | lib/skellington/template.rb |
skellington-0.8.4 | lib/skellington/template.rb |