Sha256: 9fc1c1bc92b2e43d780fe36f7c210f67af60c5212ea28f1fb3fb803652a2dda0

Contents?: true

Size: 909 Bytes

Versions: 46

Compression:

Stored size: 909 Bytes

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
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
avo-3.1.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.1.2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.1.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.1.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.0.8 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-2.46.0 lib/avo/concerns/has_resource_stimulus_controllers.rb