Class: Infold::Views::FormWriter
- Inherits:
-
BaseWriter
- Object
- BaseWriter
- BaseWriter
- Infold::Views::FormWriter
- Defined in:
- lib/infold/writers/views/form_writer.rb
Instance Attribute Summary collapse
-
#app_title ⇒ Object
readonly
Returns the value of attribute app_title.
Attributes inherited from BaseWriter
Instance Method Summary collapse
- #form_field_code(field) ⇒ Object
- #form_fields ⇒ Object
-
#initialize(resource) ⇒ FormWriter
constructor
A new instance of FormWriter.
Methods inherited from BaseWriter
Methods inherited from BaseWriter
#edit_path, #indent, #index_path, #new_path, #resource_name, #show_path
Constructor Details
#initialize(resource) ⇒ FormWriter
Returns a new instance of FormWriter.
8 9 10 |
# File 'lib/infold/writers/views/form_writer.rb', line 8 def initialize(resource) @resource = resource end |
Instance Attribute Details
#app_title ⇒ Object (readonly)
Returns the value of attribute app_title.
6 7 8 |
# File 'lib/infold/writers/views/form_writer.rb', line 6 def app_title @app_title end |
Instance Method Details
#form_field_code(field) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/infold/writers/views/form_writer.rb', line 14 def form_field_code(field) code = "= render Admin::FieldsetComponent.new(form, " + ":#{field.name}, :#{field.form_element.form_kind}" code += ", required: true" if field.validation&.has_presence? code += ", no_label: true" if field.form_element.in_association case field.form_element.form_kind when :association_search "#{code}, #{belongs_to_search_form_option(field.association)})" when :select "#{code}, list: #{form_field_list(field)}, " + "selected_value: form.object.#{field.name})" when :radio "#{code}, list: #{form_field_list(field)})" when :datetime "#{code})" when :file "#{code})" when :switch "#{code}, include_hidden: true)" else option = text_form_option(field).presence option ? "#{code}, #{option})" : "#{code})" end end |
#form_fields ⇒ Object
12 |
# File 'lib/infold/writers/views/form_writer.rb', line 12 def form_fields; @resource.form_fields end |