class Temp::Template
A Template
object represents a template and provides information about it.
Attributes
conf[R]
desc[R]
filename[R]
files[R]
name[R]
path[R]
tempfile[R]
Public Class Methods
all(conf)
click to toggle source
Returns an array of all templates in the template directory
# File lib/temp/template.rb, line 11 def self.all(conf) Dir.entries(conf.template_dir).map do |t| unless t == '.' || t == '..' Temp::Template.new(t, conf) end end.compact end
find_files(path)
click to toggle source
Finds all of the files in a path
# File lib/temp/template.rb, line 33 def self.find_files(path) path = File.expand_path(path) Dir.glob(File.join(path, '**/*')).map { |f| f.sub(path + '/', '') } end
new(name, conf)
click to toggle source
Loads a template
# File lib/temp/template.rb, line 20 def initialize(name, conf) @conf = conf @path = File.join(@conf.template_dir, name) @filename = name raise Temp::Exceptions::TemplateNonExistentError unless File.exist? @path @tempfile = Temp::Tempfile.new(@path, @conf.template_options) @name = @tempfile.info[:name] || name @desc = @tempfile.info[:desc] || '' @files = Template.find_files(@path) - @tempfile.ignore_files end