Sha256: 196f61c488703c3f2057fec23ad8d8fc7415de0ee14067643b9cb48bade2da3e

Contents?: true

Size: 1.18 KB

Versions: 39

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Hints
    # Returns a hint
    #
    # To add a hint to a content pass +hint: true+ to the element definition in its element.yml
    #
    # Then the hint itself is placed in the locale yml files.
    #
    # Alternativly you can pass the hint itself to the hint key.
    #
    # == Locale Example:
    #
    #   # elements.yml
    #   - name: headline
    #     contents:
    #     - name: headline
    #       type: EssenceText
    #       hint: true
    #
    #   # config/locales/de.yml
    #     de:
    #       content_hints:
    #         headline: Lorem ipsum
    #
    # == Hint Key Example:
    #
    #   - name: headline
    #     contents:
    #     - name: headline
    #       type: EssenceText
    #       hint: Lorem ipsum
    #
    # @return String
    #
    def hint
      hint = definition['hint']
      if hint == true
        Alchemy.t(name, scope: hint_translation_scope)
      else
        hint
      end
    end

    # Returns true if the element has a hint
    def has_hint?
      hint.present?
    end

    private

    def hint_translation_scope
      "#{self.class.model_name.to_s.demodulize.downcase}_hints"
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 lib/alchemy/hints.rb
alchemy_cms-4.6.6 lib/alchemy/hints.rb
alchemy_cms-4.6.5 lib/alchemy/hints.rb
alchemy_cms-4.5.1 lib/alchemy/hints.rb
alchemy_cms-4.4.5 lib/alchemy/hints.rb
alchemy_cms-4.6.4 lib/alchemy/hints.rb
alchemy_cms-4.0.6 lib/alchemy/hints.rb
alchemy_cms-4.6.3 lib/alchemy/hints.rb
alchemy_cms-4.6.2 lib/alchemy/hints.rb
alchemy_cms-4.6.1 lib/alchemy/hints.rb
alchemy_cms-4.6.0 lib/alchemy/hints.rb
alchemy_cms-4.5.0 lib/alchemy/hints.rb
alchemy_cms-4.4.4 lib/alchemy/hints.rb
alchemy_cms-4.4.3 lib/alchemy/hints.rb
alchemy_cms-4.4.2 lib/alchemy/hints.rb
alchemy_cms-4.4.1 lib/alchemy/hints.rb
alchemy_cms-4.4.0 lib/alchemy/hints.rb
alchemy_cms-4.3.2 lib/alchemy/hints.rb
alchemy_cms-4.2.4 lib/alchemy/hints.rb
alchemy_cms-4.3.1 lib/alchemy/hints.rb