Class: Ezframe::Template

Inherits:
Object show all
Defined in:
lib/ezframe/template.rb

Class Method Summary collapse

Class Method Details

.fill_from_file(filename, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ezframe/template.rb', line 6

def fill_from_file(filename, opts = {})
  dir = File.dirname(filename)
  unless File.exist?(filename)
    raise "fill_template: file does not exist: #{filename}"
  end
  instr = File.open(filename, &:read)
  return fill_in_text(instr, opts)
end

.fill_in_text(text, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ezframe/template.rb', line 15

def fill_in_text(text, opts = {})
  outstr = text.gsub(/\#\{([^\}]+)\}/) do
    keyword = $1
    if opts[keyword.to_sym]
      opts[keyword.to_sym] 
    elsif ENV[keyword]
      ENV[keyword]
    else
      EzLog.info "[WARN] no value for keyword: #{keyword}"
      nil
    end
  end
  return outstr
end