diff --git a/lib/cc/exporter/web_zip/exportable.rb b/lib/cc/exporter/web_zip/exportable.rb new file mode 100644 index 00000000000..5679860f2d2 --- /dev/null +++ b/lib/cc/exporter/web_zip/exportable.rb @@ -0,0 +1,15 @@ +module CC::Exporter::WebZip + module Exportable + def content_cartridge + self.attachment + end + + def convert_to_offline_web_zip + exporter = CC::Exporter::WebZip::Exporter.new(content_cartridge.open, false) + zip = CC::Exporter::WebZip::ZipPackage.new(exporter) + result = zip.create + exporter.cleanup_files + result + end + end +end \ No newline at end of file diff --git a/lib/cc/exporter/web_zip/exporter.rb b/lib/cc/exporter/web_zip/exporter.rb new file mode 100644 index 00000000000..15afa9c1c00 --- /dev/null +++ b/lib/cc/exporter/web_zip/exporter.rb @@ -0,0 +1,9 @@ +module CC::Exporter::WebZip + class Exporter < CC::Exporter::Epub::Exporter + + # override epub exporter templates + def templates + + end + end +end \ No newline at end of file diff --git a/lib/cc/exporter/web_zip/zip_package.rb b/lib/cc/exporter/web_zip/zip_package.rb new file mode 100644 index 00000000000..02f67cf4ebf --- /dev/null +++ b/lib/cc/exporter/web_zip/zip_package.rb @@ -0,0 +1,5 @@ +module CC::Exporter::WebZip + class ZipPackage < CC::Exporter::Epub::FilesDirectory + + end +end \ No newline at end of file diff --git a/spec/lib/cc/exporter/web_zip/exportable_spec.rb b/spec/lib/cc/exporter/web_zip/exportable_spec.rb new file mode 100644 index 00000000000..43240578b39 --- /dev/null +++ b/spec/lib/cc/exporter/web_zip/exportable_spec.rb @@ -0,0 +1,48 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '/../../cc_spec_helper') + +describe "Exportable" do + class ExportableTest + include CC::Exporter::WebZip::Exportable + + def attachment + @_attachment ||= Attachment.create({ + context: Course.create, + filename: 'exportable-test-file', + uploaded_data: File.open(cartridge_path) + }) + end + + def cartridge_path + File.join(File.dirname(__FILE__), "/../../../../fixtures/migration/unicode-filename-test-export.imscc") + end + end + + context "#convert_to_epub" do + + before do + @epub_export = ExportableTest.new.convert_to_offline_web_zip + end + + let(:zip_path) do + @epub_export + end + + let(:zip) do + File.open(zip_path) + end + + it "should create a zip file" do + expect(zip).not_to be_nil + end + + it "creates a zip file whose name includes the cartridge's name" do + expect(zip_path).to include('unicode-filename-test') + end + + after do + File.delete(zip_path) if File.exist?(zip_path) + end + end + +end diff --git a/spec/lib/cc/exporter/web_zip/exporter_spec.rb b/spec/lib/cc/exporter/web_zip/exporter_spec.rb new file mode 100644 index 00000000000..4affbafb5c5 --- /dev/null +++ b/spec/lib/cc/exporter/web_zip/exporter_spec.rb @@ -0,0 +1,29 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '/../../cc_spec_helper') + +describe "Exporter" do + include CC::Exporter::WebZip + + before(:once) do + def cartridge_path + File.join(File.dirname(__FILE__), "/../../../../fixtures/exporter/cc-with-modules-export.imscc") + end + + @attachment = Attachment.create({ + context: course, + filename: 'exportable-test-file', + uploaded_data: File.open(cartridge_path) + }) + + end + + context "create web zip package default settings" do + let(:exporter) do + CC::Exporter::WebZip::Exporter.new(@attachment.open) + end + + it "should sort content by module" do + expect(exporter.base_template).to eq "../templates/module_sorting_template.html.erb" + end + end +end