Sha256: f39994786b9b4e98cce747896596c7530da06b32a7ed462599be1b8cdf4c697d

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

module CamaleonCms
  class ApplicationDecorator < Draper::Decorator
    delegate_all
    @_deco_locale = nil
    include CamaleonCms::MetasDecoratorMethods

    def marshal_dump
      @object
    end

    def marshal_load(obj)
      @object = obj
    end

    # return the keywords for this model
    def the_keywords
      k = object.get_option('keywords', '')
      k = h.current_site.the_keywords if object.class.name != 'CamaleonCms::Site' && !k.present?
      k.to_s.translate(get_locale)
    end

    def the_slug(locale = nil)
      object.slug.translate(get_locale(locale))
    end

    # return the identifier
    def the_id
      object.id.to_s
    end

    # return created at date formatted
    def the_created_at(format = :long)
      h.l(object.created_at, format: format.to_sym)
    end

    # return updated at date formatted
    def the_updated_at(format = :long)
      h.l(object.updated_at, format: format.to_sym)
    end

    # draw breadcrumb for this model
    # add_post_type: true/false to include post type link
    def the_breadcrumb(add_post_type = true)
      generate_breadcrumb(add_post_type)
      h.breadcrumb_draw
    end

    # ---------------------
    def set_decoration_locale(locale)
      @_deco_locale = locale.to_sym
    end

    # get the locale for current decorator
    def get_locale(locale = nil)
      locale || @_deco_locale || begin
        h.cama_get_i18n_frontend
      rescue StandardError
        nil
      end || I18n.locale
    end

    # return the current locale prefixed to add in frontend routes
    def _calc_locale(_l)
      _l = (_l || @_deco_locale || begin
        h.cama_get_i18n_frontend
      rescue StandardError
        nil
      end || I18n.locale).to_s
      "_#{_l}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
camaleon_cms-2.9.0 app/decorators/camaleon_cms/application_decorator.rb
camaleon_cms-2.8.3 app/decorators/camaleon_cms/application_decorator.rb
camaleon_cms-2.8.2 app/decorators/camaleon_cms/application_decorator.rb
camaleon_cms-2.8.1 app/decorators/camaleon_cms/application_decorator.rb
camaleon_cms-2.8.0 app/decorators/camaleon_cms/application_decorator.rb