Class: BulmaX::BaseComponent
Direct Known Subclasses
BaseInput, Block, Box, Breadcrumbs, BulmaX::Breadcrumbs::Item, Button, Card, Card::CardContent, Card::CardFooter, Card::CardHead, Checkbox, Columns, Columns::Column, Dropdown, Dropdown::Content, Dropdown::Item, Field, Field::Control, Field::Label, Figure, File, Footer, Form, Grid, Grid::Cell, Help, Hero, Hero::HeroPart, Icon, Image, Level, Level::Part, Link, Media, Message, Modal, Navbar, Navbar::NavbarMenu, Navbar::NavbarMenu::NavbarDropdown, Navbar::NavbarMenu::NavbarDropdown::NavbarDropdownItem, Navbar::NavbarMenu::NavbarItem, Navbar::NavbarMenu::NavbarStart, Notification, Pagination, Pagination::List, Pagination::List::Item, Pagination::NavigationItem, Panel, Progress, Radio, Section, Select::Option, Slot, Table, Table::Part, Table::Part::Row, Table::Part::Row::Cell, Tabs, Tabs::Tab, Tag, Title, VerticalMenu, VerticalMenu::List
Constant Summary
collapse
- BOOLEAN =
[true, false].freeze
- COLORS =
%w[primary secondary link info success warning danger text].freeze
- COLOR_MODIFIER =
%w[light dark soft bold on-scheme].freeze
- COLOR_PALETTE =
(0..100).step(5).to_a.map { Kernel.format('%<value>02d', value: _1) }.freeze
- MODIFIERS_PALETTE =
COLORS +
COLORS
.product(COLOR_MODIFIER).map { _1.join('-') } +
COLORS
.product(COLOR_PALETTE).map { _1.join('-') } +
COLORS
.product(COLOR_MODIFIER, COLOR_PALETTE)
.map { _1.join('-') } +
[nil] +
COLORS + %w[light dark white black]
- MODIFIERS_DECLINED =
COLORS + COLORS.product(COLOR_MODIFIER).map { _1.join('-') } + [nil] + %w[light dark]
- MODIFIERS =
(COLORS + [nil])
- BLANK_VALUES =
[nil, false, '', [], {}].freeze
Shared::SpacingOptions::VALID_SPACING_KEYS, Shared::SpacingOptions::VALID_SPACING_VALUES
Instance Method Summary
collapse
#aria_attributes, included
#global_attributes, #global_classes, included
#data_attributes, included
#flex_classes, included
included, #spacing_classes
included, #text_classes
included
Constructor Details
Returns a new instance of BaseComponent.
46
47
48
49
50
51
|
# File 'lib/bulma_x/base_component.rb', line 46
def initialize(**, &)
super(&)
build_from_options(**)
validate!(**)
end
|
Instance Method Details
#after_template ⇒ Object
119
120
121
122
|
# File 'lib/bulma_x/base_component.rb', line 119
def after_template
super
{ "</#{self.class.name}>".html_safe }
end
|
#attributes(**kwargs) ⇒ Object
NOTE: attributes will remove all pairs having a falsy value, including false bool. Use “false” string to keep it.
96
97
98
|
# File 'lib/bulma_x/base_component.rb', line 96
def attributes(**kwargs)
compact_blank(kwargs)
end
|
#base_attributes ⇒ Object
80
81
82
83
84
|
# File 'lib/bulma_x/base_component.rb', line 80
def base_attributes
%i[data_attributes aria_attributes global_attributes].each_with_object({}) do |method, acc|
acc.merge!(public_send(method)) if respond_to?(method)
end
end
|
#base_classes ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/bulma_x/base_component.rb', line 71
def base_classes
[
respond_to?(:spacing_classes) && spacing_classes,
respond_to?(:text_classes) && text_classes,
respond_to?(:flex_classes) && flex_classes,
respond_to?(:global_classes) && global_classes
].flatten
end
|
#before_template ⇒ Object
114
115
116
117
|
# File 'lib/bulma_x/base_component.rb', line 114
def before_template
{ "<#{self.class.name}>".html_safe }
super
end
|
#classes(*args) ⇒ Object
NOTE: classes will remove all pairs having a falsy value, including false bool. Use “false” string to keep it.
87
88
89
90
91
92
93
|
# File 'lib/bulma_x/base_component.rb', line 87
def classes(*args)
compact_args = compact_blank(args.flatten)
return {} if compact_args.empty?
{ class: compact_args.join(' ') }
end
|
#compact_blank(obj) ⇒ Object
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/bulma_x/base_component.rb', line 102
def compact_blank(obj)
case obj
when Array
obj.reject { BLANK_VALUES.include?(it) }
when Hash
obj.reject { |_, v| BLANK_VALUES.include?(v) }
else
obj
end
end
|
#css(str) ⇒ Object
100
|
# File 'lib/bulma_x/base_component.rb', line 100
def css(str) = str.to_s.tr('_', '-')
|
#render_root ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/bulma_x/base_component.rb', line 55
def render_root(&)
public_send(
root_tag,
**classes(root_classes),
**attributes(**root_attributes)
) do
capture(&) if block_given?
end
end
|
#view_template ⇒ Object
53
|
# File 'lib/bulma_x/base_component.rb', line 53
def view_template(&) = render_root(&)
|