Class: Pakman::Templater

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/pakman/erb/templater.rb

Instance Method Summary collapse

Instance Method Details

#merge_pak(manifestsrc, pakpath, binding, name) ⇒ Object



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pakman/erb/templater.rb', line 14

def merge_pak( manifestsrc, pakpath, binding, name )

  start = Time.now

  pakname = Pakman.pakname_from_file( manifestsrc )

  puts "Merging template pack '#{pakname}'"

  # todo: rename to load_file once depreated API got removed

  manifest = Manifest.load_file_v2( manifestsrc )

  manifest.each do |entry|
    dest   = entry[0]
    source = entry[1]

    if dest =~ /__file__/   # replace w/ name

      dest = dest.gsub( '__file__', name )
    end

    # get full (absolute) path and make sure path exists

    destfull = File.expand_path( dest, pakpath )
    destpath = File.dirname( destfull )
    FileUtils.makedirs( destpath ) unless File.directory?( destpath )

    logger.debug "destfull=>#{destfull}<"
    logger.debug "destpath=>#{destpath}<"

    if source =~ /\.erb\.|.erb$/
      puts "  Merging to #{dest}..."

      out = File.new( destfull, 'w+:utf-8' )   ## note: use utf8 (by default)

      out << ErbTemplate.from_file( source ).render( binding )
      out.flush
      out.close
    else
      puts "  Copying to #{dest} from #{source}..."

      FileUtils.copy( source, destfull )
    end
  end # each entry in manifest


  puts "Done (in #{Time.now-start} s)."
end