Class: Charming::Presentation::View

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/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, TemplateView

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.



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

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)


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

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).



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

def layout_assigns
  assigns
end

#renderObject

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



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

def render
  ""
end