Module: Chamomile::ViewDSL
- Included in:
- Application
- Defined in:
- lib/chamomile/view_dsl.rb
Overview
Instance methods for building layout trees from view. Included by Application — all methods run in the model's own context, so @ivars, quit, tick, etc. work naturally.
Instance Method Summary collapse
- #horizontal(align: :top, &block) ⇒ Object
- #list(items, **opts) ⇒ Object
- #panel(title: nil, width: nil, border: :rounded, color: nil, focused: false, &block) ⇒ Object
- #raw(string) ⇒ Object
- #spinner(**opts) ⇒ Object
- #status_bar(content, **opts) ⇒ Object
- #table(data, **opts) ⇒ Object
- #text(content, **opts) ⇒ Object
- #vertical(align: :left, &block) ⇒ Object
Instance Method Details
#horizontal(align: :top, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chamomile/view_dsl.rb', line 19 def horizontal(align: :top, &block) layout = Layout::Horizontal.new(align: align) _layout_stack.push(layout) yield _layout_stack.pop _layout_stack.empty? ? layout : (_layout_stack.last.add(layout) && nil) rescue StandardError _layout_stack.pop raise end |
#list(items, **opts) ⇒ Object
46 47 48 |
# File 'lib/chamomile/view_dsl.rb', line 46 def list(items, **opts) _add_to_stack(Layout::List.new(items, **opts)) end |
#panel(title: nil, width: nil, border: :rounded, color: nil, focused: false, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chamomile/view_dsl.rb', line 30 def panel(title: nil, width: nil, border: :rounded, color: nil, focused: false, &block) = Layout::Panel.new(title: title, width: width, border: border, color: color, focused: focused) _layout_stack.push() block.call if block_given? _layout_stack.pop _layout_stack.empty? ? : (_layout_stack.last.add() && nil) rescue StandardError _layout_stack.pop raise end |
#raw(string) ⇒ Object
62 63 64 |
# File 'lib/chamomile/view_dsl.rb', line 62 def raw(string) _add_to_stack(Layout::Raw.new(string)) end |
#spinner(**opts) ⇒ Object
58 59 60 |
# File 'lib/chamomile/view_dsl.rb', line 58 def spinner(**opts) _add_to_stack(Layout::Spinner.new(**opts)) end |
#status_bar(content, **opts) ⇒ Object
54 55 56 |
# File 'lib/chamomile/view_dsl.rb', line 54 def (content, **opts) _add_to_stack(Layout::StatusBar.new(content, **opts)) end |
#table(data, **opts) ⇒ Object
50 51 52 |
# File 'lib/chamomile/view_dsl.rb', line 50 def table(data, **opts) _add_to_stack(Layout::Table.new(data, **opts)) end |
#text(content, **opts) ⇒ Object
42 43 44 |
# File 'lib/chamomile/view_dsl.rb', line 42 def text(content, **opts) _add_to_stack(Layout::Text.new(content, **opts)) end |
#vertical(align: :left, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/chamomile/view_dsl.rb', line 8 def vertical(align: :left, &block) layout = Layout::Vertical.new(align: align) _layout_stack.push(layout) yield _layout_stack.pop _layout_stack.empty? ? layout : (_layout_stack.last.add(layout) && nil) rescue StandardError _layout_stack.pop raise end |