Module: Trenni::Formatters::HTML::DefinitionListForm
- Includes:
- FormFormatter
- Defined in:
- lib/trenni/formatters/html/definition_list_form.rb
Instance Method Summary collapse
-
#checkbox(**options) ⇒ Object
A checkbox field.
- #element(klass, **options, &block) ⇒ Object
- #fieldset(**options, &block) ⇒ Object
-
#input(**options) ⇒ Object
An input field (single line text).
-
#output(**options) ⇒ Object
An output field for the result of a computation.
-
#submit(**options) ⇒ Object
A submission button.
-
#textarea(**options) ⇒ Object
A textarea field (multi-line text).
Methods included from FormFormatter
#button, #button_attributes_for, #button_title_for, #checkbox_attributes_for, #details_for, #field_for, #hidden, #hidden_attributes_for, #input_attributes_for, #new_record?, #object_value_for, #output_attributes_for, #pattern_for, #placeholder_for, #raw_value_for, #submit_attributes_for, #submit_title_for, #textarea_attributes_for, #title_for, #value_for
Instance Method Details
#checkbox(**options) ⇒ Object
A checkbox field.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 90 def checkbox(**) = @options.merge(**) Builder.fragment do |builder| builder.tag(:dd) do builder.tag :input, :type => :hidden, :name => name_for(**), :value => 'false' builder.inline(:label) do builder.tag :input, checkbox_attributes_for(**) # We would like a little bit of whitespace between the checkbox and the title. builder.text " " + title_for(**) end if details = details_for(**) builder.inline(:small, class: 'details') {builder.text details} end end end end |
#element(klass, **options, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 120 def element(klass, **, &block) = @options.merge(**) Builder.fragment(block&.binding) do |builder| builder.inline(:dt) do builder.text title_for(**) end builder.tag(:dd) do klass.call(self, builder, **, &block) if details = details_for(**) builder.inline(:small, class: 'details') {builder.text details} end end end end |
#fieldset(**options, &block) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 138 def fieldset(**, &block) super do |builder| builder.tag(:dl) do yield(builder) end end end |
#input(**options) ⇒ Object
An input field (single line text).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 35 def input(**) = @options.merge(**) Builder.fragment do |builder| builder.inline(:dt) do builder.text title_for(**) end builder.inline(:dd) do builder.tag :input, input_attributes_for(**) if details = details_for(**) builder.inline(:small, class: 'details') {builder.text details} end end end end |
#output(**options) ⇒ Object
An output field for the result of a computation.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 54 def output(**) = @options.merge(**) Builder.fragment do |builder| builder.inline(:dt) {builder.text title_for(**)} builder.inline(:dd) do builder.inline :output, output_attributes_for(**) do builder.text value_for(**) end end end end |
#submit(**options) ⇒ Object
A submission button
111 112 113 114 115 116 117 118 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 111 def submit(**) = @options.merge(**) [:title] ||= submit_title_for(**) Builder.fragment do |builder| builder.tag :input, submit_attributes_for(**) end end |
#textarea(**options) ⇒ Object
A textarea field (multi-line text).
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/trenni/formatters/html/definition_list_form.rb', line 69 def textarea(**) = @options.merge(**) Builder.fragment do |builder| builder.tag(:dt) do builder.text title_for(**) if details = details_for(**) builder.inline(:small, class: 'details') {builder.text details} end end builder.inline(:dd) do builder.tag :textarea, textarea_attributes_for(**) do builder.text value_for(**) end end end end |