PresentlySourcePresentlyEnvironmentApplication

module Application

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.

Definitions

def slides_root

The root directory containing slide Markdown files.

Signature

returns String

Absolute path to the slides root.

Implementation

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

def templates_roots

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

Signature

returns Array(String)

Ordered list of template directories.

Implementation

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

def application

The application class to use.

Signature

returns Class

The Presently application class.

Implementation

def application
	Presently::Application
end

def middleware

Build the middleware stack with Presently's public assets.

Signature

returns Protocol::HTTP::Middleware

The complete middleware stack.

Implementation

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