moodle2cc 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +4 -0
- data/lib/moodle2cc/cc/converter.rb +1 -1
- data/lib/moodle2cc/cc/web_content.rb +7 -0
- data/lib/moodle2cc/moodle/backup.rb +8 -10
- data/lib/moodle2cc/resource_factory.rb +5 -1
- data/lib/moodle2cc/version.rb +1 -1
- data/lib/test/test_helper.rb +5 -4
- data/moodle2cc.gemspec +1 -1
- data/test/fixtures/moodle_backup/moodle.xml +1 -1
- data/test/unit/canvas/converter_test.rb +1 -1
- data/test/unit/canvas/web_content_test.rb +9 -0
- data/test/unit/cc/converter_test.rb +1 -1
- data/test/unit/resource_factory_test.rb +11 -1
- metadata +6 -6
data/Changelog
CHANGED
@@ -28,7 +28,7 @@ module Moodle2CC::CC
|
|
28
28
|
create_manifest
|
29
29
|
end
|
30
30
|
create_web_resources
|
31
|
-
Zip::
|
31
|
+
Zip::File.open(imscc_tmp_path, Zip::File::CREATE) do |zipfile|
|
32
32
|
Dir["#{@export_dir}/**/*"].each do |file|
|
33
33
|
zipfile.add(file.sub(@export_dir + '/', ''), file)
|
34
34
|
end
|
@@ -10,6 +10,13 @@ module Moodle2CC::CC
|
|
10
10
|
@rel_path = File.join(CC_WIKI_FOLDER, "#{file_slug(@title)}.html")
|
11
11
|
body = mod.alltext
|
12
12
|
body = mod.content || '' if body.nil? || body.length == 0
|
13
|
+
if body.nil? || body.length == 0 && mod.summary
|
14
|
+
body = mod.summary
|
15
|
+
url = mod.reference.to_s.strip
|
16
|
+
unless url.gsub(%r{http(s)?://}, '').length == 0
|
17
|
+
body += %(<p><a href="#{CGI.escapeHTML(url)}" title="#{CGI.escapeHTML(@title)}">#{@title}</a></p>)
|
18
|
+
end
|
19
|
+
end
|
13
20
|
@body = convert_file_path_tokens(body)
|
14
21
|
end
|
15
22
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'zip
|
1
|
+
require 'zip'
|
2
2
|
|
3
3
|
module Moodle2CC::Moodle
|
4
4
|
class Backup
|
@@ -11,8 +11,8 @@ module Moodle2CC::Moodle
|
|
11
11
|
has_one :course, Course
|
12
12
|
|
13
13
|
def self.read(backup_file)
|
14
|
-
Zip::
|
15
|
-
xml = zipfile.
|
14
|
+
Zip::File.open(backup_file) do |zipfile|
|
15
|
+
xml = zipfile.read("moodle.xml")
|
16
16
|
backup = parse xml
|
17
17
|
backup.backup_file = backup_file
|
18
18
|
backup.files = zipfile.entries.select { |e| e.name =~ /^course_files/ && !e.directory? }.
|
@@ -22,14 +22,12 @@ module Moodle2CC::Moodle
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def copy_files_to(dir)
|
25
|
-
Zip::
|
25
|
+
Zip::File.open(@backup_file) do |zipfile|
|
26
26
|
@files.each do |file|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
f.write zip.read
|
32
|
-
end
|
27
|
+
destination_file = File.join(dir, file)
|
28
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
29
|
+
File.open(destination_file, 'w') do |f|
|
30
|
+
f.write zipfile.read("course_files/#{file}")
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -11,7 +11,11 @@ class Moodle2CC::ResourceFactory
|
|
11
11
|
when 'resource'
|
12
12
|
case mod.type
|
13
13
|
when 'file'
|
14
|
-
|
14
|
+
if mod.summary && mod.summary.length > 0
|
15
|
+
@namespace.const_get(:WebContent).new(mod)
|
16
|
+
else
|
17
|
+
@namespace.const_get(:WebLink).new(mod)
|
18
|
+
end
|
15
19
|
when 'html', 'text'
|
16
20
|
@namespace.const_get(:WebContent).new(mod)
|
17
21
|
end
|
data/lib/moodle2cc/version.rb
CHANGED
data/lib/test/test_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'zip
|
1
|
+
require 'zip'
|
2
2
|
|
3
3
|
module TestHelper
|
4
4
|
def create_moodle_backup_zip(backup_name='moodle_backup')
|
5
5
|
moodle_backup_path = File.expand_path("../../../test/tmp/#{backup_name}.zip", __FILE__)
|
6
|
-
Zip::
|
6
|
+
Zip::File.open(moodle_backup_path, Zip::File::CREATE) do |zipfile|
|
7
|
+
zipfile.remove("moodle.xml") if zipfile.find_entry("moodle.xml")
|
7
8
|
zipfile.add("moodle.xml", File.expand_path("../../../test/fixtures/#{backup_name}/moodle.xml", __FILE__))
|
8
9
|
zipfile.mkdir("course_files")
|
9
10
|
zipfile.mkdir("course_files/folder")
|
@@ -24,13 +25,13 @@ module TestHelper
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def get_imsmanifest_xml
|
27
|
-
Zip::
|
28
|
+
Zip::File.open(@converter.imscc_path) do |zipfile|
|
28
29
|
xml = Nokogiri::XML(zipfile.read("imsmanifest.xml"))
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def get_imscc_file(file)
|
33
|
-
Zip::
|
34
|
+
Zip::File.open(@converter.imscc_path) do |zipfile|
|
34
35
|
zipfile.read(file)
|
35
36
|
end
|
36
37
|
end
|
data/moodle2cc.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = %q{Migrates Moodle backup ZIP to IMS Common Cartridge package}
|
9
9
|
gem.homepage = "https://github.com/instructure/moodle2cc"
|
10
10
|
|
11
|
-
gem.add_runtime_dependency "rubyzip"
|
11
|
+
gem.add_runtime_dependency "rubyzip", '~> 1.0.0'
|
12
12
|
gem.add_runtime_dependency "happymapper"
|
13
13
|
gem.add_runtime_dependency "builder"
|
14
14
|
gem.add_runtime_dependency "thor"
|
@@ -502,7 +502,7 @@
|
|
502
502
|
<NAME>About Your Instructor</NAME>
|
503
503
|
<TYPE>file</TYPE>
|
504
504
|
<REFERENCE>http://en.wikipedia.org/wiki/Einstein</REFERENCE>
|
505
|
-
<SUMMARY
|
505
|
+
<SUMMARY>Sometimes these include a summary</SUMMARY>
|
506
506
|
<ALLTEXT></ALLTEXT>
|
507
507
|
<POPUP>resizable=1,scrollbars=1,directories=1,location=1,menubar=1,toolbar=1,status=1,width=1024,height=768</POPUP>
|
508
508
|
<OPTIONS></OPTIONS>
|
@@ -23,7 +23,7 @@ class TestUnitCCConverter < MiniTest::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_it_creates_imsmanifest_xml
|
26
|
-
Zip::
|
26
|
+
Zip::File.open(@converter.imscc_path) do |zipfile|
|
27
27
|
assert zipfile.find_entry("imsmanifest.xml")
|
28
28
|
end
|
29
29
|
end
|
@@ -34,4 +34,13 @@ class TestUnitCanvasWebContent < MiniTest::Unit::TestCase
|
|
34
34
|
assert_equal 'i6447ff05ab6e342a42302007a6e3bcb4', xml.root.xpath('identifierref').text
|
35
35
|
end
|
36
36
|
|
37
|
+
def test_it_creates_web_content_item_from_link_with_summary
|
38
|
+
mod = @backup.course.mods.find { |m| m.mod_type == "resource" &&
|
39
|
+
(!m.summary.nil? && m.summary.length != 0)}
|
40
|
+
mod.type = 'file'
|
41
|
+
web_content = Moodle2CC::Canvas::WebContent.new mod
|
42
|
+
|
43
|
+
assert web_content.body.include?(mod.reference)
|
44
|
+
assert web_content.body.include?(mod.summary)
|
45
|
+
end
|
37
46
|
end
|
@@ -23,7 +23,7 @@ class TestUnitCCConverter < MiniTest::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_it_creates_imsmanifest_xml
|
26
|
-
Zip::
|
26
|
+
Zip::File.open(@converter.imscc_path) do |zipfile|
|
27
27
|
assert zipfile.find_entry("imsmanifest.xml")
|
28
28
|
end
|
29
29
|
end
|
@@ -69,8 +69,18 @@ class TestUnitCCResource < MiniTest::Unit::TestCase
|
|
69
69
|
assert_kind_of Moodle2CC::Canvas::WebContent, resource
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_it_can_get_web_content_resource_from_file_resource_with_summary
|
73
|
+
mod = @backup.course.mods.find { |m| m.mod_type == "resource" && (!m.summary.nil? && m.summary.length != 0)}
|
74
|
+
mod.type = 'file'
|
75
|
+
resource = @cc_factory.get_resource_from_mod(mod)
|
76
|
+
assert_kind_of Moodle2CC::CC::WebContent, resource
|
77
|
+
|
78
|
+
resource = @canvas_factory.get_resource_from_mod(mod)
|
79
|
+
assert_kind_of Moodle2CC::Canvas::WebContent, resource
|
80
|
+
end
|
81
|
+
|
72
82
|
def test_it_can_get_web_link_resource
|
73
|
-
mod = @backup.course.mods.find { |m| m.mod_type == "resource" }
|
83
|
+
mod = @backup.course.mods.find { |m| m.mod_type == "resource" && (m.summary.nil? || m.summary.length == 0) }
|
74
84
|
mod.type = 'file'
|
75
85
|
resource = @cc_factory.get_resource_from_mod(mod)
|
76
86
|
assert_kind_of Moodle2CC::CC::WebLink, resource
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moodle2cc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,24 +11,24 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rubyzip
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.0.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
none: false
|
28
28
|
requirements:
|
29
|
-
- -
|
29
|
+
- - ~>
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
31
|
+
version: 1.0.0
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
33
|
name: happymapper
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|