Sha256: 056928cfeaba254b9efea908e8286334d0ecda7a3bef089253c742b744411fc3

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    # This is a superset of ResourceSerializer, meant to be used were we need
    # associations and other info. Currently is used on ExploreCurriculums
    # (together with the CurriculumResourceSerializer)
    class ResourceDetailsSerializer < ResourceSerializer
      include ResourceHelper

      attributes :breadcrumb_title, :copyright, :downloads, :grade, :has_related, :id,
                 :opr_description, :opr_standards, :path, :short_title, :subject, :teaser, :time_to_teach,
                 :title, :type

      def downloads
        serialize_download = lambda do |download|
          next unless download.is_a?(ResourceDownload)

          indent = object.pdf_downloads? download.download_category
          {
            id: download.id,
            icon: h.file_icon(download.download.attachment_content_type),
            title: download.download.title,
            url: download_path(download, slug: object.slug),
            preview_url: preview_download_path(id: download, slug: object.slug),
            indent: indent
          }
        end
        object.download_categories.map { |k, v| [k, v.map(&serialize_download)] }
      end

      def copyright
        copyrights_text(object)
      end

      def has_related # rubocop:disable Naming/PredicateName
        false
      end

      def opr_standards
        return unless object.opr? && object.document.present?

        DocumentGenerator.document_presenter.new(object.document).standards
      end

      private

      def h
        ApplicationController.helpers
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.5.4 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.5.3 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.5.2 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.5.1 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.5.0 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.4.2 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.4.1 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.4.0 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.3.1 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.3.0 app/serializers/lcms/engine/resource_details_serializer.rb
lcms-engine-0.2.0 app/serializers/lcms/engine/resource_details_serializer.rb