Class: Lcms::Engine::DocumentPresenter
Constant Summary
collapse
- PDF_SUBTITLES =
{ full: '', sm: '_student_materials', tm: '_teacher_materials' }.freeze
- SUBJECT_FULL =
{ 'ela' => 'ELA', 'math' => 'Math' }.freeze
- TOC_RESOURCES =
[I18n.t('document.toc.tm'), I18n.t('document.toc.sm'), I18n.t('document.toc.credits')].freeze
- TOPIC_FULL =
{ 'ela' => 'Unit', 'math' => 'Topic' }.freeze
- TOPIC_SHORT =
{ 'ela' => 'U', 'math' => 'T' }.freeze
ContentPresenter::CONFIG_PATH, ContentPresenter::DEFAULT_CONFIG, ContentPresenter::MATERIALS_CONFIG_PATH, ContentPresenter::PDF_EXT, ContentPresenter::THUMB_EXT
Instance Method Summary
collapse
base_config, #base_filename, #config, #content_type, #footer_margin_styles, #gdoc_folder, #gdoc_key, #initialize, materials_config, #materials_config_for, #orientation, #padding_styles
#initialize, #t
Instance Method Details
#cc_attribution ⇒ Object
14
15
16
17
18
19
20
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 14
def cc_attribution
core_cc = ld_metadata.cc_attribution
return core_cc if (fs_cc = fs_metadata.cc_attribution).blank?
return core_cc if core_cc.casecmp(fs_cc).zero?
"#{core_cc} #{fs_cc}"
end
|
#color_code ⇒ Object
22
23
24
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 22
def color_code
"#{subject}-base"
end
|
#color_code_grade ⇒ Object
26
27
28
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 26
def color_code_grade
"#{subject}-#{grade}"
end
|
#content_for(context_type, options = {}) ⇒ Object
30
31
32
33
34
35
36
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 30
def content_for(context_type, options = {})
with_excludes = (options[:excludes] || []).any?
content = render_content(context_type, options)
content = update_activity_timing(content) if with_excludes
content = remove_optional_break(content) if ela? && with_excludes
content
end
|
#description ⇒ Object
38
39
40
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 38
def description
ld_metadata.lesson_objective.presence || ld_metadata.description
end
|
#doc_type ⇒ Object
42
43
44
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 42
def doc_type
assessment? ? 'assessment' : 'lesson'
end
|
#ela2? ⇒ Boolean
46
47
48
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 46
def ela2?
ela? && grade.to_s == '2'
end
|
#ela6? ⇒ Boolean
50
51
52
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 50
def ela6?
ela? && grade.to_s == '6'
end
|
#full_breadcrumb(unit_level: false) ⇒ Object
58
59
60
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 58
def full_breadcrumb(unit_level: false)
resource ? Breadcrumbs.new(resource).full_title : full_breadcrumb_from_metadata(unit_level)
end
|
62
63
64
65
66
67
68
69
70
71
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 62
def full_breadcrumb_from_metadata(unit_level)
lesson_level = assessment? ? 'Assessment' : "Lesson #{lesson}" unless unit_level
[
SUBJECT_FULL[subject] || subject,
grade.to_i.zero? ? grade : "Grade #{grade}",
ll_strand? ? ld_module : "Module #{ld_module.try(:upcase)}",
topic.present? ? "#{TOPIC_FULL[subject]} #{topic.try(:upcase)}" : nil,
lesson_level
].compact.join(' / ')
end
|
#grade ⇒ Object
73
74
75
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 73
def grade
ld_metadata.grade[/\d+/] || ld_metadata.grade
end
|
#ld_module ⇒ Object
87
88
89
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 87
def ld_module
ela? ? ld_metadata.module : ld_metadata.unit
end
|
#lesson ⇒ Object
91
92
93
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 91
def lesson
ld_metadata.lesson
end
|
#ll_strand? ⇒ Boolean
95
96
97
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 95
def ll_strand?
ld_metadata.module =~ /strand/i
end
|
#math_practice ⇒ Object
99
100
101
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 99
def math_practice
ld_metadata.lesson_mathematical_practice.squish
end
|
#pdf_filename ⇒ Object
107
108
109
110
111
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 107
def pdf_filename
name = short_breadcrumb(join_with: '_', with_short_lesson: true)
name += PDF_SUBTITLES[content_type.to_sym]
"#{name}_v#{version.presence || 1}#{Lcms::Engine::ContentPresenter::PDF_EXT}"
end
|
113
114
115
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 113
def
full_breadcrumb
end
|
103
104
105
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 103
def
"UnboundEd / #{full_breadcrumb}"
end
|
#remove_optional_break(content) ⇒ Object
77
78
79
80
81
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 77
def remove_optional_break(content)
html = Nokogiri::HTML.fragment content
html.at_css('.o-ld-optbreak-wrapper')&.remove
html.to_html
end
|
#render_content(context_type, options = {}) ⇒ Object
#short_breadcrumb(join_with: ' / ', with_short_lesson: false, with_subject: true, unit_level: false) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 137
def short_breadcrumb(join_with: ' / ', with_short_lesson: false, with_subject: true, unit_level: false)
unless unit_level
lesson_abbr =
if assessment?
with_short_lesson ? 'A' : 'Assessment'
else
with_short_lesson ? "L#{lesson}" : "Lesson #{lesson}"
end
end
[
with_subject ? SUBJECT_FULL[subject] || subject : nil,
grade.to_i.zero? ? grade : "G#{grade}",
ll_strand? ? 'LL' : "M#{ld_module.try(:upcase)}",
topic.present? ? "#{TOPIC_SHORT[subject]}#{topic.try(:upcase)}" : nil,
lesson_abbr
].compact.join(join_with)
end
|
#short_title ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
156
157
158
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 156
def short_title
assessment? ? doc_type : "Lesson #{lesson}"
end
|
#short_url ⇒ Object
160
161
162
163
164
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 160
def short_url
@short_url ||= Bitly.client
.shorten(document_url(self))
.short_url
end
|
#standards ⇒ Object
166
167
168
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 166
def standards
ld_metadata.standard.presence || ld_metadata.lesson_standard
end
|
#student_materials ⇒ Object
170
171
172
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 170
def student_materials
materials.gdoc.where_metadata_any_of(materials_config_for(:student))
end
|
#student_materials_props ⇒ Object
#subject ⇒ Object
178
179
180
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 178
def subject
ld_metadata&.resource_subject
end
|
#subject_to_str ⇒ Object
182
183
184
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 182
def subject_to_str
SUBJECT_FULL[subject] || subject
end
|
#teacher_materials ⇒ Object
191
192
193
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 191
def teacher_materials
materials.gdoc.where_metadata_any_of(materials_config_for(:teacher))
end
|
#teacher_materials_props ⇒ Object
#teaser ⇒ Object
199
200
201
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 199
def teaser
ld_metadata.teaser
end
|
#title ⇒ Object
186
187
188
189
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 186
def title
title = ld_metadata&.title
resource&.prerequisite? ? "Prerequisite - #{title}" : title
end
|
#topic ⇒ Object
203
204
205
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 203
def topic
ela? ? ld_metadata.unit : ld_metadata.topic
end
|
#unit ⇒ Object
207
208
209
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 207
def unit
@unit ||= resource&.parent
end
|
#update_activity_timing(content) ⇒ Object
Makes sure that time of group is equal to sum of timings of child activities
120
121
122
123
124
125
126
127
|
# File 'app/presenters/lcms/engine/document_presenter.rb', line 120
def update_activity_timing(content)
html = Nokogiri::HTML.fragment content
html.css('.o-ld-group').each do |group|
group_time = group.css('.o-ld-title__time--h3').inject(0) { |time, section| time + section.text.to_i }
group.at_css('.o-ld-title__time--h2').content = group_time.zero? ? "\u2014" : "#{group_time} mins"
end
html.to_html
end
|