Module: Presently::Environment::Application

Includes:
Lively::Environment::Application
Defined in:
lib/presently/environment/application.rb

Overview

The environment configuration for a Presently application server.

Extends the Lively environment with Presently-specific middleware and configuration. Override #slides_root and #templates_roots to customize paths.

Instance Method Summary collapse

Instance Method Details

#applicationObject

The application class to use.



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

def application
	Presently::Application
end

#middlewareObject

Build the middleware stack with Presently’s public assets.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/presently/environment/application.rb', line 41

def middleware
	application = self.application
	slides_root = self.slides_root
	templates_roots = self.templates_roots
	root = self.root
	
	::Protocol::HTTP::Middleware.build do |builder|
		# Serve assets from the user's public directory:
		builder.use Lively::Assets, root: File.expand_path("public", root)
		
		# Serve Presently's bundled assets (CSS, JS, components, etc.):
		builder.use Lively::Assets, root: File.expand_path("../../../public", __dir__)
		
		# Serve Lively's built-in assets (Live.js, morphdom, etc.):
		builder.use Lively::Assets, root: File.expand_path("public", Gem.loaded_specs["lively"].full_gem_path)
		
		builder.use application,
			slides_root: slides_root,
			templates_roots: templates_roots
	end
end

#slides_rootObject

The root directory containing slide Markdown files.



21
22
23
# File 'lib/presently/environment/application.rb', line 21

def slides_root
	File.expand_path("slides", self.root)
end

#templates_rootsObject

Additional directories to search for slide templates. These are searched before the gem’s bundled templates, allowing selective overrides without duplicating all templates.



29
30
31
# File 'lib/presently/environment/application.rb', line 29

def templates_roots
	[File.expand_path("templates", self.root)].select{|d| File.directory?(d)}
end