Sha256: 2c2171cf6678195153e05413460e5ab7116a8995a06c5f253a12cda0b9e3a139

Contents?: true

Size: 748 Bytes

Versions: 49

Compression:

Stored size: 748 Bytes

Contents

# With if bindings, we need to track each branch, which is on the
# same scope level as the original if statement.  We use this class
# to track each branch.

require 'volt/server/binding_setup'
class IfBindingSetup < BindingSetup
  def initialize
    @branches = []
  end
  
  def add_branch(content, template_name)
    @branches << [content, template_name]
  end
  
  def to_setup_code
    branches = @branches.map do |branch|
      content = branch[0]
      if content == nil
        content = nil.inspect
      else
        content = "Proc.new { #{branch[0]} }"
      end
      
      "[#{content}, #{branch[1].inspect}]"
    end.join(', ')
    
    "lambda { |target, context, id| IfBinding.new(target, context, id, [#{branches}]) }"
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
volt-0.3.3 lib/volt/server/if_binding_setup.rb
volt-0.3.2 lib/volt/server/if_binding_setup.rb
volt-0.3.1 lib/volt/server/if_binding_setup.rb
volt-0.3.0 lib/volt/server/if_binding_setup.rb
volt-0.2.9 lib/volt/server/if_binding_setup.rb
volt-0.2.7 lib/volt/server/if_binding_setup.rb
volt-0.2.5 lib/volt/server/if_binding_setup.rb
volt-0.2.4 lib/volt/server/if_binding_setup.rb
volt-0.2.3 lib/volt/server/if_binding_setup.rb