Module: LexxyVariables::Helper

Defined in:
lib/lexxy_variables/helper.rb

Overview

Mixed into Action View by the engine. context is opaque to the gem and is passed straight through to the host's catalog/assigns/resolve callables.

Instance Method Summary collapse

Instance Method Details

#lexxy_variable_chip(name, key:, block: false) ⇒ Object

Default variable/attachment chip shown in the editor. block: renders the block style, for chips that expand to a rich fragment (e.g. snippets).



30
31
32
33
34
# File 'lib/lexxy_variables/helper.rb', line 30

def lexxy_variable_chip(name, key:, block: false)
  tag.span name,
    class: [ "lexxy-variable", ("lexxy-variable--block" if block) ],
    data: { lexxy_key: key }
end

#lexxy_variables_prompt(context: nil, trigger: "{{", empty_results: "No variables found") ⇒ Object

Renders the the editor extension reads, built from the configured catalog. context is passed to the catalog callable.



22
23
24
25
26
# File 'lib/lexxy_variables/helper.rb', line 22

def lexxy_variables_prompt(context: nil, trigger: "{{", empty_results: "No variables found")
  items = Array(LexxyVariables.config.resolve_catalog(context))
  render partial: "lexxy_variables/prompt",
         locals: { items: items, trigger: trigger, empty_results: empty_results }
end

#render_variable_content(rich_text, context: nil, locale: I18n.locale, assigns: {}, **inline_assigns) ⇒ Object

assigns: (and any extra keyword args) are per-render values merged on top of the configured assigns, so a caller can supply a key's value inline:

render_variable_content(@record.body, first_name: @user.first_name)

Inline values win over the configured assigns. Keys not used by any chip in the body are ignored. Under the default renderer inline values are HTML-escaped; under Liquid they are emitted as-is, so pre-escape them or pass a drop.



14
15
16
17
18
# File 'lib/lexxy_variables/helper.rb', line 14

def render_variable_content(rich_text, context: nil, locale: I18n.locale, assigns: {}, **inline_assigns)
  LexxyVariables::Pipeline.new(self).call(
    rich_text, context: context, locale: locale, assigns: assigns.merge(inline_assigns)
  )
end