Skip to content

Commit c0e9717

Browse files
committed
Synchronize the recent changes in openscied-lcms application
1 parent 126095f commit c0e9717

22 files changed

+105
-94
lines changed

app/controllers/admin/documents_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create
2323

2424
@document = reimport_lesson
2525
if @document.save
26-
redirect_to AdminController.document_path(@document.document.id),
26+
redirect_to AdminController.document_path(@document.document),
2727
notice: t('.success', name: @document.document.name)
2828
else
2929
render :new, alert: t('.error')
@@ -79,7 +79,9 @@ def gdoc_files
7979
link = form_params[:link]
8080
if link.match?(%r{/drive/(.*/)?folders/})
8181
folder_id = ::Lt::Google::Api::Drive.folder_id_for(link)
82-
::Lt::Google::Api::Drive.new(google_credentials).list_file_ids_in(folder_id)
82+
::Lt::Google::Api::Drive.new(google_credentials)
83+
.list_file_ids_in(folder_id)
84+
.map { |id| Lt::Lcms::Lesson::Downloader::Gdoc.gdoc_file_url(id) }
8385
else
8486
[link]
8587
end

app/controllers/application_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class ApplicationController < ActionController::Base
1818
render 'pages/not_found', status: :not_found
1919
end
2020

21+
# engine helpers to generate PDF
22+
helper Openscied::Core::PdfHelper
23+
2124
protected
2225

2326
# Raise translation missing errors in controllers too

app/entities/hierarchical_position.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def position_for(type)
6464
val = if !resource.persisted? && resource.send(type)
6565
resource.level_position
6666
else
67-
resource.self_and_ancestors.detect { |res| res.send type }&.level_position
67+
resource.self_and_ancestors_not_persisted.detect { |res| res.send type }&.level_position
6868
end
6969
val ? val + 1 : 0
7070
end

app/jobs/document_generate_pdf_job.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative 'concerns/retry_simple'
4-
53
class DocumentGeneratePdfJob < Lcms::Engine::ApplicationJob
64
include ResqueJob
75

@@ -11,8 +9,8 @@ class DocumentGeneratePdfJob < Lcms::Engine::ApplicationJob
119

1210
PDF_EXPORTERS = {
1311
'full' => DocumentExporter::PDF::Document,
14-
'sm' => DocumentExporter::PDF::StudentMaterial,
15-
'tm' => DocumentExporter::PDF::TeacherMaterial
12+
'sm' => DocumentExporter::PDF::StudentMaterial,
13+
'tm' => DocumentExporter::PDF::TeacherMaterial
1614
}.freeze
1715

1816
def perform(doc, options)

app/jobs/material_generate_pdf_job.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative 'concerns/retry_simple'
4-
53
class MaterialGeneratePDFJob < Lcms::Engine::ApplicationJob
64
include ResqueJob
75

app/models/document.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ class Document < Lcms::Engine::ApplicationRecord
1111
before_save :set_resource_from_metadata
1212

1313
store_accessor :foundational_metadata
14-
store_accessor :metadata
1514
serialize :toc, DocTemplate::Objects::TOCMetadata
1615

1716
scope :actives, -> { where(active: true) }
1817
scope :inactives, -> { where(active: false) }
1918

2019
scope :failed, -> { where(reimported: false) }
2120

22-
scope :where_metadata, ->(key, val) { where('documents.metadata @> hstore(:key, :val)', key: key, val: val) }
21+
scope :where_metadata, ->(key, val) { where('documents.metadata ->> ? = ?', key, val) }
2322

