ProjectSource

Utopia

Utopia is a web application framework built on top of Rack.

Nested

Definitions

PAGES_PATH = 'pages'.freeze

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

VARIABLES_KEY = 'utopia.variables'.freeze

This is used for shared controller variables which get consumed by the 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

Locale

A structured representation of locale based on RFC3066.

Implementation

Locale = Struct.new(:language, :country, :variant) do
	def to_s
		to_a.compact.join('-')
	end
	
	def self.dump(instance)
		if instance
			instance.to_s
		end
	end
	
	def self.load(instance)
		if instance.is_a? String
			self.new(*instance.split('-', 3))
		elsif instance.is_a? Array
			return self.new(*instance)
		elsif instance.is_a? self
			return instance.frozen? ? instance : instance.dup
		end
	end
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