Class: ActiveElement::Components::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/active_element/components/json.rb

Overview

Outputs a ‘<script>` tag and sets globally-available JSON data, available as `ActiveElement.jsonData.<key>`. Note key is camelized, so `foo_bar_baz` becomes `fooBarBaz`.

Instance Method Summary collapse

Constructor Details

#initialize(controller, object:, key:) ⇒ Json

Returns a new instance of Json.



8
9
10
11
12
# File 'lib/active_element/components/json.rb', line 8

def initialize(controller, object:, key:)
  @controller = controller
  @object = object
  @key = key
end

Instance Method Details

#localsObject



18
19
20
21
22
23
24
# File 'lib/active_element/components/json.rb', line 18

def locals
  {
    controller: controller,
    object: object,
    key: ActiveElement::Components::Util.json_name(key)
  }
end

#templateObject



14
15
16
# File 'lib/active_element/components/json.rb', line 14

def template
  'active_element/components/json'
end