2423
scope :order_by_curriculum, lambda {
2524
select('documents.*, resources.hierarchical_position')
@@ -36,13 +35,14 @@ class Document < Lcms::Engine::ApplicationRecord
3635
scope :filter_by_grade, ->(grade) { where_metadata(:grade, grade) }
3736

3837
scope :filter_by_unit, lambda { |u|
39-
where("(lower(documents.metadata -> 'unit') = :u OR lower(documents.metadata -> 'topic') = :u)", u: u.to_s.downcase)
38+
where("(lower(documents.metadata ->> 'unit') = :u OR lower(documents.metadata ->> 'topic') = :u)",
39+
u: u.to_s.downcase)
4040
}
4141

4242
scope :filter_by_module, lambda { |mod|
4343
sql = <<-SQL
44-
(documents.metadata @> hstore('subject', 'math') AND documents.metadata @> hstore('unit', :mod))
45-
OR (documents.metadata @> hstore('subject', 'ela') AND documents.metadata @> hstore('module', :mod))
44+
(documents.metadata ->> 'subject' <> 'ela' AND documents.metadata ->> 'unit' = :mod)
45+
OR (documents.metadata ->> 'subject' = 'ela' AND documents.metadata ->> 'module' = :mod)
4646
SQL
4747
where(sql, mod: mod)
4848
}

app/models/resource.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Resource < Lcms::Engine::ApplicationRecord
6464
validates :url, presence: true, url: true, if: %i(video? podcast?)
6565

6666
scope :where_grade, ->(grades) { where_metadata_in :grade, grades }
67+
scope :where_module, ->(modules) { where_metadata_in :module, modules }
6768
scope :where_subject, ->(subjects) { where_metadata_in :subject, subjects }
6869
scope :media, -> { where(resource_type: MEDIA_TYPES) }
6970
scope :generic_resources, -> { where(resource_type: GENERIC_TYPES) }
@@ -271,15 +272,18 @@ def add_grade_author(author)
271272
grade.save
272273
end
273274

274-
def update_metadata
275+
def self_and_ancestors_not_persisted
275276
# during create we can't call self_and_ancestors directly on the resource
276277
# because this query uses the associations on resources_hierarchies
277278
# which are only created after the resource is persisted
278-
chain = [self] + parent&.self_and_ancestors.to_a
279+
[self] + parent&.self_and_ancestors.to_a
280+
end
279281

280-
meta = chain.each_with_object({}) do |r, obj|
281-
obj[r.curriculum_type] = r.short_title
282-
end.compact
282+
def update_metadata
283+
meta = self_and_ancestors_not_persisted
284+
.each_with_object({}) do |r, obj|
285+
obj[r.curriculum_type] = r.short_title
286+
end.compact
283287
metadata.merge! meta if meta.present?
284288
end
285289

app/presenters/content_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def padding_styles(align_type: 'padding')
6464
def render_content(context_type, options = {})
6565
options[:parts_index] = document_parts_index
6666
rendered_layout = DocumentRenderer::Part.call(layout_content(context_type), options)
67-
content = HtmlSanitizer.clean_content(rendered_layout, context_type)
67+
content = DocTemplate.sanitizer.clean_content(rendered_layout, context_type)
6868
ReactMaterialsResolver.resolve(content, self)
6969
end
7070
end

app/presenters/material_presenter.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class MaterialPresenter < ContentPresenter
55
attr_reader :parsed_document
66

77
delegate :css_styles, :short_url, :subject, to: :lesson
8-
delegate :sheet_type, to: :metadata
98
delegate :parts, to: :parsed_document
109

1110
DEFAULT_TITLE = 'Material'
@@ -15,17 +14,13 @@ def anchors
1514
end
1615

1716
def base_filename(with_version: true)
18-
name = identifier
17+
name = metadata['identifier']
1918
unless name =~ /^(math|ela)/i || pdf?
2019
name = "#{lesson.short_breadcrumb(join_with: '_', with_short_lesson: true)}_#{name}"
2120
end
2221
with_version ? "#{name}_v#{version.presence || 1}" : name
2322
end
2423

25-
def identifier
26-
metadata['identifier']
27-
end
28-
2924
def cc_attribution
3025
metadata['cc_attribution'].presence || lesson&.cc_attribution
3126
end
@@ -102,6 +97,10 @@ def render_content(context_type, options = {})
10297
DocumentRenderer::Part.call(layout_content(context_type), options)
10398
end
10499

100+
def sheet_type
101+
metadata['sheet_type'].to_s
102+
end
103+
105104
def show_title?
106105
(metadata['show_title'].presence || 'yes').casecmp('yes').zero?
107106
end

app/views/devise/confirmations/new.html.erb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
<div class="row u-od-margin-top--gutter2x">
2-
<div class="columns u-od-padding-v--large">
3-
<div class="o-od-devise-form__wrap">
4-
<h1 class="u-od-margin-bottom--gutter">Resend confirmation instructions</h1>
1+
<div class="o-page">
2+
<div class="o-page__content u-pd-content">
3+
<div class="u-centered u-container--condensed">
4+
<h1 class="u-margin-bottom--large">Resend confirmation instructions</h1>
5+
<div class="u-hr-small u-margin-bottom--xlarge"></div>
56

67
<%= form_for(resource, as: resource_name, url: user_confirmation_path, html: { method: :post }) do |f| %>
7-
<%= f.email_field :email, autofocus: true, class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:access_code].present? ? ' o-od-input-error' : ''), placeholder: 'Enter your email', value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
8+
<%= f.email_field :email, autofocus: true, class: 'o-input-placehoder--medium-gray' + (resource.errors[:access_code].present? ? ' o-input-error' : ''), placeholder: 'Enter your email', value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
89
<% if resource.errors[:email].present? %>
9-
<p class="u-od-cs-txt-link--alert">
10+
<p class="cs-txt-link--error">
1011
Email <%= resource.errors[:email].first %>
1112
</p>
1213
<% end %>
1314

