Module: Arara::BaseComponent
- Included in:
- ButtonComponent, CardActionButtonsComponent, CardActionIconsComponent, CardActionsComponent, CardComponent, CardMediaComponent, CardMediaContentComponent, CardPrimaryContentComponent, CheckboxComponent, ChipComponent, ChipsetComponent, DataTableBodyCellComponent, DataTableBodyCheckboxComponent, DataTableBodyComponent, DataTableBodyRowComponent, DataTableComponent, DataTableHeaderCellComponent, DataTableHeaderCheckboxComponent, DataTableHeaderComponent, DataTableHeaderRowComponent, DialogButtonComponent, DialogComponent, DialogContentComponent, DialogFooterComponent, DialogTitleComponent, ElevationComponent, FabComponent, FabIconComponent, FormFieldComponent, IconButtonComponent, MaterialIconComponent, MenuComponent, MenuDividerComponent, MenuItemComponent, RadioButtonComponent, SelectComponent, SelectItemComponent, StepComponent, StepConnectorComponent, StepperComponent, SwitchComponent, TextFieldComponent, TypographyComponent
- Defined in:
- app/components/arara/base_component.rb
Defined Under Namespace
Classes: MissingTag
Class Method Summary collapse
Instance Method Summary collapse
- #default_data_controller ⇒ Object
- #default_html_class ⇒ Object
- #default_html_tag ⇒ Object
- #html_class ⇒ Object
- #html_content ⇒ Object
- #html_data ⇒ Object
- #html_options ⇒ Object
- #html_tag ⇒ Object
- #initialize(tag: nil, content: nil, variant: nil, id: nil, data: nil, **options) ⇒ Object
Class Method Details
.included(mod) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/components/arara/base_component.rb', line 5 def self.included(mod) attr_reader :user_content, :user_variant, :user_tag, :user_data, :id, :options def initialize(tag: nil, content: nil, variant: nil, id: nil, data: nil, **) @user_tag = tag.try(:to_s) || default_html_tag @user_variant = variant.try(:to_s) @user_content = content @user_data = data || {} @html_class = .fetch(:class, "") @options = @id = id end def html_content return content if content user_content end def html_class classes = default_html_class ? [default_html_class] : [] classes.push(@html_class) unless @html_class.try(:empty?) classes.empty? ? [] : classes end def html_tag raise MissingTag.new('You need to specify a tag') if @user_tag.nil? @user_tag end def opts = .dup opts[:class] = html_class unless html_class.empty? opts[:data] = html_data unless html_data.empty? opts[:id] = id if id opts end def html_data data_controller = default_data_controller ? [default_data_controller] : [] data_controller.push(user_data[:controller]) if user_data.has_key?(:controller) data_controller = (data_controller.empty? ? nil : data_controller.join(" ")) data = user_data.dup data.merge!({controller: data_controller}) data end def default_data_controller end def default_html_class end def default_html_tag end end |
Instance Method Details
#default_data_controller ⇒ Object
52 53 |
# File 'app/components/arara/base_component.rb', line 52 def default_data_controller end |
#default_html_class ⇒ Object
55 56 |
# File 'app/components/arara/base_component.rb', line 55 def default_html_class end |
#default_html_tag ⇒ Object
58 59 |
# File 'app/components/arara/base_component.rb', line 58 def default_html_tag end |
#html_class ⇒ Object
23 24 25 26 27 |
# File 'app/components/arara/base_component.rb', line 23 def html_class classes = default_html_class ? [default_html_class] : [] classes.push(@html_class) unless @html_class.try(:empty?) classes.empty? ? [] : classes end |
#html_content ⇒ Object
18 19 20 21 |
# File 'app/components/arara/base_component.rb', line 18 def html_content return content if content user_content end |
#html_data ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/components/arara/base_component.rb', line 42 def html_data data_controller = default_data_controller ? [default_data_controller] : [] data_controller.push(user_data[:controller]) if user_data.has_key?(:controller) data_controller = (data_controller.empty? ? nil : data_controller.join(" ")) data = user_data.dup data.merge!({controller: data_controller}) data end |
#html_options ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/components/arara/base_component.rb', line 34 def opts = .dup opts[:class] = html_class unless html_class.empty? opts[:data] = html_data unless html_data.empty? opts[:id] = id if id opts end |
#html_tag ⇒ Object
29 30 31 32 |
# File 'app/components/arara/base_component.rb', line 29 def html_tag raise MissingTag.new('You need to specify a tag') if @user_tag.nil? @user_tag end |
#initialize(tag: nil, content: nil, variant: nil, id: nil, data: nil, **options) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/components/arara/base_component.rb', line 8 def initialize(tag: nil, content: nil, variant: nil, id: nil, data: nil, **) @user_tag = tag.try(:to_s) || default_html_tag @user_variant = variant.try(:to_s) @user_content = content @user_data = data || {} @html_class = .fetch(:class, "") @options = @id = id end |