Class: Lcms::Engine::ResourcePresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/presenters/lcms/engine/resource_presenter.rb

Direct Known Subclasses

GenericPresenter, MediaPresenter

Instance Method Summary collapse

Instance Method Details

#categorized_downloads_listObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/presenters/lcms/engine/resource_presenter.rb', line 20

def categorized_downloads_list
  @categorized_downloads_list ||= begin
    downloads_list = Lcms::Engine::DownloadCategory.all.map do |dc|
      downloads = Array.wrap(download_categories[dc.title])
      downloads.concat(document_bundles) if dc.bundle?
      settings = download_categories_settings[dc.title.parameterize] || {}

      next unless settings.values.any? || downloads.any?

      data = { category: dc, title: dc.title, downloads: downloads, settings: settings }
      Struct.new(*data.keys, keyword_init: true).new(data)
    end

    if (uncategorized = download_categories['']).present?
      data = { downloads: uncategorized, settings: {} }
      downloads_list << Struct.new(*data.keys, keyword_init: true).new(data)
    end

    downloads_list.compact
  end
end

#downloads_indent(opts = {}) ⇒ Object



16
17
18
# File 'app/presenters/lcms/engine/resource_presenter.rb', line 16

def downloads_indent(opts = {})
  pdf_downloads?(opts[:category]) ? 'u-li-indent' : ''
end

#page_titleObject



10
11
12
13
14
# File 'app/presenters/lcms/engine/resource_presenter.rb', line 10

def page_title
  grade_avg = grades.average || 'base'
  grade_code = grade_avg.include?('k') ? grade_avg : "G#{grade_avg}"
  "#{subject.try(:upcase)} #{grade_code.try(:upcase)}: #{title}"
end

#subject_and_grade_titleObject



6
7
8
# File 'app/presenters/lcms/engine/resource_presenter.rb', line 6

def subject_and_grade_title
  "#{subject.try(:titleize)} #{grades.list.first.try(:titleize)}"
end