Module: Weft
- Defined in:
- lib/weft.rb,
lib/weft/page.rb,
lib/weft/error.rb,
lib/weft/action.rb,
lib/weft/params.rb,
lib/weft/router.rb,
lib/weft/context.rb,
lib/weft/presets.rb,
lib/weft/version.rb,
lib/weft/redirect.rb,
lib/weft/registry.rb,
lib/weft/resolver.rb,
lib/weft/component.rb,
lib/weft/page/head.rb,
lib/weft/dsl/params.rb,
lib/weft/autoloading.rb,
lib/weft/dsl/actions.rb,
lib/weft/dsl/sandbox.rb,
lib/weft/dsl/updates.rb,
lib/weft/page/assets.rb,
lib/weft/dsl/triggers.rb,
lib/weft/configuration.rb,
lib/weft/router/errors.rb,
lib/weft/context/wiring.rb,
lib/weft/dsl/containers.rb,
lib/weft/dsl/inclusions.rb,
lib/weft/dsl/recoveries.rb,
lib/weft/router/actions.rb,
lib/weft/params/assembly.rb,
lib/weft/router/streaming.rb,
lib/weft/context/expansion.rb,
lib/weft/context/modifiers.rb,
lib/weft/context/traversal.rb,
lib/weft/defaults/error_page.rb,
lib/weft/router/oob_includes.rb,
lib/weft/context/interception.rb,
lib/weft/registry/eligibility.rb,
lib/weft/defaults/not_found_page.rb,
lib/weft/defaults/error_component.rb,
lib/weft/defaults/not_found_component.rb
Overview
Component-oriented hypermedia for Ruby.
Defined Under Namespace
Modules: Autoloading, DSL, Defaults, Presets Classes: Action, Component, Configuration, Context, Forbidden, HTTPError, InternalError, NotFound, Page, Params, Redirect, Registry, Resolver, Router, Unauthorized, Unprocessable
Constant Summary collapse
- Error =
Abstract base — never raise directly; use a semantic subclass. Exists for
rescue Weft::Errorto catch the whole gem-error family. Class.new(StandardError)
- InvalidConfiguration =
Raised for semantic mistakes inside
Weft.configure { |c| ... }— values of the right kind that nonetheless violate a constraint (e.g. an asset root not starting with/), or state conflicts (duplicate asset bundles). Class.new(Error)
- InvalidDefinition =
Raised for semantic mistakes in class-body DSL declarations — e.g. a page declares params but no
page_path, oradds_children_toreceives a Symbol that does not start with@. Class.new(Error)
- InvalidUsage =
Raised for semantic mistakes at render / action time — invalid input combinations or references to state that isn't there (e.g. an unknown assets bundle named at
register_stylesheet). Class.new(Error)
- AncestorNotFound =
Raised by the bang forms of the render-tree lookup (
closest!/enclosing!) when no node matches the requested criteria — the component expected an ancestor that isn't there (it should usually bedependent!and rendered only inside that ancestor). Class.new(InvalidUsage)
- MissingContainerIvar =
Raised by the
adds_children_to :@ivarmacro when build returns without ever assigning the named ivar and then a child is added — almost always means the developer declared the macro but forgot the matching assignment. Class.new(InvalidDefinition)
- NotReceived =
Raised at component construction when a
receiveskey with no declared default ends resolution valueless — the call site didn't hand it over and no other source (wire dual, inherited bag) supplied it. Class.new(InvalidUsage)
- VERSION =
"0.2.0"
Class Attribute Summary collapse
-
.logger ⇒ Object
Weft's process-wide logger.
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
-
.configure_autoloading(paths:, inflections: {}, reload: false) ⇒ Object
Set up Zeitwerk-managed autoloading (and, optionally, dev-mode reloading) for the application's own code.
-
.preset(name) ⇒ Object
Look up a registered preset by name.
-
.redirect(target, **params) ⇒ Object
Convenience wrapper for Weft::Redirect.to.
-
.register_preset(name, **defaults) ⇒ Object
Register a named interaction preset.
-
.registry ⇒ Object
The process-wide registry.
Class Attribute Details
.logger ⇒ Object
Weft's process-wide logger. In standalone mode this defaults to a $stdout
Logger at the configured log_level (:info by default) — modeling the
unified activity+error stream a 12-factor Rails container emits under
RAILS_LOG_TO_STDOUT, so deployments aggregate it like any other web
container. When mounted in Rails, set Weft.logger = Rails.logger and
this default never applies. Weft.configure applies log_level to it.
46 47 48 |
# File 'lib/weft.rb', line 46 def logger @logger ||= Logger.new($stdout) end |
Class Method Details
.configuration ⇒ Object
50 51 52 |
# File 'lib/weft.rb', line 50 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
54 55 56 57 |
# File 'lib/weft.rb', line 54 def configure yield configuration apply_configuration end |
.configure_autoloading(paths:, inflections: {}, reload: false) ⇒ Object
Set up Zeitwerk-managed autoloading (and, optionally, dev-mode reloading) for the application's own code. The imperative older sibling of configure: call it FIRST in your boot file — it builds the loader and eager-loads everything on the spot, so constants from these paths are resolvable by the time a configure block references them.
Weft.configure_autoloading(
paths: [File.join(APP_ROOT, "app", "components"),
File.join(APP_ROOT, "app", "pages")],
inflections: { "dropship_ui" => "DropshipUI" },
reload: ENV["APP_ENV"] == "development"
)
With reload: true, code changes take effect without restarting: constants reload on every request, unloaded classes are evicted from the registry the moment Zeitwerk removes them, and class-valued configuration knobs rebind to their fresh definitions. Returns the Zeitwerk::Loader.
76 77 78 |
# File 'lib/weft.rb', line 76 def configure_autoloading(paths:, inflections: {}, reload: false) Autoloading.setup(paths: paths, inflections: inflections, reload: reload) end |
.preset(name) ⇒ Object
Look up a registered preset by name. Delegates to Weft::Presets.
93 94 95 |
# File 'lib/weft.rb', line 93 def preset(name) Presets.lookup(name) end |
.redirect(target, **params) ⇒ Object
Convenience wrapper for Weft::Redirect.to.
81 82 83 |
# File 'lib/weft.rb', line 81 def redirect(target, **params) Redirect.to(target, **params) end |
.register_preset(name, **defaults) ⇒ Object
Register a named interaction preset. Delegates to Weft::Presets.
Weft.register_preset :tooltip, trigger: :hover, swap: :fill
88 89 90 |
# File 'lib/weft.rb', line 88 def register_preset(name, **defaults) Presets.register(name, **defaults) end |
.registry ⇒ Object
The process-wide registry. Defined here rather than in the gem root
because registration happens at class-definition time (the inherited
hooks on Component and Page call this), so any file that defines a
subclass needs the accessor resolvable at load.
9 10 11 |
# File 'lib/weft/registry.rb', line 9 def registry @registry ||= Registry.new end |