Class: Weft::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/weft/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiated internally by Weft.configuration. Configure Weft via Weft.configure { |c| ... } rather than constructing this directly.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/weft/configuration.rb', line 23

def initialize
  @component_path = DEFAULT_COMPONENT_PATH
  @include_htmx = true
  @include_sse_ext = :auto
  @auto_reload = false
  @reload_paths = []
  @router_logging = false
  @verbose_error_pages = true
  @htmx_errors = :fragment
  @log_level = :info
  @stream_suffix = "_stream"
  @static_assets = {}
end

Instance Attribute Details

#auto_reloadObject

Returns the value of attribute auto_reload.



17
18
19
# File 'lib/weft/configuration.rb', line 17

def auto_reload
  @auto_reload
end

#component_pathObject

Returns the value of attribute component_path.



16
17
18
# File 'lib/weft/configuration.rb', line 16

def component_path
  @component_path
end

#error_componentObject

Lazy defaults — resolved on first read so Weft::Defaults classes load before the Configuration class is required. Assignment sticks.



121
122
123
# File 'lib/weft/configuration.rb', line 121

def error_component
  @error_component ||= Weft::Defaults::ErrorComponent
end

#error_pageObject



125
126
127
# File 'lib/weft/configuration.rb', line 125

def error_page
  @error_page ||= Weft::Defaults::ErrorPage
end

#htmx_errorsObject

Returns the value of attribute htmx_errors.



16
17
18
# File 'lib/weft/configuration.rb', line 16

def htmx_errors
  @htmx_errors
end

#include_htmxObject

Returns the value of attribute include_htmx.



17
18
19
# File 'lib/weft/configuration.rb', line 17

def include_htmx
  @include_htmx
end

#include_sse_extObject

Returns the value of attribute include_sse_ext.



16
17
18
# File 'lib/weft/configuration.rb', line 16

def include_sse_ext
  @include_sse_ext
end

#log_levelObject

Returns the value of attribute log_level.



16
17
18
# File 'lib/weft/configuration.rb', line 16

def log_level
  @log_level
end

#not_found_componentObject



133
134
135
# File 'lib/weft/configuration.rb', line 133

def not_found_component
  @not_found_component ||= Weft::Defaults::NotFoundComponent
end

#not_found_pageObject



129
130
131
# File 'lib/weft/configuration.rb', line 129

def not_found_page
  @not_found_page ||= Weft::Defaults::NotFoundPage
end

#reload_pathsObject

Returns the value of attribute reload_paths.



17
18
19
# File 'lib/weft/configuration.rb', line 17

def reload_paths
  @reload_paths
end

#router_loggingObject

Returns the value of attribute router_logging.



17
18
19
# File 'lib/weft/configuration.rb', line 17

def router_logging
  @router_logging
end

#stream_suffixObject

Returns the value of attribute stream_suffix.



16
17
18
# File 'lib/weft/configuration.rb', line 16

def stream_suffix
  @stream_suffix
end

#verbose_error_pagesObject

Returns the value of attribute verbose_error_pages.



17
18
19
# File 'lib/weft/configuration.rb', line 17

def verbose_error_pages
  @verbose_error_pages
end

Instance Method Details

#resolved_log_levelObject

Resolves the configured log_level symbol to its Logger severity constant (e.g. :warn -> Logger::WARN). Used by Weft.configure to set logger.level.



90
91
92
# File 'lib/weft/configuration.rb', line 90

def resolved_log_level
  LOG_LEVELS.fetch(@log_level)
end

#static_assets(name: nil, root: nil, from: nil) ⇒ Object

Register a directory to serve as static assets at a URL prefix, under a logical bundle name. The bundle name is the stable reference used at call sites (register_stylesheet "css/app.css", assets: :app); the root/from pair can be reconfigured (e.g. from env vars in production) without touching call sites.

Multi-call: each call adds a => {root:, from:} entry. Raises ArgumentError on duplicate name or duplicate root.

c.static_assets root: "/static", from: File.join(APP_ROOT, "public")
# name: defaults to :default — call sites without an `assets:` kwarg
# implicitly resolve against this bundle.

c.static_assets name: :vendor, root: "/vendor",
              from: File.join(APP_ROOT, "vendor", "assets")

Called with no arguments, returns a copy of the registered bundles as a hash (name => from:). Used by the apply step and the page-side resolve_asset_url logic.



113
114
115
116
117
# File 'lib/weft/configuration.rb', line 113

def static_assets(name: nil, root: nil, from: nil)
  return @static_assets.transform_values(&:dup) if name.nil? && root.nil? && from.nil?

  register_static_assets_bundle(name: name, root: root, from: from)
end