Sha256: a1269a17ba8fbb83c80a3e56dadb3dd2790a86bda1c2d81e31f66ca6f11e0cf1

Contents?: true

Size: 928 Bytes

Versions: 10

Compression:

Stored size: 928 Bytes

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 templates_dir
      File.join File.dirname(__FILE__), '..', 'templates'
    end

    def write
      print "Generating #{Skellington.unslash outpath}..."
      FileUtils.mkdir_p File.dirname outpath
      f = File.open outpath, 'w'
      f.write self
      f.close
      puts 'done'
    end

    def to_s
      t = File.read(File.open("#{templates_dir}/#{@name}.eruby"))
      Erubis::Eruby.new(t).evaluate(gen: @generator)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
skellington-0.4.11 lib/skellington/template.rb
skellington-0.4.10 lib/skellington/template.rb
skellington-0.4.9 lib/skellington/template.rb
skellington-0.4.8 lib/skellington/template.rb
skellington-0.4.6 lib/skellington/template.rb
skellington-0.4.5 lib/skellington/template.rb
skellington-0.4.4 lib/skellington/template.rb
skellington-0.4.3 lib/skellington/template.rb
skellington-0.4.2 lib/skellington/template.rb
skellington-0.4.1 lib/skellington/template.rb