Class: Satis::Editor::Component

Inherits:
ApplicationComponent show all
Defined in:
app/components/satis/editor/component.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationComponent

#original_view_context

Instance Method Summary collapse

Methods inherited from ApplicationComponent

add_helper, #component_name

Constructor Details

#initialize(form: nil, attribute: nil, **options) ⇒ Component

Returns a new instance of Component.



7
8
9
10
11
# File 'app/components/satis/editor/component.rb', line 7

def initialize(form: nil, attribute: nil, **options)
  @form = form
  @attribute = attribute
  @options = options
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'app/components/satis/editor/component.rb', line 6

def attribute
  @attribute
end

#formObject (readonly)

Returns the value of attribute form.



6
7
8
# File 'app/components/satis/editor/component.rb', line 6

def form
  @form
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'app/components/satis/editor/component.rb', line 6

def options
  @options
end

Instance Method Details

#langObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/satis/editor/component.rb', line 17

def lang
  # Mode is there for older code, it's deprecated
  if @options[:lang]
    @options[:lang]
  elsif @options[:mode]
    case @options[:mode]
    when 'application/yaml'
      'yaml'
    when 'application/json'
      'json'
    when 'text/x-ruby'
      ''

    end
  end
end

#readonly?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/components/satis/editor/component.rb', line 13

def readonly?
  (@options[:readonly].is_a?(TrueClass) || @options[:readonly].is_a?(FalseClass)) ? @options[:readonly] : content?
end

#valueObject



34
35
36
37
38
39
40
41
42
# File 'app/components/satis/editor/component.rb', line 34

def value
  if content?
    html_escape_once(content)
  elsif options[:input_html]&.[](:value)
    options[:input_html][:value]
  elsif form
    form.object.send(attribute)
  end
end