Class: Presently::Application
- Inherits:
-
Lively::Application
- Object
- Lively::Application
- Presently::Application
- Defined in:
- lib/presently/application.rb
Overview
Represents 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
-
#allowed_views ⇒ Object
The view classes that this application allows.
-
#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_roots: []) ⇒ Application
constructor
Initialize a new Presently application.
-
#state ⇒ Object
The shared state passed to all views via the resolver.
-
#title ⇒ Object
The application title shown in the browser.
Constructor Details
#initialize(delegate, slides_root: "slides", templates_roots: []) ⇒ Application
Initialize a new Presently application.
28 29 30 31 32 33 |
# File 'lib/presently/application.rb', line 28 def initialize(delegate, slides_root: "slides", templates_roots: []) @slides_root = @templates_roots = templates_roots super(delegate) end |
Instance Method Details
#allowed_views ⇒ Object
The view classes that this application allows.
37 38 39 |
# File 'lib/presently/application.rb', line 37 def allowed_views [DisplayView, PresenterView] end |
#body(request) ⇒ Object
Create the body view for the given request path.
67 68 69 70 71 72 73 74 |
# File 'lib/presently/application.rb', line 67 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.
49 50 51 52 53 54 55 56 |
# File 'lib/presently/application.rb', line 49 def controller @controller ||= begin templates = Templates.for(@templates_roots) presentation = Presentation.load(@slides_root, templates: templates) PresentationController.new(presentation, state: State.new) end end |
#handle(request) ⇒ Object
Handle an HTTP request by rendering the appropriate page.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/presently/application.rb', line 79 def handle(request) path, query = request.path.split("?", 2) if path == "/export" = Export.(query) presentation = Presentation.load(@slides_root, templates: controller.templates) export = Export.new(presentation: presentation, **) return Protocol::HTTP::Response[200, [["content-type", "text/html"]], [export.call]] end 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 |
#state ⇒ Object
The shared state passed to all views via the resolver.
43 44 45 |
# File 'lib/presently/application.rb', line 43 def state {controller: controller} end |
#title ⇒ Object
The application title shown in the browser.
60 61 62 |
# File 'lib/presently/application.rb', line 60 def title "Presently" end |