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-2.53.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-2.52.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.6.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.6.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.6.2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-2.49.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.6.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.6.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.8 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.7 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.6 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.6.beta1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.5 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.3 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.2 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.1 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.5.0 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.4.4 lib/avo/concerns/has_resource_stimulus_controllers.rb
avo-3.4.3 lib/avo/concerns/has_resource_stimulus_controllers.rb