Class: Lcms::Engine::MaterialPresenter

Inherits:
ContentPresenter show all
Defined in:
app/presenters/lcms/engine/material_presenter.rb

Constant Summary collapse

DEFAULT_TITLE =
'Material'

Constants inherited from ContentPresenter

ContentPresenter::CONFIG_PATH, ContentPresenter::DEFAULT_CONFIG, ContentPresenter::MATERIALS_CONFIG_PATH, ContentPresenter::PDF_EXT, ContentPresenter::THUMB_EXT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ContentPresenter

base_config, #config, #footer_margin_styles, #gdoc_key, #initialize, materials_config, #materials_config_for, #padding_styles

Methods inherited from BasePresenter

#initialize, #t

Constructor Details

This class inherits a constructor from Lcms::Engine::ContentPresenter

Instance Attribute Details

#documentObject

Returns the value of attribute document.



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

def document
  @document
end

Instance Method Details

#anchorsObject



12
13
14
# File 'app/presenters/lcms/engine/material_presenter.rb', line 12

def anchors
  @anchors || []
end

#base_filename(with_version: true) ⇒ Object



16
17
18
19
20
21
22
# File 'app/presenters/lcms/engine/material_presenter.rb', line 16

def base_filename(with_version: true)
  name = ['identifier']
  unless name =~ /^(math|ela)/i || pdf?
    name = "#{document.short_breadcrumb(join_with: '_', with_short_lesson: true)}_#{name}"
  end
  with_version ? "#{name}_v#{version.presence || 1}" : name
end

#cc_attributionObject



24
25
26
# File 'app/presenters/lcms/engine/material_presenter.rb', line 24

def cc_attribution
  ['cc_attribution'].presence || document&.cc_attribution
end

#content_for(context_type) ⇒ Object



28
29
30
# File 'app/presenters/lcms/engine/material_presenter.rb', line 28

def content_for(context_type)
  render_content(context_type)
end

#content_typeObject



32
33
34
# File 'app/presenters/lcms/engine/material_presenter.rb', line 32

def content_type
  ['type']
end

#full_breadcrumbObject



36
37
38
# File 'app/presenters/lcms/engine/material_presenter.rb', line 36

def full_breadcrumb
  document.full_breadcrumb(unit_level: unit_level?)
end

#gdoc_folderObject



40
41
42
# File 'app/presenters/lcms/engine/material_presenter.rb', line 40

def gdoc_folder
  "#{document.id}_v#{document.version}"
end

#gdoc_preview_titleObject



44
45
46
# File 'app/presenters/lcms/engine/material_presenter.rb', line 44

def gdoc_preview_title
  preview_links['gdoc'].present? ? 'Preview Google Document' : 'Generate Google Document'
end

#gdoc_urlObject



48
49
50
# File 'app/presenters/lcms/engine/material_presenter.rb', line 48

def gdoc_url
  material_url('gdoc')
end

#header?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/presenters/lcms/engine/material_presenter.rb', line 52

def header?
  config[:header]
end

#header_breadcrumbObject



56
57
58
59
60
61
# File 'app/presenters/lcms/engine/material_presenter.rb', line 56

def header_breadcrumb
  short_breadcrumb = document.short_breadcrumb(join_with: '/', unit_level: unit_level?,
                                               with_short_lesson: true, with_subject: false)
  short_title = unit_level? ? document.resource&.parent&.title : document.title
  "#{document.subject.upcase} #{short_breadcrumb} #{short_title}"
end

#material_filenameObject



72
73
74
# File 'app/presenters/lcms/engine/material_presenter.rb', line 72

def material_filename
  "materials/#{id}/#{base_filename}"
end

#name_date?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'app/presenters/lcms/engine/material_presenter.rb', line 63

def name_date?
  # toggle display of name-date row on the header
  # https://github.com/learningtapestry/unbounded/issues/422
  # Added the config definition for new types. If config says "NO", it's
  # impossible to force-add the name-date field.
  # It's impossible only to remove it when config allows it
  !['name_date'].to_s.casecmp('no').zero? && config[:name_date]
end

#orientationObject



76
77
78
# File 'app/presenters/lcms/engine/material_presenter.rb', line 76

def orientation
  ['orientation'].presence || super
end

#pdf_filenameObject



80
81
82
# File 'app/presenters/lcms/engine/material_presenter.rb', line 80

def pdf_filename
  "#{document.id}/#{base_filename}"
end

#pdf_preview_titleObject



88
89
90
# File 'app/presenters/lcms/engine/material_presenter.rb', line 88

def pdf_preview_title
  preview_links['pdf'].present? ? 'Preview PDF' : 'Generate PDF'
end

#pdf_urlObject



84
85
86
# File 'app/presenters/lcms/engine/material_presenter.rb', line 84

def pdf_url
  material_url('url')
end

#preserve_table_padding?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/presenters/lcms/engine/material_presenter.rb', line 92

def preserve_table_padding?
  (['preserve_table_padding'].presence || 'no').casecmp('yes').zero?
end

#render_content(context_type, options = {}) ⇒ Object



96
97
98
99
# File 'app/presenters/lcms/engine/material_presenter.rb', line 96

def render_content(context_type, options = {})
  options[:parts_index] = document_parts_index
  DocumentRenderer::Part.call(layout_content(context_type), options)
end

#sheet_typeObject



101
102
103
# File 'app/presenters/lcms/engine/material_presenter.rb', line 101

def sheet_type
  ['sheet_type'].to_s
end

#show_title?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/presenters/lcms/engine/material_presenter.rb', line 105

def show_title?
  (['show_title'].presence || 'yes').casecmp('yes').zero?
end

#student_material?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/presenters/lcms/engine/material_presenter.rb', line 109

def student_material?
  ::Material.where(id: id).gdoc.(materials_config_for(:student)).exists?
end

#subtitleObject



113
114
115
# File 'app/presenters/lcms/engine/material_presenter.rb', line 113

def subtitle
  config.dig(:subtitle, sheet_type.to_sym).presence || DEFAULT_TITLE
end

#teacher_material?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'app/presenters/lcms/engine/material_presenter.rb', line 117

def teacher_material?
  ::Material.where(id: id).gdoc.(materials_config_for(:teacher)).exists?
end

#thumb_urlObject



125
126
127
# File 'app/presenters/lcms/engine/material_presenter.rb', line 125

def thumb_url
  material_url('thumb')
end

#titleObject



121
122
123
# File 'app/presenters/lcms/engine/material_presenter.rb', line 121

def title
  ['title'].presence || config[:title].presence || DEFAULT_TITLE
end

#unit_level?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'app/presenters/lcms/engine/material_presenter.rb', line 129

def unit_level?
  ['breadcrumb_level'] == 'unit'
end

#vertical_text?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'app/presenters/lcms/engine/material_presenter.rb', line 133

def vertical_text?
  ['vertical_text'].present?
end