Module: Primrose::Helpers
- Defined in:
- lib/primrose/helpers.rb
Instance Method Summary collapse
-
#button(label:, action:, **opts) ⇒ Object
Specific helpers.
- #checkbox(label:, checked: false, **opts) ⇒ Object
-
#component(name, **args, &block) ⇒ Object
Load a component dynamically based on the name.
- #form(elements:, method:, style_class: nil, action: nil, **opts, &block) ⇒ Object
-
#hidden_field(name:, value:, **opts) ⇒ Object
def grid_layout(rows:, columns:, **opts) component(‘GridLayout’, rows: rows, columns: columns, **opts) end.
-
#list(items:, **opts) ⇒ Object
def table(headers:, rows:, **opts) component(‘Table’, headers: headers, rows: rows, **opts) end.
- #navbar(links:, **opts) ⇒ Object
- #text_field(placeholder:, **opts) ⇒ Object
Instance Method Details
#button(label:, action:, **opts) ⇒ Object
Specific helpers
30 31 32 |
# File 'lib/primrose/helpers.rb', line 30 def (label:, action:, **opts) component('Button', label: label, action: action, **opts) end |
#checkbox(label:, checked: false, **opts) ⇒ Object
42 43 44 |
# File 'lib/primrose/helpers.rb', line 42 def checkbox(label:, checked: false, **opts) component('Checkbox', label: label, checked: checked, **opts) end |
#component(name, **args, &block) ⇒ Object
Load a component dynamically based on the name
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/primrose/helpers.rb', line 16 def component(name, **args, &block) klass = Object.const_get("Primrose::Components::#{name}") begin instance = klass.new(**args) rescue ArgumentError => e puts "Error while initializing #{klass}: #{e.}" puts "Backtrace: #{e.backtrace.join("\n")}" raise e end block&.call(instance) instance.render end |
#form(elements:, method:, style_class: nil, action: nil, **opts, &block) ⇒ Object
67 68 69 |
# File 'lib/primrose/helpers.rb', line 67 def form(elements:, method:, style_class: nil, action: nil, **opts, &block) component('Form', elements: elements, method: method, style_class: style_class, action: action, **opts, &block) end |
#hidden_field(name:, value:, **opts) ⇒ Object
def grid_layout(rows:, columns:, **opts)
component('GridLayout', rows: rows, columns: columns, **opts)
end
62 63 64 65 |
# File 'lib/primrose/helpers.rb', line 62 def hidden_field(name:, value:, **opts) puts "Creating hidden field with name #{name} and value #{value}" component('HiddenField', name: name, value: value) end |
#list(items:, **opts) ⇒ Object
def table(headers:, rows:, **opts)
component('Table', headers: headers, rows: rows, **opts)
end
54 55 56 |
# File 'lib/primrose/helpers.rb', line 54 def list(items:, **opts) component('List', items: items, **opts) end |
#navbar(links:, **opts) ⇒ Object
34 35 36 |
# File 'lib/primrose/helpers.rb', line 34 def (links:, **opts) component('Navbar', links: links, **opts) end |
#text_field(placeholder:, **opts) ⇒ Object
38 39 40 |
# File 'lib/primrose/helpers.rb', line 38 def text_field(placeholder:, **opts) component('TextField', placeholder: placeholder, **opts) end |