Class: FolderTemplate::TemplateFolderEntry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, content) ⇒ TemplateFolderEntry

Returns a new instance of TemplateFolderEntry.



17
18
19
20
21
# File 'lib/folder_template/template_folder_entry.rb', line 17

def initialize( filename, content )
  @append, filename = _filter_append_marker( filename )
  @filename_template = TemplateString.new( filename )
  @content_template = TemplateString.new( content ) if !content.nil?
end

Instance Attribute Details

#appendObject (readonly)

Returns the value of attribute append.



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

def append
  @append
end

#content_templateObject (readonly)

Returns the value of attribute content_template.



14
15
16
# File 'lib/folder_template/template_folder_entry.rb', line 14

def content_template
  @content_template
end

#filename_templateObject (readonly)

Returns the value of attribute filename_template.



13
14
15
# File 'lib/folder_template/template_folder_entry.rb', line 13

def filename_template
  @filename_template
end

Instance Method Details

#generate(fs, env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/folder_template/template_folder_entry.rb', line 32

def generate( fs, env )
  filename = filename_template.expand( env ).to_s
  basename = File.basename( filename, File.extname( filename ) )

  if ( content_template )
    local_env = env.merge( filename:filename, basename:basename )
    content = content_template.expand( local_env ).to_s
    if ( append )
      fs.append_to_file( filename, content )
    else
      fs.write_to_file( filename, content )
    end
  else
    fs.makedirs( filename )
  end
end

#variablesObject



23
24
25
26
27
28
29
# File 'lib/folder_template/template_folder_entry.rb', line 23

def variables
  @variables ||= [filename_template, content_template].reject do |t|
    t.nil?
  end.each_with_object( Set.new ) do |t, variables|
    variables.merge( t.variables )
  end
end