Class: Presently::Application

Inherits:
Lively::Application
  • Object
show all
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

Constructor Details

#initialize(delegate, slides_root: "slides", templates_roots: []) ⇒ Application

Initialize a new Presently application.



26
27
28
29
30
31
# File 'lib/presently/application.rb', line 26

def initialize(delegate, slides_root: "slides", templates_roots: [])
	@slides_root = slides_root
	@templates_roots = templates_roots
	
	super(delegate)
end

Instance Method Details

#allowed_viewsObject

The view classes that this application allows.



35
36
37
# File 'lib/presently/application.rb', line 35

def allowed_views
	[DisplayView, PresenterView]
end

#body(request) ⇒ Object

Create the body view for the given request path.



65
66
67
68
69
70
71
72
# File 'lib/presently/application.rb', line 65

def body(request)
	case request.path
	when "/"
		DisplayView.new(controller: controller)
	when "/presenter"
		PresenterView.new(controller: controller)
	end
end

#controllerObject

The shared presentation controller.



47
48
49
50
51
52
53
54
# File 'lib/presently/application.rb', line 47

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.



77
78
79
80
81
82
83
84
# File 'lib/presently/application.rb', line 77

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

#stateObject

The shared state passed to all views via the resolver.



41
42
43
# File 'lib/presently/application.rb', line 41

def state
	{controller: controller}
end

#titleObject

The application title shown in the browser.



58
59
60
# File 'lib/presently/application.rb', line 58

def title
	"Presently"
end