lib/skellington/template.rb in skellington-0.8.1 vs lib/skellington/template.rb in skellington-0.8.2

- old
+ new

@@ -12,10 +12,14 @@ 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 @@ -26,10 +30,24 @@ end puts 'done' end def to_s - t = File.read(File.open("#{templates_dir}/#{@name}.eruby")) + path = "#{templates_dir}/#{@name}.eruby" + if @generator.files.dig(@name, 'common') + path = "#{common_templates}/#{@generator.files[@name]['common']}" + end + + begin + t = File.read(File.open(path)) + + # this can go away soon + if t =~ /^common: (.*)$/ + t = File.read(File.open("#{common_templates}/#{$1}")) + end + rescue Errno::ENOENT + t = File.read(File.open("#{common_templates}/#{@name}.eruby")) + end Erubis::Eruby.new(t).evaluate(gen: @generator) end end end