module ERBh
Public Class Methods
default_options()
click to toggle source
# File lib/erbh.rb, line 17 def self.default_options @default_options end
define_method(name, &block)
click to toggle source
# File lib/erbh.rb, line 13 def self.define_method(name, &block) @methods[name] = block end
erbh(str, variables = {}, options = {})
click to toggle source
# File lib/erbh.rb, line 25 def erbh(str, variables = {}, options = {}) options = ERBh.default_options.merge(options) context = Object.new variables.each do |name, value| context.instance_variable_set("@#{name}", value) end class << context ERBh.erbh_methods.each do |name, block| define_method(name, block) end end context.instance_eval do erb = ERB.new("<% @#{options[:eoutvar]} = #{options[:eoutvar]} %>\n" + str, **options) erb.result(binding).sub(/\A\n/, '') end end
erbh_methods()
click to toggle source
# File lib/erbh.rb, line 21 def self.erbh_methods @methods end
Private Instance Methods
erbh(str, variables = {}, options = {})
click to toggle source
# File lib/erbh.rb, line 25 def erbh(str, variables = {}, options = {}) options = ERBh.default_options.merge(options) context = Object.new variables.each do |name, value| context.instance_variable_set("@#{name}", value) end class << context ERBh.erbh_methods.each do |name, block| define_method(name, block) end end context.instance_eval do erb = ERB.new("<% @#{options[:eoutvar]} = #{options[:eoutvar]} %>\n" + str, **options) erb.result(binding).sub(/\A\n/, '') end end