Module: Erubis::PrintEnabledEnhancer

Included in:
PrintEnabledEruby
Defined in:
lib/erubis/enhancer.rb

Overview

enable print function

Notice: use Eruby#evaluate() and don’t use Eruby#result() to be enable print function.

this is only for Eruby.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descObject

:nodoc:



123
124
125
# File 'lib/erubis/enhancer.rb', line 123

def self.desc   # :nodoc:
  "enable to use print function in '<% %>'"
end

Instance Method Details

#add_preamble(src) ⇒ Object



127
128
129
130
# File 'lib/erubis/enhancer.rb', line 127

def add_preamble(src)
  src << "@_buf = "
  super
end

#evaluate(context = nil) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/erubis/enhancer.rb', line 138

def evaluate(context=nil)
  _src = @src
  if context.is_a?(Hash)
    context.each do |key, val| instance_variable_set("@#{key}", val) end
  elsif context
    context.instance_variables.each do |name|
      instance_variable_set(name, context.instance_variable_get(name))
    end
  end
  return instance_eval(_src, (@filename || '(erubis)'))
end


132
133
134
135
136
# File 'lib/erubis/enhancer.rb', line 132

def print(*args)
  args.each do |arg|
    @_buf << arg.to_s
  end
end