Sha256: 0804f4bebe23d63202d1b10ff0ef155ecf9632f2e4003c7c92c25a3ad702af33

Contents?: true

Size: 1.09 KB

Versions: 31

Compression:

Stored size: 1.09 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.html_safe
      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

31 entries across 31 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.6 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.9 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.4.1 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.4.0 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.5 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.8 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.13 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.16 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.4 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.3 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.2 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.7 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.1 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.3.0 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.6 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.5 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.1.12 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.0.15 app/components/alchemy/ingredients/base_view.rb
alchemy_cms-7.2.4 app/components/alchemy/ingredients/base_view.rb