Class: Presently::Application
- Inherits:
-
Lively::Application
- Object
- Lively::Application
- Presently::Application
- Defined in:
- lib/presently/application.rb
Overview
The main Presently application middleware.
Handles routing for the display view (‘/`), presenter view (`/presenter`), and WebSocket connections (`/live`). Creates a shared PresentationController that keeps all connected clients in sync.
Instance Method Summary collapse
-
#body(request) ⇒ Object
Create the body view for the given request path.
-
#controller ⇒ Object
The shared presentation controller.
-
#handle(request) ⇒ Object
Handle an HTTP request by rendering the appropriate page.
-
#initialize(delegate, slides_root: "slides", templates_root: nil, **options) ⇒ Application
constructor
Initialize a new Presently application.
-
#title ⇒ Object
The application title shown in the browser.
Constructor Details
#initialize(delegate, slides_root: "slides", templates_root: nil, **options) ⇒ Application
Initialize a new Presently application.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/presently/application.rb', line 54 def initialize(delegate, slides_root: "slides", templates_root: nil, **) presentation = Presentation.load(, templates_root: templates_root) state = State.new resolver = Resolver.new( controller: PresentationController.new(presentation, state: state), ).tap do |resolver| resolver.allow(DisplayView, PresenterView) end super(delegate, resolver: resolver, **) end |
Instance Method Details
#body(request) ⇒ Object
Create the body view for the given request path.
83 84 85 86 87 88 89 90 |
# File 'lib/presently/application.rb', line 83 def body(request) case request.path when "/" DisplayView.new(controller: controller) when "/presenter" PresenterView.new(controller: controller) end end |
#controller ⇒ Object
The shared presentation controller.
70 71 72 |
# File 'lib/presently/application.rb', line 70 def controller resolver.state[:controller] end |
#handle(request) ⇒ Object
Handle an HTTP request by rendering the appropriate page.
95 96 97 98 99 100 101 102 |
# File 'lib/presently/application.rb', line 95 def handle(request) if body = self.body(request) page = Page.new(title: title, body: body) return Protocol::HTTP::Response[200, [], [page.call]] else return Protocol::HTTP::Response[404, [], ["Not Found"]] end end |
#title ⇒ Object
The application title shown in the browser.
76 77 78 |
# File 'lib/presently/application.rb', line 76 def title "Presently" end |