Sha256: f94a2e85d7d5ad389772dbd65f7f2ec24e2d632a73f5d6aebcbfa8120d08a075

Contents?: true

Size: 1.23 KB

Versions: 28

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

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

      DEFAULT_FORM_CLASSES = "ariadne-space-y-8 ariadne-divide-y ariadne-divide-gray-200 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

28 entries across 28 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.17-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17-aarch64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.17 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16-aarch64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.16 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-x86_64-linux app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-x86_64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-x64-mingw32 app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-x64-mingw-ucrt app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-arm64-darwin app/lib/ariadne/action_view_extensions/form_helper.rb
ariadne_view_components-0.0.15-aarch64-linux app/lib/ariadne/action_view_extensions/form_helper.rb