Class: Charming::View

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/view.rb

Overview

View is the base class for all screen view implementations. It provides assign injection (via ‘initialize`), rendering hooks, layout composition helpers (`row`, `column`, `render_component`, `yield_content`), and access to controller theme, style, and focus state from within views.

Direct Known Subclasses

Component

Instance Method Summary collapse

Constructor Details

#initialize(**assigns) ⇒ View

Initializes the view with named assigns injected as instance-local accessor methods via ‘define_singleton_method`. Called when a controller instantiates a view for rendering.



10
11
12
13
# File 'lib/charming/view.rb', line 10

def initialize(**assigns)
  @assigns = assigns
  define_assign_readers
end

Instance Method Details

#focused?(slot) ⇒ Boolean

Delegates focus checking to the controller in assigns, allowing views to determine which slot (sidebar, content) has focus.

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/charming/view.rb', line 26

def focused?(slot)
  ctrl = assigns[:focus_controller] || assigns[:controller]
  ctrl ? ctrl.focused?(slot) : false
end

#layout_assignsObject

Returns all view assigns as a hash, used by layouts to compose the full template (content + screen + controller).



16
17
18
# File 'lib/charming/view.rb', line 16

def layout_assigns
  assigns
end

#renderObject

Renders the view’s body. Default is empty — subclasses override to return visible text.



21
22
23
# File 'lib/charming/view.rb', line 21

def render
  ""
end