Module: DR::Eruby::BindingHelper
Constant Summary collapse
- EMPTY_BINDING =
empty binding (at first) that stays the same and can be shared
empty_binding
- BLANK_OBJECT =
Object.new
Instance Method Summary collapse
-
#add_variables(variables, _binding = empty_binding) ⇒ Object
add variables values to a binding; variables is a Hash.
-
#empty_binding ⇒ Object
complement TOPLEVEL_BINDING.
-
#local_extraction(local_keys, context_name: '_context') ⇒ Object
From Tilt/template.rb return a string extracting local_keys from a hash named _context.
Instance Method Details
#add_variables(variables, _binding = empty_binding) ⇒ Object
add variables values to a binding; variables is a Hash
18 19 20 21 |
# File 'lib/dr/base/eruby.rb', line 18 def add_variables(variables, _binding=empty_binding) eval variables.collect{|k,v| "#{k} = variables[#{k.inspect}]; "}.join, _binding _binding end |
#empty_binding ⇒ Object
complement TOPLEVEL_BINDING
6 7 8 9 10 11 12 |
# File 'lib/dr/base/eruby.rb', line 6 def empty_binding #wraps into anonymous module so that 'def foo' do not pollute namespace Module.new do #regenerate a new binding return binding end end |
#local_extraction(local_keys, context_name: '_context') ⇒ Object
From Tilt/template.rb return a string extracting local_keys from a hash named _context
25 26 27 28 29 30 31 32 33 |
# File 'lib/dr/base/eruby.rb', line 25 def local_extraction(local_keys, context_name: '_context') local_keys.map do |k| if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/ "#{k} = #{context_name}[#{k.inspect}]" else raise "invalid locals key: #{k.inspect} (keys must be variable names)" end end.join("\n")+"\n" end |