Class: Forme::Serializer::Bootstrap5
- Inherits:
-
Forme::Serializer
- Object
- Forme::Serializer
- Forme::Serializer::Bootstrap5
- Defined in:
- lib/forme/bs5.rb
Constant Summary collapse
- BUTTON_STYLES =
%w[ btn-primary btn-secondary btn-success btn-danger btn-warning btn-info btn-light btn-dark btn-link btn-outline-primary btn-outline-secondary btn-outline-success btn-outline-danger btn-outline-warning btn-outline-info btn-outline-light btn-outline-dark ].freeze
Constants inherited from Forme::Serializer
Instance Method Summary collapse
Methods inherited from Forme::Serializer
#serialize_close, #serialize_open
Instance Method Details
#call(tag) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/forme/bs5.rb', line 177 def call(tag) return super unless tag.is_a?(Tag) attr_class = case tag.type when :input # default to <input type="text"...> if not set tag.attr[:type] = :text if tag.attr[:type].nil? case tag.attr[:type].to_sym when :checkbox, :radio "form-check-input" when :range "form-range" when :color %w"form-control form-control-color" when :submit, :reset classes = ["btn"] classes << "btn-primary" if (tag.attr[:class].to_s.split(" ") & BUTTON_STYLES).empty? classes when :hidden # nothing else unless tag.attr[:class] && tag.attr[:class].include?("form-control-plaintext") "form-control" end end when :textarea "form-control" when :select "form-select" end Forme.attr_classes_after(tag.attr, *attr_class) if attr_class super end |