Sha256: 68a8a10721acf8efc3df1ec9bd99b9abcadf8abd04be8134c0811ae23409ec60

Contents?: true

Size: 1.17 KB

Versions: 52

Compression:

Stored size: 1.17 KB

Contents

module Avo
  module Concerns
    module HasResourceStimulusControllers
      extend ActiveSupport::Concern

      included do
        class_attribute :stimulus_controllers, default: ""
      end

      def get_stimulus_controllers
        return "" if @view.nil?

        controllers = []

        case @view.to_sym
        when :show
          controllers << "resource-show"
        when :new, :edit
          controllers << "resource-edit"
        when :index
          controllers << "resource-index"
        end

        controllers << self.class.stimulus_controllers

        controllers.join " "
      end

      def stimulus_data_attributes
        attributes = {
          controller: get_stimulus_controllers,
        }

        get_stimulus_controllers.split(" ").each do |controller|
          attributes["#{controller}-view-value"] = @view
        end

        attributes
      end

      def add_stimulus_attributes_for(entity, attributes)
        entity.get_stimulus_controllers.split(" ").each do |controller|
          attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
avo-3.16.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.7 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.6 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.5 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.15.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.5 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.14.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.13.7 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.13.6 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.13.5 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.13.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.13.3 lib/avo/concerns/has_resource_stimulus_controllers.rb