Sha256: 90d6bcaac7278868c81cf893440b9d92ecdf18b0a014c37052f659488e2f1f1e

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class ResourcePresenter < SimpleDelegator
      def subject_and_grade_title
        "#{subject.try(:titleize)} #{grades.list.first.try(:titleize)}"
      end

      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

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

      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?

            OpenStruct.new(category: dc, title: dc.title, downloads: downloads, settings: settings)
          end

          uncategorized = download_categories['']
          downloads_list << OpenStruct.new(downloads: uncategorized, settings: {}) if uncategorized.present?

          downloads_list.compact
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lcms-engine-0.3.1 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.1.4 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.3.0 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.1.3 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.2.0 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.1.2 app/presenters/lcms/engine/resource_presenter.rb
lcms-engine-0.1.0 app/presenters/lcms/engine/resource_presenter.rb