Class: LexxyVariables::Configuration
- Inherits:
-
Object
- Object
- LexxyVariables::Configuration
- Defined in:
- lib/lexxy_variables/configuration.rb
Overview
Host-supplied policy. The gem ships working defaults, so the smallest
integration is just config.catalog = [...]. Everything else is optional.
LexxyVariables.configure do |c|
c.catalog = [ { key: "company", name: "Company", value: "Acme" } ]
end
catalog: the insertable items for the editor prompt. A list, a zero-arg callable, or a ->(context) callable. Items respond to #key, #name, optional #value (used by the default assigns), and #attachable_sgid. assigns: ->(context, used_keys) or ->(used_keys) returning a Hash of key => value for a render. Omit to read #value off catalog items. renderer: Renderers::Substitution (default, no Liquid) or Renderers::Liquid. max_fragment_depth: how deep :fragment chips (e.g. snippets) expand. The default of 1 resolves a snippet's inner variables and drops nested snippets. content_layout: the ActionText content layout wrapper for rendered output. sort: how the catalog is ordered in the prompt and dropdown. Defaults to :name (case-insensitive alphabetical). Use :key to sort by key, false to preserve the catalog's given order, or a callable: a ->(item) sort key, or a ->(a, b) comparator.
Instance Attribute Summary collapse
-
#assigns ⇒ Object
Returns the value of attribute assigns.
-
#catalog ⇒ Object
writeonly
Sets the attribute catalog.
-
#content_layout ⇒ Object
Returns the value of attribute content_layout.
-
#max_fragment_depth ⇒ Object
Returns the value of attribute max_fragment_depth.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#sort ⇒ Object
Returns the value of attribute sort.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_attachment(content_type:, phase:, resolve:, label: nil) ⇒ Object
Adds or overrides an attachment type.
- #resolve_assigns(context, keys) ⇒ Object
- #resolve_catalog(context) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 |
# File 'lib/lexxy_variables/configuration.rb', line 27 def initialize @registry = Registry.new @renderer = Renderers::Substitution.new @content_layout = "layouts/action_text/contents/content" @max_fragment_depth = 1 @catalog = [] @sort = :name register_default_variable_type end |
Instance Attribute Details
#assigns ⇒ Object
Returns the value of attribute assigns.
23 24 25 |
# File 'lib/lexxy_variables/configuration.rb', line 23 def assigns @assigns end |
#catalog=(value) ⇒ Object (writeonly)
Sets the attribute catalog
25 26 27 |
# File 'lib/lexxy_variables/configuration.rb', line 25 def catalog=(value) @catalog = value end |
#content_layout ⇒ Object
Returns the value of attribute content_layout.
23 24 25 |
# File 'lib/lexxy_variables/configuration.rb', line 23 def content_layout @content_layout end |
#max_fragment_depth ⇒ Object
Returns the value of attribute max_fragment_depth.
23 24 25 |
# File 'lib/lexxy_variables/configuration.rb', line 23 def max_fragment_depth @max_fragment_depth end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
24 25 26 |
# File 'lib/lexxy_variables/configuration.rb', line 24 def registry @registry end |
#renderer ⇒ Object
Returns the value of attribute renderer.
23 24 25 |
# File 'lib/lexxy_variables/configuration.rb', line 23 def renderer @renderer end |
#sort ⇒ Object
Returns the value of attribute sort.
23 24 25 |
# File 'lib/lexxy_variables/configuration.rb', line 23 def sort @sort end |
Instance Method Details
#register_attachment(content_type:, phase:, resolve:, label: nil) ⇒ Object
Adds or overrides an attachment type. Variables are pre-registered. A host
calls this to add types like snippets, or to override the variable resolver.
label is an optional badge name shown in the prompt when types are mixed.
40 41 42 |
# File 'lib/lexxy_variables/configuration.rb', line 40 def (content_type:, phase:, resolve:, label: nil) registry.register(AttachmentType.new(content_type:, phase:, resolve:, label:)) end |
#resolve_assigns(context, keys) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/lexxy_variables/configuration.rb', line 48 def resolve_assigns(context, keys) return default_assigns(context, keys) unless @assigns if @assigns.arity == 1 @assigns.call(keys) else @assigns.call(context, keys) end end |
#resolve_catalog(context) ⇒ Object
44 45 46 |
# File 'lib/lexxy_variables/configuration.rb', line 44 def resolve_catalog(context) sort_catalog(Array(call_with_context(@catalog, context))) end |