Class: Temp::Template
- Inherits:
-
Object
- Object
- Temp::Template
- Defined in:
- lib/temp/template.rb
Overview
A Template object represents a template and provides information about it.
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tempfile ⇒ Object
readonly
Returns the value of attribute tempfile.
Class Method Summary collapse
-
.all(conf) ⇒ Object
Returns an array of all templates in the template directory.
-
.find_files(path) ⇒ Object
Finds all of the files in a path.
Instance Method Summary collapse
-
#initialize(name, conf) ⇒ Template
constructor
Loads a template.
Constructor Details
#initialize(name, conf) ⇒ Template
Loads a template
20 21 22 23 24 25 26 27 28 29 30 |
# 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.) @name = @tempfile.info[:name] || name @desc = @tempfile.info[:desc] || '' @files = Template.find_files(@path) - @tempfile.ignore_files end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def conf @conf end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def desc @desc end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def filename @filename end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def files @files end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def path @path end |
#tempfile ⇒ Object (readonly)
Returns the value of attribute tempfile.
8 9 10 |
# File 'lib/temp/template.rb', line 8 def tempfile @tempfile end |
Class Method Details
.all(conf) ⇒ Object
Returns an array of all templates in the template directory
11 12 13 14 15 16 17 |
# 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) ⇒ Object
Finds all of the files in a path
33 34 35 36 |
# File 'lib/temp/template.rb', line 33 def self.find_files(path) path = File.(path) Dir.glob(File.join(path, '**/*')).map { |f| f.sub(path + '/', '') } end |