Module: ERBh
- Defined in:
- lib/erbh.rb
Overview
rubocop:disable Style/Documentation
Class Method Summary collapse
- .default_options ⇒ Object
- .define_method(name, &block) ⇒ Object
- .erbh(str, variables = {}, options = {}) ⇒ Object
- .erbh_methods ⇒ Object
Class Method Details
.default_options ⇒ Object
17 18 19 |
# File 'lib/erbh.rb', line 17 def self. @default_options end |
.define_method(name, &block) ⇒ Object
13 14 15 |
# File 'lib/erbh.rb', line 13 def self.define_method(name, &block) @methods[name] = block end |
.erbh(str, variables = {}, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/erbh.rb', line 25 def erbh(str, variables = {}, = {}) = ERBh..merge() 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("<% @#{[:eoutvar]} = #{[:eoutvar]} %>\n" + str, **) erb.result(binding).sub(/\A\n/, '') end end |
.erbh_methods ⇒ Object
21 22 23 |
# File 'lib/erbh.rb', line 21 def self.erbh_methods @methods end |