Class: Ui::Component
- Inherits:
-
Object
- Object
- Ui::Component
- Defined in:
- lib/rapid_ui/component.rb
Overview
responsible for the out building of the component
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#action_attr ⇒ Object
Returns the value of attribute action_attr.
-
#alt ⇒ Object
Returns the value of attribute alt.
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#img ⇒ Object
Returns the value of attribute img.
-
#method ⇒ Object
Returns the value of attribute method.
-
#name_attr ⇒ Object
Returns the value of attribute name_attr.
-
#placeholder ⇒ Object
Returns the value of attribute placeholder.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#style ⇒ Object
Returns the value of attribute style.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#text ⇒ Object
Returns the value of attribute text.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#build_class ⇒ Object
builds out css class for the component.
-
#build_component ⇒ Object
builds out the component.
-
#build_default_class ⇒ Object
builds out a default class for the component.
-
#build_dynamic ⇒ Object
adds dynamic class to the component is the switch is set.
-
#build_name ⇒ Object
builds out the name for the compnent.
-
#build_responsiveness ⇒ Object
builds out the reponsive css classes.
-
#build_stimulus_props ⇒ Object
builds out stimulus.js shortcuts.
-
#initialize(settings) ⇒ Component
constructor
A new instance of Component.
-
#set_defaults ⇒ Object
sets component defaults.
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
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def action @action end |
#action_attr ⇒ Object
Returns the value of attribute action_attr.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def action_attr @action_attr end |
#alt ⇒ Object
Returns the value of attribute alt.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def alt @alt end |
#css_class ⇒ Object
Returns the value of attribute css_class.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def css_class @css_class end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def id @id end |
#img ⇒ Object
Returns the value of attribute img.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def img @img end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def method @method end |
#name_attr ⇒ Object
Returns the value of attribute name_attr.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def name_attr @name_attr end |
#placeholder ⇒ Object
Returns the value of attribute placeholder.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def placeholder @placeholder end |
#rows ⇒ Object
Returns the value of attribute rows.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def rows @rows end |
#style ⇒ Object
Returns the value of attribute style.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def style @style end |
#tag ⇒ Object
Returns the value of attribute tag.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def tag @tag end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def text @text end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/rapid_ui/component.rb', line 4 def url @url end |
#value ⇒ Object
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_class ⇒ Object
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_component ⇒ Object
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_class ⇒ Object
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_dynamic ⇒ Object
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_name ⇒ Object
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_responsiveness ⇒ Object
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_props ⇒ Object
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_defaults ⇒ Object
sets component defaults
14 15 16 17 |
# File 'lib/rapid_ui/component.rb', line 14 def set_defaults @data = nil @css_class = '' end |