Class: FolderTemplate::TemplateFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/folder_template/template_folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_pathObject (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

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/folder_template/template_folder.rb', line 15

def context
  @context
end

#file_templatesObject (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

#variablesObject



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