Class: Jasonette::Items

Inherits:
Base
  • Object
show all
Defined in:
lib/jasonette/core/items.rb

Direct Known Subclasses

Body::Layers, Components

Constant Summary

Constants included from Properties

Properties::DEFAULT_IS_ARRAY, Properties::TYPES

Instance Attribute Summary

Attributes inherited from Base

#attributes, #context

Instance Method Summary collapse

Methods inherited from Base

#_method, #array!, #as_json, #attr_value, #attributes!, #empty?, #encode, #extract!, #implicit_set!, #initialize, #inline, #klass, #method_missing, #set!, #with_attributes

Methods included from Properties

#all_instance_variable_set, #create_new_klass, #get_default_for_property, #get_ivar, #has_any_property_type?, #has_property?, included, #ivar_for_property, #klass_for_property, #merge_properties, #parent_jasonette, #parent_jasonette_set, #prop, #properties_empty?, #property_get!, #property_names, #property_sender, #property_set!, #property_variables, #set_ivar

Constructor Details

This class inherits a constructor from Jasonette::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jasonette::Base

Instance Method Details

#button(caption = nil, is_url = false, skip_type = false) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# 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") ⇒ Object



31
32
33
34
35
36
37
38
# 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) ⇒ Object



4
5
6
7
8
9
10
11
# 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") ⇒ Object



61
62
63
64
65
66
67
# 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) ⇒ Object



98
99
100
101
102
103
104
# 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) ⇒ Object



106
107
108
109
110
111
112
# 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) ⇒ Object



51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



89
90
91
92
93
94
95
96
# 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) ⇒ Object



13
14
15
16
17
18
19
20
# 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) ⇒ Object



79
80
81
82
83
84
85
86
87
# 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) ⇒ Object



69
70
71
72
73
74
75
76
77
# 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) ⇒ Object



22
23
24
25
26
27
28
29
# 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