class Jasonette::Items

Public Instance Methods

button(caption=nil, is_url=false, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 40
def button caption=nil, is_url=false, skip_type=false
  item = Jasonette::Item.new(context) do
    type "button" unless skip_type
    unless caption.nil?
      is_url ? (url caption) : (text caption)
    end
    encode(&::Proc.new) if block_given?
  end
  append item
end
image(uri=nil, skip_type=false, url_key="url") click to toggle source
# File lib/jasonette/core/items.rb, line 31
def image uri=nil, skip_type=false, url_key="url"
  item = Jasonette::Item.new(context) do
    type "image" unless skip_type
    set! url_key, uri unless uri.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end
label(caption=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 4
def label caption=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    text caption unless caption.nil?
    type "label" unless skip_type
    encode(&::Proc.new) if block_given?
  end
  append item
end
layout(orientation="vertical") click to toggle source
# File lib/jasonette/core/items.rb, line 61
def layout orientation="vertical"
  item = Jasonette::Layout.new(context) do
    type orientation
    encode(&::Proc.new) if block_given?
  end
  append item
end
map(skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 98
def map skip_type=false
  item = Jasonette::Map.new(context) do
    type "map" unless skip_type
    encode(&::Proc.new) if block_given?
  end
  append item
end
merge!(items) click to toggle source
# File lib/jasonette/core/items.rb, line 106
def merge! items
  item = Jasonette::Item.new(context) do
    merge! items
    encode(&::Proc.new) if block_given?
  end
  append item
end
slider(name, value=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 51
def slider name, value=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    type "slider" unless skip_type
    name name
    value value unless value.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end
space(height=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 89
def space height=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    type "space" unless skip_type
    height height unless height.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end
text(caption=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 13
def text caption=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    text caption unless caption.nil?
    type "text" unless skip_type
    encode(&::Proc.new) if block_given?
  end
  append item
end
textarea(name=nil, value=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 79
def textarea name=nil, value=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    type "textarea" unless skip_type
    name name unless name.nil?
    value value unless value.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end
textfield(name=nil, value=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 69
def textfield name=nil, value=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    type "textfield" unless skip_type
    name name unless name.nil?
    value value unless value.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end
video(uri=nil, skip_type=false) click to toggle source
# File lib/jasonette/core/items.rb, line 22
def video uri=nil, skip_type=false
  item = Jasonette::Item.new(context) do
    type "video" unless skip_type
    file_url uri unless uri.nil?
    encode(&::Proc.new) if block_given?
  end
  append item
end

Private Instance Methods

append(builder) click to toggle source
# File lib/jasonette/core/items.rb, line 116
def append builder
  @attributes = [] if @attributes.empty?
  raise "HashError : You may have used `set!` before" if ::Hash === @attributes
  @attributes << builder.attributes!
  builder
end