Serializer
class that converts tags to BS3 bootstrap tags.
Registered at :bs3.
Public Instance methods
call(tag)
[show source]
# File lib/forme/bs3.rb 347 def call(tag) 348 # All textual <input>, <textarea>, and <select> elements with .form-control 349 case tag 350 when Tag 351 case tag.type 352 when :input 353 # default to <input type="text"...> if not set 354 tag.attr[:type] = :text if tag.attr[:type].nil? 355 356 case tag.attr[:type].to_sym 357 when :checkbox, :radio, :hidden 358 # .form-control class causes rendering problems, so remove if found 359 tag.attr[:class] = tag.attr[:class].gsub(/\s*form-control\s*/,'') if tag.attr[:class] 360 tag.attr[:class] = nil if tag.attr[:class] && tag.attr[:class].empty? 361 362 when :file 363 tag.attr[:class] = nil unless tag.attr[:class] && tag.attr[:class].strip != '' 364 365 when :submit, :reset 366 klass = ['btn', 'btn-default'] 367 if tag.attr[:class] && tag.attr[:class].strip != '' 368 tag.attr[:class].split(' ').each { |c| klass.push c } 369 end 370 tag.attr[:class] = klass.uniq 371 ['btn-primary','btn-success', 'btn-info', 'btn-warning','btn-danger', 372 'btn-outline','btn-link' 373 ].each do |k| 374 tag.attr[:class].delete('btn-default') if tag.attr[:class].include?(k) 375 end 376 tag.attr[:class].join(' ') 377 378 else 379 klass = tag.attr[:class] ? "form-control #{tag.attr[:class].to_s}" : '' 380 tag.attr[:class] = "form-control #{klass.gsub(/\s*form-control\s*/,'')}".strip 381 end 382 383 return "<#{tag.type}#{attr_html(tag.attr)}/>" 384 385 when :textarea, :select 386 klass = tag.attr[:class] ? "form-control #{tag.attr[:class].to_s}" : '' 387 tag.attr[:class] = "form-control #{klass.gsub(/\s*form-control\s*/,'')}".strip 388 return "#{serialize_open(tag)}#{call(tag.children)}#{serialize_close(tag)}" 389 else 390 super 391 end 392 else 393 super 394 end 395 end