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:



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

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

Instance Method Details

#add_preamble(src) ⇒ Object



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

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

#evaluate(context = nil) ⇒ Object



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

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


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

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