Class: ErbPP::ERBLN

Inherits:
Object
  • Object
show all
Defined in:
ext/cumo/narray/gen/erbln.rb

Instance Method Summary collapse

Constructor Details

#initialize(str, filename, trim_mode = nil, eoutvar = '_erbout') ⇒ ERBLN

Returns a new instance of ERBLN.



104
105
106
107
108
109
# File 'ext/cumo/narray/gen/erbln.rb', line 104

def initialize(str, filename, trim_mode=nil, eoutvar='_erbout')
  @filename = filename
  compiler = ERB::Compiler.new(trim_mode)
  set_eoutvar(compiler, eoutvar)
  @src, @enc = *compiler.compile(str)
end

Instance Method Details

#result(b) ⇒ Object



122
123
124
125
126
127
128
# File 'ext/cumo/narray/gen/erbln.rb', line 122

def result(b)
  #open("tmpout","a") do |f|
  #  f.puts "\n#file:#{@filename}"
  #  f.puts @src
  #end
  eval(@src, b, (@filename || '(erb)'), 0)
end

#run(b) ⇒ Object



118
119
120
# File 'ext/cumo/narray/gen/erbln.rb', line 118

def run(b)
  print self.result(b)
end

#set_eoutvar(compiler, eoutvar = '_erbout') ⇒ Object



111
112
113
114
115
116
# File 'ext/cumo/narray/gen/erbln.rb', line 111

def set_eoutvar(compiler, eoutvar = '_erbout')
  compiler.put_cmd = "#{eoutvar}.concat0"
  compiler.insert_cmd = "#{eoutvar}.concat1"
  compiler.pre_cmd = ["#{eoutvar} = CountLnString.new(#{@filename.inspect})"]
  compiler.post_cmd = ["#{eoutvar}.final"]
end