handle files added directly to the item list of a module
fixes CNVS-23798 test plan: - Have a course with content separated into modules, including specific files. - Confirm that course is configured to sort by module (default behavior). - Export course as an ePub at `/epub_exports`. - Observe that file names are included as part of the module list. - Click the link to get to the file template. - Observe that the file can be viewed by clicking on the tile name. Change-Id: I28c6afeba668714ed284cc5437fb06d522b4f855 Reviewed-on: https://gerrit.instructure.com/65988 Tested-by: Jenkins Reviewed-by: Matt Berns <mberns@instructure.com> Product-Review: John Corrigan <jcorrigan@instructure.com> QA-Review: John Corrigan <jcorrigan@instructure.com>
This commit is contained in:
parent
164c002aa0
commit
d5797f967b
|
@ -12,7 +12,7 @@ module CC::Exporter::Epub
|
|||
def add_files
|
||||
files.each do |file_data|
|
||||
File.open(file_data[:path_to_file]) do |file|
|
||||
epub.add_item(file_data[:local_path], file, file_data[:migration_id], {
|
||||
epub.add_item(file_data[:local_path], file, file_data[:identifier], {
|
||||
'media-type' => file_data[:media_type]
|
||||
})
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ module CC::Exporter::Epub
|
|||
b.set_primary_identifier(pub_id)
|
||||
b.language = I18n.locale
|
||||
b.add_title(title, nil, GEPUB::TITLE_TYPE::MAIN) do |title|
|
||||
title.file_as = "#{title} Epub"
|
||||
title.file_as = "#{title} ePub"
|
||||
title.display_seq = 1
|
||||
end
|
||||
b.add_creator('Canvas by Instructure') do |creator|
|
||||
|
|
|
@ -57,7 +57,7 @@ module CC::Exporter::Epub::Converters
|
|||
|
||||
def to_h
|
||||
return {
|
||||
migration_id: data['identifier'],
|
||||
identifier: data['identifier'],
|
||||
local_path: local_path,
|
||||
file_name: File.basename(local_path),
|
||||
path_to_file: path_to_file,
|
||||
|
|
|
@ -97,7 +97,12 @@ module CC::Exporter::Epub::Converters
|
|||
#
|
||||
# <audio src='media/audio.mp3' controls='controls' />
|
||||
def convert_audio_tags!(html_node)
|
||||
html_node.search('a.instructure_audio_link, a.audio_comment').each do |audio_link|
|
||||
selector = [
|
||||
"a.instructure_audio_link",
|
||||
"a.audio_comment",
|
||||
"a[href$='mp3']"
|
||||
].join(',')
|
||||
html_node.search(selector).each do |audio_link|
|
||||
audio_link.replace(<<-AUDIO_TAG)
|
||||
<audio src="#{audio_link['href']}" controls="controls">
|
||||
#{I18n.t('Audio content is not supported by your device or app.')}
|
||||
|
@ -117,7 +122,13 @@ module CC::Exporter::Epub::Converters
|
|||
#
|
||||
# <video src='media/video.mp4' controls='controls' />
|
||||
def convert_video_tags!(html_node)
|
||||
html_node.search('a.instructure_video_link, a.video_comment').each do |video_link|
|
||||
selector = [
|
||||
"a.instructure_video_link",
|
||||
"a.video_comment",
|
||||
"a[href$='m4v']",
|
||||
"a[href$='mp4']"
|
||||
].join(',')
|
||||
html_node.search(selector).each do |video_link|
|
||||
video_link.replace(<<-VIDEO_TAG)
|
||||
<video src="#{video_link['href']}" controls="controls">
|
||||
#{I18n.t('Video content is not supported by your device or app.')}
|
||||
|
|
|
@ -35,7 +35,7 @@ module CC::Exporter::Epub::Converters
|
|||
end
|
||||
|
||||
def object_path_selector
|
||||
selector = [
|
||||
return [
|
||||
"a", [
|
||||
"[href*='#{OBJECT_TOKEN.gsub('$', '')}']",
|
||||
"[href*='#{WIKI_TOKEN.gsub('$', '')}']"
|
||||
|
|
|
@ -10,11 +10,13 @@ module CC::Exporter::Epub
|
|||
announcements: "Announcements",
|
||||
topics: "Discussion Topics",
|
||||
quizzes: "Quizzes",
|
||||
pages: "Wiki Pages"
|
||||
pages: "Wiki Pages",
|
||||
files: "Files"
|
||||
}.freeze
|
||||
|
||||
LINKED_RESOURCE_KEY = {
|
||||
"Assignment" => :assignments,
|
||||
"Attachment" => :files,
|
||||
"DiscussionTopic" => :topics,
|
||||
"Quizzes::Quiz" => :quizzes,
|
||||
"WikiPage" => :pages
|
||||
|
@ -34,7 +36,7 @@ module CC::Exporter::Epub
|
|||
def templates
|
||||
@_templates ||= {
|
||||
title: cartridge_json[:title],
|
||||
files: cartridge_json[:files]
|
||||
files: cartridge_json[:files],
|
||||
}.tap do |hash|
|
||||
resources = filter_syllabus_for_modules ? module_ids : LINKED_RESOURCE_KEY.values
|
||||
hash.merge!(
|
||||
|
@ -42,7 +44,7 @@ module CC::Exporter::Epub
|
|||
:announcements => create_universal_template(:announcements)
|
||||
)
|
||||
resources.each do |resource_type|
|
||||
hash.merge!(resource_type => create_content_template(resource_type))
|
||||
hash.reverse_merge!(resource_type => create_content_template(resource_type))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<% if item.has_key?(:local_path) %>
|
||||
<h2 id="<%= item[:identifier] %>">
|
||||
<%= item[:file_name] %>
|
||||
</h2>
|
||||
<%= convert_media_from_string!(<<-HTML)
|
||||
<a href="#{item[:local_path]}">
|
||||
#{I18n.t("Click here to see the file.")}
|
||||
</a>
|
||||
HTML
|
||||
%>
|
||||
<% else %>
|
||||
<h2 id="<%= item[:linked_resource_id] %>">
|
||||
<%= item[:title] %>
|
||||
</h2>
|
||||
<%= I18n.t(
|
||||
"File %{filename} could not be included in the ePub document. Please see separate zip file for access.", {
|
||||
filename: item[:title]
|
||||
})
|
||||
%>
|
||||
<% end %>
|
|
@ -7,7 +7,7 @@
|
|||
<h1 id="<%= content[:migration_id]%>"><%= title %></h1>
|
||||
<ol>
|
||||
<% content[:items].each do |item| %>
|
||||
<li><a href="#<%= "#{item[:identifier]}" %>"><%= item[:title] %></a></li>
|
||||
<li><a href="#<%= "#{item[:linked_resource_id]}" %>"><%= item[:title] %></a></li>
|
||||
<% end %>
|
||||
</ol>
|
||||
<div style="page-break-before:always;"></div>
|
||||
|
|
|
@ -39,7 +39,7 @@ describe "Exporter" do
|
|||
it "should not contain content type keys" do
|
||||
# once we have a more robust imscc we should add another test to check
|
||||
# that the keys reflect the module migration ids
|
||||
content_keys = CC::Exporter::Epub::Exporter::LINKED_RESOURCE_KEY.values
|
||||
content_keys = CC::Exporter::Epub::Exporter::LINKED_RESOURCE_KEY.except("Attachment").values
|
||||
expect(content_keys.any? {|k| exporter.templates.key?(k)}).to be_falsey
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue