Sha256: 9420aec45aaa56ad11c018e650fd23598ad77e80dcc18a29b48084a9c3d873d8

Contents?: true

Size: 1.19 KB

Versions: 85

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Ariadne
  module ActionViewExtensions
    # :nodoc:
    module FormHelper
      include ClassNameHelper

      DEFAULT_FORM_CLASSES = "ariadne-space-y-8 sm:ariadne-space-y-5"
      def ariadne_form_with(model: nil, scope: nil, url: nil, format: nil, classes: "", attributes: {}, **options, &block)
        options[:class] = class_names(DEFAULT_FORM_CLASSES, options[:class])
        options[:builder] ||= Ariadne::FormBuilder
        options[:html] ||= {}

        data = options.delete(:data) || {}
        attributes = attributes.delete_if do |key, value|
          key_name = key.to_s
          if key_name.start_with?("data-")
            data[key_name.sub(/^data-/, "").to_sym] = value
            true
          else
            false
          end
        end

        data[:controller] = if data.fetch(:controller, {}).present?
          "#{data[:controller]} ariadne-form"
        else
          "ariadne-form"
        end

        form_with(model: model, scope: scope, url: url, format: format, data: data, attributes: attributes, **options, &block)
      end
    end
  end
end

ActiveSupport.on_load(:action_view) do
  include Ariadne::ActionViewExtensions::FormHelper
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.30 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.30-aarch64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.29-aarch64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.28-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb