Sha256: 3aff35fdab37079b6644cad32e424ebd706f3fba70dbaceeba8b6745a906e2df

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

class ComfortableMexicanSofa::FormBuilder < BootstrapForm::FormBuilder

  # Renders form input for a fragment
  #
  # @param [Comfy::Cms::Page] record
  # @param [ComfortableMexicanSofa::Content::Tag] tag
  # @param [Integer] index
  def fragment_field(tag, index)
    tag.form_field(object_name, @template, index) do |tag_input|
      name = "#{object_name}[fragments_attributes][#{index}][identifier]"
      identifer_input = @template.hidden_field_tag(name, tag.identifier, id: nil)

      name  = "#{object_name}[fragments_attributes][#{index}][tag]"
      value = tag.class.to_s.demodulize.underscore
      tag_name_input = @template.hidden_field_tag(name, value, id: nil)

      label = I18n.t("comfy.cms.content.tag.#{tag.identifier}", default: tag.identifier.titleize)
      renderable = tag.respond_to?(:renderable) ? tag.renderable : true

      form_group bootstrap: { label: { text: label, for: tag.form_field_id, class: "renderable-#{renderable}" } } do
        concat identifer_input
        concat tag_name_input
        concat tag_input
      end
    end
  end

  # Wrapper for form action that is sticking to the bottom of the viewport.
  # Example:
  #   = form.form_actions do
  #     = form.submit
  #
  def form_actions
    content_tag(:div, class: "form-actions row bg-light") do
      content_tag(:div, class: "col-lg-8 offset-lg-2") do
        content_tag(:div, class: "form-group row mb-0") do
          content_tag(:div, class: "col-sm-10 offset-sm-2") do
            yield
          end
        end
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-2.0.16 lib/comfortable_mexican_sofa/form_builder.rb
comfortable_mexican_sofa-2.0.15 lib/comfortable_mexican_sofa/form_builder.rb
comfortable_mexican_sofa-2.0.14 lib/comfortable_mexican_sofa/form_builder.rb
comfortable_mexican_sofa-2.0.13 lib/comfortable_mexican_sofa/form_builder.rb