Class: FolderTemplate::TemplateFolder
- Inherits:
-
Object
- Object
- FolderTemplate::TemplateFolder
- Defined in:
- lib/folder_template/template_folder.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#file_templates ⇒ Object
readonly
Returns the value of attribute file_templates.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(fs, env) ⇒ Object
-
#initialize(path) ⇒ TemplateFolder
constructor
A new instance of TemplateFolder.
- #variables ⇒ Object
Constructor Details
#initialize(path) ⇒ TemplateFolder
Returns a new instance of TemplateFolder.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/folder_template/template_folder.rb', line 17 def initialize( path ) @base_path = path file_templates_path = File.join( path, "template" ) @file_templates = _load_template( file_templates_path ) context_filename = File.join( path, "context.rb" ) @context = Context.load( context_filename ) if File.readable?( context_filename ) @context ||= Context.new end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
13 14 15 |
# File 'lib/folder_template/template_folder.rb', line 13 def base_path @base_path end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/folder_template/template_folder.rb', line 15 def context @context end |
#file_templates ⇒ Object (readonly)
Returns the value of attribute file_templates.
14 15 16 |
# File 'lib/folder_template/template_folder.rb', line 14 def file_templates @file_templates end |
Class Method Details
.validate_template_path(path) ⇒ Object
40 41 42 43 |
# File 'lib/folder_template/template_folder.rb', line 40 def self.validate_template_path( path ) File.readable?( File.join( path.to_s, "context.rb" ) ) && File.directory?( File.join( path.to_s, "template" ) ) end |
Instance Method Details
#generate(fs, env) ⇒ Object
34 35 36 37 38 |
# File 'lib/folder_template/template_folder.rb', line 34 def generate( fs, env ) file_templates.each do |entry| entry.generate( fs, context.merge( env ) ) end end |
#variables ⇒ Object
28 29 30 31 32 |
# File 'lib/folder_template/template_folder.rb', line 28 def variables @variables ||= @file_templates.each_with_object( Set.new ) do |e, variables| variables.merge( e.variables ) end end |