Class: Sandals::View
- Inherits:
-
Object
- Object
- Sandals::View
- Defined in:
- lib/sandals/view.rb
Constant Summary collapse
- UNSET =
BindingResolver::UNSET
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #button(content, &action) ⇒ Object
- #checkbox(label, checked: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #em(content) ⇒ Object
- #error(content) ⇒ Object
- #file_field(label, error: nil, &action) ⇒ Object
- #flow(&block) ⇒ Object
- #form(&block) ⇒ Object
- #image(source, alt: "") ⇒ Object
-
#initialize ⇒ View
constructor
A new instance of View.
- #link(content, to:) ⇒ Object
- #notice(content) ⇒ Object
- #number_field(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #para(*parts) ⇒ Object
- #radio(label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #select(label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #stack(&block) ⇒ Object
- #strong(content) ⇒ Object
- #submit(content, &action) ⇒ Object
- #subtitle(content) ⇒ Object
- #table(headers:, rows:) ⇒ Object
- #text_area(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #text_field(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
- #title(content) ⇒ Object
Constructor Details
#initialize ⇒ View
Returns a new instance of View.
11 12 13 14 15 |
# File 'lib/sandals/view.rb', line 11 def initialize @children = [] @containers = [self] @next_control_id = 0 end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/sandals/view.rb', line 9 def children @children end |
Instance Method Details
#button(content, &action) ⇒ Object
139 140 141 |
# File 'lib/sandals/view.rb', line 139 def (content, &action) add Button.new(control_id("button"), content, action:) end |
#checkbox(label, checked: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sandals/view.rb', line 91 def checkbox( label, checked: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) checked, error, action = resolve_binding( model:, bind:, value: checked, error:, action:, default: false ) add Checkbox.new(control_id("checkbox"), label, checked:, error:, action:) end |
#em(content) ⇒ Object
155 156 157 |
# File 'lib/sandals/view.rb', line 155 def em(content) Emphasis.new(content) end |
#error(content) ⇒ Object
29 30 31 |
# File 'lib/sandals/view.rb', line 29 def error(content) add Error.new(content) end |
#file_field(label, error: nil, &action) ⇒ Object
135 136 137 |
# File 'lib/sandals/view.rb', line 135 def file_field(label, error: nil, &action) add FileField.new(control_id("file-field"), label, error:, action:) end |
#flow(&block) ⇒ Object
163 164 165 |
# File 'lib/sandals/view.rb', line 163 def flow(&block) container Flow.new, &block end |
#form(&block) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/sandals/view.rb', line 167 def form(&block) if @containers.any? { |container| container.is_a?(Form) } raise ArgumentError, "forms cannot be nested" end container Form.new, &block end |
#image(source, alt: "") ⇒ Object
37 38 39 |
# File 'lib/sandals/view.rb', line 37 def image(source, alt: "") add Image.new(source, alt:) end |
#link(content, to:) ⇒ Object
41 42 43 |
# File 'lib/sandals/view.rb', line 41 def link(content, to:) add Link.new(content, to:) end |
#notice(content) ⇒ Object
33 34 35 |
# File 'lib/sandals/view.rb', line 33 def notice(content) add Notice.new(content) end |
#number_field(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sandals/view.rb', line 63 def number_field( label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) value, error, action = resolve_binding( model:, bind:, value:, error:, action:, default: nil ) add NumberField.new(control_id("number-field"), label, value:, error:, action:) end |
#para(*parts) ⇒ Object
25 26 27 |
# File 'lib/sandals/view.rb', line 25 def para(*parts) add Para.new(parts) end |
#radio(label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/sandals/view.rb', line 120 def radio( label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) value, error, action = resolve_binding( model:, bind:, value:, error:, action:, default: nil ) add Radio.new(control_id("radio"), label, options:, value:, error:, action:) end |
#select(label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sandals/view.rb', line 105 def select( label, options:, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) value, error, action = resolve_binding( model:, bind:, value:, error:, action:, default: nil ) add Select.new(control_id("select"), label, options:, value:, error:, action:) end |
#stack(&block) ⇒ Object
159 160 161 |
# File 'lib/sandals/view.rb', line 159 def stack(&block) container Stack.new, &block end |
#strong(content) ⇒ Object
151 152 153 |
# File 'lib/sandals/view.rb', line 151 def strong(content) Strong.new(content) end |
#submit(content, &action) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/sandals/view.rb', line 143 def submit(content, &action) unless @containers.any? { |container| container.is_a?(Form) } raise ArgumentError, "submit must be inside a form" end add Submit.new(control_id("submit"), content, action:) end |
#subtitle(content) ⇒ Object
21 22 23 |
# File 'lib/sandals/view.rb', line 21 def subtitle(content) add Subtitle.new(content) end |
#table(headers:, rows:) ⇒ Object
45 46 47 |
# File 'lib/sandals/view.rb', line 45 def table(headers:, rows:) add Table.new(headers:, rows:) end |
#text_area(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sandals/view.rb', line 77 def text_area( label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) value, error, action = resolve_binding( model:, bind:, value:, error:, action:, default: "" ) add TextArea.new(control_id("text-area"), label, value:, error:, action:) end |
#text_field(label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sandals/view.rb', line 49 def text_field( label, value: UNSET, error: UNSET, model: UNSET, bind: UNSET, &action ) value, error, action = resolve_binding( model:, bind:, value:, error:, action:, default: "" ) add TextField.new(control_id("text-field"), label, value:, error:, action:) end |