Sha256: 815e304f53bcfa82c83bccbf7d4cbef08739466c6b27e6b76be61ba9cf7527b1

Contents?: true

Size: 1.15 KB

Versions: 27

Compression:

Stored size: 1.15 KB

Contents

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
        I18n.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

27 entries across 27 versions & 2 rubygems

Version Path
alchemy_cms-3.2.1 lib/alchemy/hints.rb
alchemy_cms-3.1.3 lib/alchemy/hints.rb
lc_alchemy_cms-3.2.1 lib/alchemy/hints.rb
lc_alchemy_cms-3.2.0 lib/alchemy/hints.rb
alchemy_cms-3.2.0 lib/alchemy/hints.rb
alchemy_cms-3.2.0.rc1 lib/alchemy/hints.rb
alchemy_cms-3.2.0.beta lib/alchemy/hints.rb
alchemy_cms-3.1.1 lib/alchemy/hints.rb
alchemy_cms-3.0.4 lib/alchemy/hints.rb
alchemy_cms-3.1.0 lib/alchemy/hints.rb
alchemy_cms-3.1.0.rc3 lib/alchemy/hints.rb
alchemy_cms-3.1.0.rc2 lib/alchemy/hints.rb
alchemy_cms-3.1.0.rc1 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta6 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta5 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta4 lib/alchemy/hints.rb
alchemy_cms-3.0.3 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta3 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta2 lib/alchemy/hints.rb
alchemy_cms-3.1.0.beta1 lib/alchemy/hints.rb