14-
<%= f.submit 'Resend confirmation instructions', class: 'o-od-btn o-od-btn--xs-full o-od-btn--primary' %>
15+
<%= f.submit 'Resend confirmation instructions', class: 'o-btn o-btn--xs-full o-btn--yellow o-btn--xs-full' %>
1516
<% end %>
1617

17-
<div class="u-od-margin-bottom--gutter u-od-margin-top--gutter">
18+
<div class="u-margin-bottom--xlarge u-margin-top--xlarge">
1819
<%= link_to 'Back to Login', new_user_session_path %>
1920
</div>
2021
</div>

app/views/devise/passwords/edit.html.erb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
<div class="row u-od-margin-top--gutter2x">
2-
<div class="columns u-od-padding-v--large">
3-
<div class="o-od-devise-form__wrap">
4-
<h1 class="u-od-margin-bottom--gutter">Change your password</h1>
1+
<div class="o-page">
2+
<div class="o-page__content u-pd-content">
3+
<div class="u-centered u-container--condensed">
4+
<h1 class="u-margin-bottom--large">Change your password</h1>
5+
<div class="u-hr-small u-margin-bottom--xlarge"></div>
56

67
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
78
<%= f.hidden_field :reset_password_token %>
8-
<%= f.password_field :password, autocomplete: 'off', autofocus: true, class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:password].present? ? ' o-od-input-error' : ''), placeholder: 'Enter new password' %>
9+
<%= f.password_field :password, autocomplete: 'off', autofocus: true, class: 'o-input-placehoder--medium-gray' + (resource.errors[:password].present? ? ' o-input-error' : ''), placeholder: 'Enter new password' %>
910
<% if resource.errors[:password].present? %>
10-
<p class="u-od-cs-txt-link--alert">
11+
<p class="cs-txt-link--error">
1112
Password <%= resource.errors[:password].first %>
1213
</p>
1314
<% end %>
14-
<%= f.password_field :password_confirmation, autocomplete: 'off', class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:password_confirmation].present? ? ' o-od-input-error' : ''), placeholder: 'Confirm new password' %>
15+
<%= f.password_field :password_confirmation, autocomplete: 'off', class: 'o-input-placehoder--medium-gray' + (resource.errors[:password_confirmation].present? ? ' o-input-error' : ''), placeholder: 'Confirm new password' %>
1516
<% if resource.errors[:password_confirmation].present? %>
16-
<p class="u-od-cs-txt-link--alert">
17+
<p class="cs-txt-link--error">
1718
<%= resource.errors[:password_confirmation].first %>
1819
</p>
1920
<% end %>
20-
<%= f.submit 'Change my password', class: 'o-od-btn o-od-btn--xs-full o-od-btn--primary' %>
21+
<%= f.submit 'Change my password', class: 'o-btn o-btn--xs-full o-btn--yellow o-btn--xs-full' %>
2122
<% end %>
2223
</div>
2324
</div>
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
<div class="row u-od-margin-top--gutter2x u-od-margin-bottom--gutter">
2-
<div class="columns u-od-padding-v--large">
3-
<div class="o-od-devise-form__wrap">
4-
<h1 class="u-od-margin-bottom--gutter">Forgot your password?</h1>
1+
<div class="o-page">
2+
<div class="o-page__content u-pd-content">
3+
<div class="u-centered u-container--condensed">
4+
<h1 class="u-margin-bottom--large">Forgot your password?</h1>
5+
<div class="u-hr-small u-margin-bottom--xlarge"></div>
56

