Sha256: 59345b0d34f89c063875c12847c2795e1338139699b417a228c5270d6c260ba0

Contents?: true

Size: 951 Bytes

Versions: 25

Compression:

Stored size: 951 Bytes

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # Decorates Work-like objects with a `#title` and `#page_title` for display.
  class PageTitleDecorator < Draper::Decorator
    ##
    # overlays the `#title` of the object, making an effort to guarantee
    # a reasonable title is found. if one isn't found, it uses an i18n
    # key to produce a generic 'No Title' string.
    #
    # @return [String] a displayable title for this object
    def title
      title = Array(object.try(:title)).join(' | ')
      return title if title.present?
      label = Array(object.try(:label)).join(' | ')
      return label if label.present?

      h.t('hyrax.works.missing_title')
    end

    ##
    # @return [String] a title for pages about this object
    def page_title
      result = "#{object.human_readable_type} [#{object.to_param}] // #{h.application_name}"
      result = title + ' // ' + result if object.persisted?
      result
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/presenters/hyrax/page_title_decorator.rb
hyrax-5.0.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/page_title_decorator.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/page_title_decorator.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.6.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.5.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.4.2 app/presenters/hyrax/page_title_decorator.rb
hyrax-4.0.0.beta1 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.4.1 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.4.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.3.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.2.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.1.0 app/presenters/hyrax/page_title_decorator.rb
hyrax-3.0.2 app/presenters/hyrax/page_title_decorator.rb