module Utopia

Classes and Modules

class Application < Protocol::HTTP::Middleware

The protocol-facing entrypoint for a Utopia application.

class Components

Installs JavaScript packages into the public components directory. Package contents are copied from dist when it exists, otherwise from the package root.

module Content

Builds middleware for serving filesystem-backed dynamic content.

module Controller

A middleware which loads controller classes and invokes functionality based on the requested path.

module Exceptions

Middleware for handling exceptional situations.

module Extensions
module HTTP

HTTP protocol implementation.

class ImportMap

Represents an import map for JavaScript modules with support for URI and relative path resolution. Import maps allow you to control how JavaScript imports are resolved, supporting both absolute URLs and relative paths with proper context-aware resolution.

module Localization

Computes request localization preferences and resolves localized resources.

class Path

Represents a path as an array of path components. Useful for efficient URL manipulation.

module Redirection

A middleware which assists with redirecting from one path to another.

class Request

Utopia's application-facing request wrapper.

module Response

Response helpers for Utopia applications.

module Session

Provides cookie-backed session middleware.

class Setup

Used for setting up a Utopia web application, typically via config/environment.rb

class Shell

This is designed to be used with the corresponding bake task.

module Static

A middleware which serves static files from the specified root directory.

Definitions

PAGES_PATH = "pages".freeze

The default pages path for module Utopia::Content middleware.

def self.default_root(subdirectory = PAGES_PATH, pwd = Dir.pwd)

The default root directory for middleware to operate within, e.g. the web-site directory. Convention over configuration.

Implementation

def self.default_root(subdirectory = PAGES_PATH, pwd = Dir.pwd)
	File.expand_path(subdirectory, pwd)
end

def self.default_path(*arguments)

The same as Utopia.default_root but returns an instance of class Utopia::Path.

Implementation

def self.default_path(*arguments)
	Path[default_root(*arguments)]
end

def self.Path(path)

Coerce a value into a class Utopia::Path.

Signature

parameter path Utopia::Path | String

The path.

returns Path | Nil

The coerced path.

Implementation

def self.Path(path)
	Path.create(path)
end

def self.setup(root = nil, **options)

You can call this method exactly once per process.

Implementation

def self.setup(root = nil, **options)
	if @setup
		raise RuntimeError, "Utopia already setup!"
	end
	
	# We extract the root from the caller of this method:
	if root.nil?
		config_root = File.dirname(caller[0])
		root = File.dirname(config_root)
	end
	
	@setup = Setup.new(root, **options)
	
	@setup.apply!
	
	return @setup
end