Sha256: b69f6d434ed9a0e577bd915b4574ea62c23f8f611441cb84f4f12d3d0af57125

Contents?: true

Size: 1.08 KB

Versions: 25

Compression:

Stored size: 1.08 KB

Contents

module Alchemy
  module Ingredients
    class BaseView < ViewComponent::Base
      attr_reader :ingredient, :html_options

      delegate :alchemy, to: :helpers
      delegate :settings, :value, to: :ingredient

      # @param ingredient [Alchemy::Ingredient]
      # @param html_options [Hash] Options that will be passed to the wrapper tag.
      def initialize(ingredient, html_options: {})
        raise ArgumentError, "Ingredient missing!" if ingredient.nil?

        @ingredient = ingredient
        @html_options = html_options
      end

      def call
        value
      end

      def render?
        value.present?
      end

      private

      # Fetches value from ingredient settings and allows to merge a value on top of it
      #
      # @param key [Symbol] - The settings key you want to fetch the value from
      # @param value [Object] - A optional value that can override the setting.
      #   Normally passed as into the ingredient view.
      def settings_value(key, value: nil, default: nil)
        value.nil? ? settings.fetch(key, default) : value
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
alchemy_cms-7.0.11 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.6 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.5 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.10 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.4 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.9 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.3 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.2 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.1 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.0 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.0.pre.rc1 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.0.pre.b2 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.0.pre.b1 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.8 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.7 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.6 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.5 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.4 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.3 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.2 app/components/alchemy/ingredients/base_view.rb