Class: Lcms::Engine::MaterialPresenter
Constant Summary
collapse
- DEFAULT_TITLE =
'Material'
ContentPresenter::CONFIG_PATH, ContentPresenter::DEFAULT_CONFIG, ContentPresenter::MATERIALS_CONFIG_PATH, ContentPresenter::PDF_EXT, ContentPresenter::THUMB_EXT
Instance Attribute Summary collapse
Instance Method Summary
collapse
base_config, #config, #footer_margin_styles, #gdoc_key, #initialize, materials_config, #materials_config_for, #padding_styles
#initialize, #t
Instance Attribute Details
#document ⇒ Object
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
#anchors ⇒ Object
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 = metadata['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_attribution ⇒ Object
24
25
26
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 24
def cc_attribution
metadata['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_type ⇒ Object
32
33
34
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 32
def content_type
metadata['type']
end
|
#full_breadcrumb ⇒ Object
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_folder ⇒ Object
40
41
42
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 40
def gdoc_folder
"#{document.id}_v#{document.version}"
end
|
#gdoc_preview_title ⇒ Object
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_url ⇒ Object
48
49
50
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 48
def gdoc_url
material_url('gdoc')
end
|
52
53
54
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 52
def
config[:header]
end
|
56
57
58
59
60
61
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 56
def
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_filename ⇒ Object
72
73
74
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 72
def material_filename
"materials/#{id}/#{base_filename}"
end
|
#name_date? ⇒ Boolean
63
64
65
66
67
68
69
70
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 63
def name_date?
!metadata['name_date'].to_s.casecmp('no').zero? && config[:name_date]
end
|
#orientation ⇒ Object
76
77
78
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 76
def orientation
metadata['orientation'].presence || super
end
|
#pdf_filename ⇒ Object
80
81
82
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 80
def pdf_filename
"#{document.id}/#{base_filename}"
end
|
#pdf_preview_title ⇒ Object
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_url ⇒ Object
84
85
86
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 84
def pdf_url
material_url('url')
end
|
#preserve_table_padding? ⇒ Boolean
92
93
94
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 92
def preserve_table_padding?
(metadata['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_type ⇒ Object
101
102
103
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 101
def sheet_type
metadata['sheet_type'].to_s
end
|
#show_title? ⇒ Boolean
105
106
107
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 105
def show_title?
(metadata['show_title'].presence || 'yes').casecmp('yes').zero?
end
|
#student_material? ⇒ Boolean
109
110
111
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 109
def student_material?
::Material.where(id: id).gdoc.where_metadata_any_of(materials_config_for(:student)).exists?
end
|
#subtitle ⇒ Object
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
117
118
119
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 117
def teacher_material?
::Material.where(id: id).gdoc.where_metadata_any_of(materials_config_for(:teacher)).exists?
end
|
#thumb_url ⇒ Object
125
126
127
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 125
def thumb_url
material_url('thumb')
end
|
#title ⇒ Object
121
122
123
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 121
def title
metadata['title'].presence || config[:title].presence || DEFAULT_TITLE
end
|
#unit_level? ⇒ Boolean
129
130
131
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 129
def unit_level?
metadata['breadcrumb_level'] == 'unit'
end
|
#vertical_text? ⇒ Boolean
133
134
135
|
# File 'app/presenters/lcms/engine/material_presenter.rb', line 133
def vertical_text?
metadata['vertical_text'].present?
end
|