Constants
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 |
Public Instance methods
call(tag)
[show source]
# File lib/forme/bs5.rb 177 def call(tag) 178 return super unless tag.is_a?(Tag) 179 180 attr_class = case tag.type 181 when :input 182 # default to <input type="text"...> if not set 183 tag.attr[:type] = :text if tag.attr[:type].nil? 184 185 case tag.attr[:type].to_sym 186 when :checkbox, :radio 187 "form-check-input" 188 when :range 189 "form-range" 190 when :color 191 %w"form-control form-control-color" 192 when :submit, :reset 193 classes = ["btn"] 194 classes << "btn-primary" if (tag.attr[:class].to_s.split(" ") & BUTTON_STYLES).empty? 195 classes 196 when :hidden 197 # nothing 198 else 199 unless tag.attr[:class] && tag.attr[:class].include?("form-control-plaintext") 200 "form-control" 201 end 202 end 203 when :textarea 204 "form-control" 205 when :select 206 "form-select" 207 end 208 Forme.attr_classes_after(tag.attr, *attr_class) if attr_class 209 210 super 211 end