Class: CoherentBaseGenerator

Inherits:
RubiGen::Base
  • Object
show all
Defined in:
lib/coherent.rb

Instance Method Summary collapse

Instance Method Details

#copy_template_folder(m, path = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/coherent.rb', line 5

def copy_template_folder(m, path=nil)
  path = path ? "#{path}/" : ""
  prefix_regex= Regexp.new("^#{Regexp.escape(source_root)}/(.*)$")
  all_files= Dir.glob("#{source_root}/**/*").select { |filepath| File.file?(filepath) }

  all_files.map! { |filepath| prefix_regex.match(filepath)[1] }

  b= binding
  
  all_folders= all_files.map { |filepath|
    File.dirname(filepath).gsub(/@(\w+)@/) { |match|
      begin
        eval($1, b)
      rescue
        "@#{$1}@"
      end
    }
  }
  all_folders.uniq.each { |folder| m.directory "#{path}#{folder}" }

  all_files.each { |filepath|
    output_path= filepath.gsub(/\.erb$/, '').gsub(/@(\w+)@/) { |match|
      begin
        eval($1, b)
      rescue
        "@#{$1}@"
      end
    }
    output_path= "#{path}#{output_path}"
    if (filepath[/\.erb$/])
      m.template filepath, output_path
    else
      m.file filepath, output_path
    end
  }
end