Class: Ui::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/rapid_ui/component.rb

Overview

responsible for the out building of the component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Component

Returns a new instance of Component.



6
7
8
9
10
11
# File 'lib/rapid_ui/component.rb', line 6

def initialize(settings)
  @settings = settings
  set_defaults
  build_component
  transpose_settings %w[action_attr alt data id img method name_attr placeholder rows style tag text title type url value]
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def action
  @action
end

#action_attrObject

Returns the value of attribute action_attr.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def action_attr
  @action_attr
end

#altObject

Returns the value of attribute alt.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def alt
  @alt
end

#css_classObject

Returns the value of attribute css_class.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def css_class
  @css_class
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def data
  @data
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def id
  @id
end

#imgObject

Returns the value of attribute img.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def img
  @img
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def method
  @method
end

#name_attrObject

Returns the value of attribute name_attr.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def name_attr
  @name_attr
end

#placeholderObject

Returns the value of attribute placeholder.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def placeholder
  @placeholder
end

#rowsObject

Returns the value of attribute rows.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def rows
  @rows
end

#styleObject

Returns the value of attribute style.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def style
  @style
end

#tagObject

Returns the value of attribute tag.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def tag
  @tag
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def text
  @text
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def title
  @title
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def type
  @type
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def url
  @url
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/rapid_ui/component.rb', line 4

def value
  @value
end

Instance Method Details

#build_classObject

builds out css class for the component



36
37
38
# File 'lib/rapid_ui/component.rb', line 36

def build_class
  add_class @settings[:class] if @settings.key?(:class)
end

#build_componentObject

builds out the component



20
21
22
23
24
25
26
27
# File 'lib/rapid_ui/component.rb', line 20

def build_component
  build_dynamic
  build_class
  build_responsiveness
  build_name
  build_default_class
  build_stimulus_props
end

#build_default_classObject

builds out a default class for the component



60
61
62
# File 'lib/rapid_ui/component.rb', line 60

def build_default_class
  add_class @settings[:css_class] if @settings.key?(:css_class)
end

#build_dynamicObject

adds dynamic class to the component is the switch is set



31
32
33
# File 'lib/rapid_ui/component.rb', line 31

def build_dynamic
  add_class 'dynamic' if on?(:dynamic)
end

#build_nameObject

builds out the name for the compnent



52
53
54
55
56
57
# File 'lib/rapid_ui/component.rb', line 52

def build_name
  return unless @settings.key?(:name)

  add_class @settings[:name]
  add_data :name, @settings[:name].parameterize.underscore
end

#build_responsivenessObject

builds out the reponsive css classes



41
42
43
44
45
46
47
48
49
# File 'lib/rapid_ui/component.rb', line 41

def build_responsiveness
  add_class build_only if @settings.key?(:only)
  add_class build_size if @settings.key?(:size)

  sizes = %i[computer tablet mobile]
  sizes.each do |device|
    add_class build_size(device) if @settings.key?(device)
  end
end

#build_stimulus_propsObject

builds out stimulus.js shortcuts



65
66
67
68
69
# File 'lib/rapid_ui/component.rb', line 65

def build_stimulus_props
  add_data :controller, @settings[:controller] if @settings.key?(:controller)
  add_data :target, @settings[:target] if @settings.key?(:target)
  add_data :action, @settings[:action] if @settings.key?(:action)
end

#set_defaultsObject

sets component defaults



14
15
16
17
# File 'lib/rapid_ui/component.rb', line 14

def set_defaults
  @data = nil
  @css_class = ''
end