class Forme::Formatter::ReadOnly
Formatter
that uses span tags with text for most input types, and disables radio/checkbox inputs.
Registered as :readonly.
Private Instance Methods
_format_input(type)
click to toggle source
Use a span with text instead of an input field. For hidden inputs, do not show anything
# File lib/forme/transformers/formatter.rb 549 def _format_input(type) 550 unless type.to_s == 'hidden' 551 tag(:span, {'class'=>'readonly-text'}, @attr[:value]) 552 end 553 end
format_checkbox()
click to toggle source
Disabled checkbox inputs, without a hidden input.
Calls superclass method
Forme::Formatter#format_checkbox
# File lib/forme/transformers/formatter.rb 541 def format_checkbox 542 @attr[:disabled] = :disabled 543 @opts[:no_hidden] = true unless @opts.has_key?(:no_hidden) 544 super 545 end
format_radio()
click to toggle source
Disabled radio button inputs.
Calls superclass method
Forme::Formatter#format_radio
# File lib/forme/transformers/formatter.rb 556 def format_radio 557 @attr[:disabled] = :disabled 558 super 559 end
format_select()
click to toggle source
Use a span with text of the selected values instead of a select box.
Calls superclass method
Forme::Formatter#format_select
# File lib/forme/transformers/formatter.rb 562 def format_select 563 t = super 564 children = [t.children.select{|o| o.attr[:selected]}.map(&:children).join(', ')] if t.children 565 tag(:span, {}, children) 566 end
format_submit()
click to toggle source
Ignore submit buttons
# File lib/forme/transformers/formatter.rb 569 def format_submit 570 '' 571 end
format_textarea()
click to toggle source
Format the text as separate paragraphs.
# File lib/forme/transformers/formatter.rb 574 def format_textarea 575 text = @attr[:value] 576 case text 577 when nil, Forme::Raw 578 # nothing 579 when String 580 text = text.gsub(/\A[\r\n]+|[\r\n]+\z/, '').split(/(?:\r?\n)(?:\r?\n)+/).map do |t| 581 t = Forme.h(t) 582 t.gsub!(/\r?\n/, "<br />") 583 tag(:p, {}, Forme.raw(t)) 584 end 585 end 586 tag(:div, {'class'=>'readonly-textarea'}, text) 587 end