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.5.18 lib/volt/server/if_binding_setup.rb
volt-0.5.17 lib/volt/server/if_binding_setup.rb
volt-0.5.16 lib/volt/server/if_binding_setup.rb
volt-0.5.15 lib/volt/server/if_binding_setup.rb
volt-0.5.14 lib/volt/server/if_binding_setup.rb
volt-0.5.13 lib/volt/server/if_binding_setup.rb
volt-0.5.12 lib/volt/server/if_binding_setup.rb
volt-0.5.11 lib/volt/server/if_binding_setup.rb
volt-0.5.10 lib/volt/server/if_binding_setup.rb
volt-0.5.9 lib/volt/server/if_binding_setup.rb
volt-0.5.8 lib/volt/server/if_binding_setup.rb
volt-0.5.7 lib/volt/server/if_binding_setup.rb
volt-0.5.6 lib/volt/server/if_binding_setup.rb
volt-0.5.4 lib/volt/server/if_binding_setup.rb
volt-0.5.3 lib/volt/server/if_binding_setup.rb
volt-0.5.2 lib/volt/server/if_binding_setup.rb
volt-0.5.1 lib/volt/server/if_binding_setup.rb
volt-0.5.0 lib/volt/server/if_binding_setup.rb
volt-0.4.18 lib/volt/server/if_binding_setup.rb
volt-0.4.17 lib/volt/server/if_binding_setup.rb