Module: Lcms::Engine::ResourceHelper

Included in:
ResourceDetailsSerializer, ResourceInstructionSerializer, ResourceSerializer
Defined in:
app/helpers/lcms/engine/resource_helper.rb

Instance Method Summary collapse

Instance Method Details

#back_to_resource_path(resource) ⇒ Object



20
21
22
23
# File 'app/helpers/lcms/engine/resource_helper.rb', line 20

def back_to_resource_path(resource)
  slug = resource.lesson? && resource.parent ?  resource.parent.slug : resource.slug
  CGI.unescape(explore_curriculum_index_path(p: slug, e: 1))
end

#copyrights_text(object) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/lcms/engine/resource_helper.rb', line 25

def copyrights_text(object)
  cc_descriptions = []
  object.copyrights.each do |copyright|
    cc_descriptions << copyright.value.strip if copyright.value.present?
  end
  object.copyrights.pluck(:disclaimer).uniq.each do |disclaimer|
    cc_descriptions << disclaimer.strip if disclaimer.present?
  end
  cc_descriptions.join(' ')
end

#download_per_category_limitObject



36
37
38
# File 'app/helpers/lcms/engine/resource_helper.rb', line 36

def download_per_category_limit
  ResourceDownload::DOWNLOAD_PER_CATEGORY_LIMIT
end

#prerequisites_standards(resource) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'app/helpers/lcms/engine/resource_helper.rb', line 65

def prerequisites_standards(resource)
  ids = StandardLink
          .where(standard_end_id: resource.standards.pluck(:id))
          .where.not(link_type: 'c')
          .pluck(:standard_begin_id)
  Standard
    .where(id: ids).pluck(:alt_names).flatten.uniq
    .map { |n| Standard.filter_ccss_standards(n, resource.subject) }.compact.sort
end


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/lcms/engine/resource_helper.rb', line 40

def resource_breadcrumbs_with_links(resource)
  return GenericPresenter.new(resource).generic_title if resource.generic?

  breadcrumbs = Breadcrumbs.new(resource)
  pieces = breadcrumbs.full_title.split(' / ')
  short_pieces = breadcrumbs.short_title.split(' / ')

  [].tap do |result|
    pieces.each_with_index do |piece, idx|
      ((result << piece) && next) if idx.zero?

      slug = Slug.build_from(pieces[0..idx])

      link = link_to show_with_slug_path(slug) do
        show = (:span, piece, class: 'show-for-ipad')
        short_piece = idx == pieces.size - 1 ? piece : short_pieces[idx]
        hide = (:span, short_piece, class: 'hide-for-ipad')
        "#{show} #{hide}".html_safe
      end

      result << link
    end
  end.join(' / ').html_safe
end

#show_resource_path(resource) ⇒ Object



8
9
10
11
12
13
14
# File 'app/helpers/lcms/engine/resource_helper.rb', line 8

def show_resource_path(resource)
  if resource.slug.present?
    show_with_slug_path(resource.slug)
  else
    resource_path(resource)
  end
end

#type_name(resource) ⇒ Object



16
17
18
# File 'app/helpers/lcms/engine/resource_helper.rb', line 16

def type_name(resource)
  resource.curriculum_type&.capitalize
end