Sha256: 39c3ca1ebbd360ea74b58c9a0aec9eede53112af18808ad09c36232a4df7f0bd

Contents?: true

Size: 1.27 KB

Versions: 39

Compression:

Stored size: 1.27 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(hint_translation_attribute, scope: hint_translation_scope)
      else
        hint
      end
    end

    # Returns true if the element has a hint defined
    def has_hint?
      !!definition[:hint]
    end

    private

    def hint_translation_attribute
      name
    end

    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-6.1.10 lib/alchemy/hints.rb
alchemy_cms-6.1.9 lib/alchemy/hints.rb
alchemy_cms-6.1.8 lib/alchemy/hints.rb
alchemy_cms-6.1.7 lib/alchemy/hints.rb
alchemy_cms-6.1.6 lib/alchemy/hints.rb
alchemy_cms-6.1.5 lib/alchemy/hints.rb
alchemy_cms-6.0.14 lib/alchemy/hints.rb
alchemy_cms-6.1.4 lib/alchemy/hints.rb
alchemy_cms-6.0.13 lib/alchemy/hints.rb
alchemy_cms-6.1.3 lib/alchemy/hints.rb
alchemy_cms-6.1.2 lib/alchemy/hints.rb
alchemy_cms-6.1.1 lib/alchemy/hints.rb
alchemy_cms-6.1.0 lib/alchemy/hints.rb
alchemy_cms-6.0.12 lib/alchemy/hints.rb
alchemy_cms-6.0.11 lib/alchemy/hints.rb
alchemy_cms-6.0.10 lib/alchemy/hints.rb
alchemy_cms-6.0.9 lib/alchemy/hints.rb
alchemy_cms-6.0.8 lib/alchemy/hints.rb
alchemy_cms-6.0.7 lib/alchemy/hints.rb
alchemy_cms-6.0.6 lib/alchemy/hints.rb