class Skellington::Template
Public Class Methods
new(name, generator)
click to toggle source
# File lib/skellington/template.rb, line 3 def initialize name, generator @name = name @generator = generator end
Public Instance Methods
common_templates()
click to toggle source
# File lib/skellington/template.rb, line 17 def common_templates File.join File.dirname(__FILE__), '..', 'templates', 'common' end
outpath()
click to toggle source
# File lib/skellington/template.rb, line 8 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
path()
click to toggle source
# File lib/skellington/template.rb, line 34 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
templates_dir()
click to toggle source
# File lib/skellington/template.rb, line 21 def templates_dir File.join File.dirname(__FILE__), '..', 'templates', @generator.framework end
to_s()
click to toggle source
# File lib/skellington/template.rb, line 46 def to_s Erubis::Eruby.new(path).evaluate(gen: @generator) end
write()
click to toggle source
# File lib/skellington/template.rb, line 25 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