67
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
7-
<%= f.email_field :email, autofocus: true, class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:access_code].present? ? ' o-od-input-error' : ''), placeholder: 'Enter your email' %>
8+
<%= f.email_field :email, autofocus: true, class: 'o-input-placehoder--medium-gray' + (resource.errors[:access_code].present? ? ' o-input-error' : ''), placeholder: 'Enter your email' %>
89
<% if resource.errors[:email].present? %>
9-
<p class="u-od-cs-txt-link--alert">
10+
<p class="cs-txt-link--error">
1011
Email <%= resource.errors[:email].first %>
1112
</p>
1213
<% end %>
1314

14-
<%= f.submit 'Send me reset password instructions', class: 'o-od-btn o-od-btn--xs-full o-od-btn--primary' %>
15+
<%= f.submit 'Send me reset password instructions', class: 'o-btn o-btn--xs-full o-btn--yellow o-btn--xs-full' %>
1516
<% end %>
1617

17-
<% if false %>
18-
<div class="u-od-margin-bottom--gutter u-od-margin-top--gutter">
19-
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
20-
</div>
21-
<% end %>
18+
<div class="u-margin-bottom--xlarge u-margin-top--xlarge">
19+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
20+
</div>
2221
</div>
2322
</div>
2423
</div>

app/views/devise/registrations/new.html.erb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
<div class="row u-od-margin-top--gutter2x">
2-
<div class="columns u-od-padding-v--large">
3-
<div class="o-od-devise-form__wrap">
4-
<h1 class="u-od-margin-bottom--gutter">Register</h1>
1+
<div class="o-page">
2+
<div class="o-page__content u-pd-content">
3+
<div class="u-centered u-container--condensed">
4+
<h1 class="u-margin-bottom--large">Register</h1>
5+
<div class="u-hr-small u-margin-bottom--xlarge"></div>
56

67
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
7-
<%= f.text_field :access_code, autofocus: true, class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:access_code].present? ? ' o-od-input-error' : ''), placeholder: 'Enter access code', value: @code %>
8+
<%= f.text_field :access_code, autofocus: true, class: 'o-input-placehoder--medium-gray' + (resource.errors[:access_code].present? ? ' o-input-error' : ''), placeholder: 'Enter access code', value: @code %>
89
<% if resource.errors[:access_code].present? %>
9-
<p class="u-od-cs-txt-link--alert">
10+
<p class="cs-txt-link--error">
1011
Access code <%= resource.errors[:access_code].first %>
1112
</p>
1213
<% end %>
13-
<%= f.email_field :email, class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:email].present? ? ' o-od-input-error' : ''), placeholder: 'Enter email address' %>
14+
<%= f.email_field :email, class: 'o-input-placehoder--medium-gray' + (resource.errors[:email].present? ? ' o-input-error' : ''), placeholder: 'Enter email address' %>
1415
<% if resource.errors[:email].present? %>
15-
<p class="u-od-cs-txt-link--alert">
16+
<p class="cs-txt-link--error">
1617
Email <%= resource.errors[:email].first %>
1718
</p>
1819
<% end %>
19-
<%= f.password_field :password, autocomplete: 'off', class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:password].present? ? ' o-od-input-error' : ''), placeholder: 'Enter a password' %>
20+
<%= f.password_field :password, autocomplete: 'off', class: 'o-input-placehoder--medium-gray' + (resource.errors[:password].present? ? ' o-input-error' : ''), placeholder: 'Enter a password' %>
2021
<% if resource.errors[:password].present? %>
21-
<p class="u-od-cs-txt-link--alert">
22+
<p class="cs-txt-link--error">
2223
Password <%= resource.errors[:password].first %>
2324
</p>
2425
<% end %>
25-
<%= f.password_field :password_confirmation, autocomplete: 'off', class: 'o-od-input-placeholder--medium-gray' + (resource.errors[:password_confirmation].present? ? ' o-od-input-error' : ''), placeholder: 'Confirm your password' %>
26+
<%= f.password_field :password_confirmation, autocomplete: 'off', class: 'o-input-placehoder--medium-gray' + (resource.errors[:password_confirmation].present? ? ' o-input-error' : ''), placeholder: 'Confirm your password' %>
2627
<% if resource.errors[:password_confirmation].present? %>
27-
<p class="u-od-cs-txt-link--alert">
28+
<p class="cs-txt-link--error">
2829
<%= resource.errors[:password_confirmation].first %>
2930
</p>
3031
<% end %>
31-
<%= f.submit 'Register', class: 'o-od-btn o-od-btn--xs-full o-od-btn--primary' %>
32+
<%= f.submit 'Register', class: 'o-btn o-btn--xs-full o-btn--yellow o-btn--xs-full' %>
3233
<% end %>
3334

34-
<div class="u-od-margin-bottom--gutter u-od-margin-top--gutter">
35+
<div class="u-margin-bottom--xlarge u-margin-top--xlarge">
3536
<%= link_to 'Back to Login', new_user_session_path %>
3637
</div>
3738
</div>

lcms-engine.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ Gem::Specification.new do |s|
3737
s.add_development_dependency 'bundler-audit', '~> 0.6.0'
3838
s.add_development_dependency 'overcommit', '~> 0.46'
3939
s.add_development_dependency 'rspec-rails', '~> 3.8'
40-
s.add_development_dependency 'rubocop', '~> 0.59'
40+
s.add_development_dependency 'rubocop', '~> 0.59.2'
4141
end

lib/concerns/doc_template/template.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def metadata
5757
def parse(source)
5858
doc = Nokogiri::HTML(source)
5959
# get css styles from head to keep classes for lists (preserve list-style-type)
60-
doc = HtmlSanitizer.process_list_styles doc
61-
@css_styles = HtmlSanitizer.sanitize_css(doc.xpath('//html/head/style/text()').to_s)
60+
doc = DocTemplate.sanitizer.process_list_styles doc
61+
@css_styles = DocTemplate.sanitizer.sanitize_css(doc.xpath('//html/head/style/text()').to_s)
6262

6363
# initial content sanitization
6464
body_node = ::DocTemplate
@@ -108,7 +108,7 @@ def remove_part(type, context_type)
108108

109109
def render(options = {})
110110
type = options.fetch(:context_type, ::DocTemplate.context_types.first)
111-
HtmlSanitizer.post_processing(@documents[type]&.render.presence || '', options)
111+
DocTemplate.sanitizer.post_processing(@documents[type]&.render.presence || '', options)
112112
end
113113

114114
module ClassMethods

lib/doc_template.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def document_contexts
4545
def material_contexts
4646
@material_contexts ||= Array.wrap(config['material_contexts']).presence || DEFAULTS[:materials_contexts]
4747
end
48+
49+
def sanitizer
50+
@sanitizer ||= config['sanitizer'].constantize
51+
end
4852
end
4953
end
5054

lib/doc_template/document.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def add_custom_nodes
5252
return unless @opts[:metadata].try(:subject).to_s.casecmp('ela').zero?
5353
return unless ela_teacher_guidance_allowed?
5454

55-
HtmlSanitizer.strip_content(@nodes)
55+
DocTemplate.sanitizer.strip_content(@nodes)
5656
@nodes.prepend_child ela_teacher_guidance(@opts[:metadata], @opts[:context_type])
5757
end
5858

5959
def ela_teacher_guidance(metadata, _context_type)
6060
@data = metadata
61-
@data.preparation = HtmlSanitizer.strip_html_element(@data.preparation)
61+
@data.preparation = DocTemplate.sanitizer.strip_html_element(@data.preparation)
6262
template = File.read ELA_TG_TEMPLATE
6363
ERB.new(template).result(binding)
6464
end

lib/doc_template/objects/sections_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def self.build_from(data, template_type)
4242
copy = Marshal.load Marshal.dump(data)
4343
sections = copy.map do |metadata|
4444
metadata[:template_type] = template_type
45-
metadata[:summary] = HtmlSanitizer.strip_html_element(metadata[:summary])
45+
metadata[:summary] = DocTemplate.sanitizer.strip_html_element(metadata[:summary])
4646
metadata.transform_keys { |k| k.to_s.gsub('section-', '').underscore }
4747
end
4848
new(set_index(children: sections))

0 commit comments

Comments
 (0)