Skip to content
This repository was archived by the owner on Aug 21, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions common_cartridge.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'common_cartridge/version'

Gem::Specification.new do |spec|
spec.name = "common_cartridge"
spec.version = "1.0.1"
spec.authors = ["Josh Simpson"]
spec.email = ["jsimpson@instructure.com"]
spec.name = 'common_cartridge'
spec.version = CommonCartridge::VERSION
spec.authors = ['Josh Simpson', 'Remy Obein']
spec.email = ['jsimpson@instructure.com', 'remy@cassia.tech']
spec.summary = %q{CommonCartridge}
spec.description = "Parse IMS Common Cartridge packages"
spec.homepage = "http://www.instructure.com/"
spec.license = "MIT"
spec.description = 'Parse IMS Common Cartridge packages'
spec.homepage = 'http://www.instructure.com/'
spec.license = 'MIT'

spec.files = Dir.glob("{lib,spec}/**/*")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "sax-machine", "~> 1.3.2"
spec.add_dependency "nokogiri", "~> 1.8.1"
spec.add_dependency "rubyzip", "~> 1.2.1"
spec.add_dependency 'sax-machine', '~> 1.3.2'
spec.add_dependency 'nokogiri', '~> 1.8.1'
spec.add_dependency 'rubyzip', '~> 1.2.1'

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3.0'
end
2 changes: 1 addition & 1 deletion lib/common_cartridge.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'sax-machine'
require 'sax_machine/sax_handler'

module CommonCartridge
def self.parse_from_zip(zipfile)
Expand Down Expand Up @@ -38,3 +37,4 @@ def initialize
require 'common_cartridge/elements/manifest'
require 'common_cartridge/package'
require 'common_cartridge/parsers/parser'
require 'common_cartridge/version'
39 changes: 28 additions & 11 deletions lib/common_cartridge/elements/lom.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
module CommonCartridge
module Elements
module Lom
class LanguageString
include SAXMachine

attribute :language
value :value
end

class Title
include SAXMachine

element :string, as: :value
element :string, value: :language, as: :language
# http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd
elements 'lomimscc:string', as: :strings, class: CommonCartridge::Elements::Lom::LanguageString

# backward compatibility
def value; strings.first.value; end
def language; strings.first.language; end

def values
strings.map do |str|
[str.language, str.value]
end.to_h
end

def to_s; string; end
end

class Description
include SAXMachine

element :string, as: :value
element :string, value: :language, as: :language
element 'lomimscc:string', as: :value
element 'lomimscc:string', value: :language, as: :language

def to_s; string; end
end

class Keyword
include SAXMachine

element :string, as: :value
element :string, value: :language, as: :language
element 'lomimscc:string', as: :value
element 'lomimscc:string', value: :language, as: :language

def to_s; string; end
end
Expand All @@ -37,22 +54,22 @@ class CopyrightAndOtherRestrictions
class Rights
include SAXMachine

element :description, class: CommonCartridge::Elements::Lom::Description
element 'lomimscc:description', as: :description, class: CommonCartridge::Elements::Lom::Description
element :copyrightAndOtherRestrictions, class: CommonCartridge::Elements::Lom::CopyrightAndOtherRestrictions
end

class General
include SAXMachine

element :title, class: CommonCartridge::Elements::Lom::Title
element :description, class: CommonCartridge::Elements::Lom::Description
elements :keyword, as: :keywords, class: CommonCartridge::Elements::Lom::Keyword
element 'lomimscc:title', as: :title, class: CommonCartridge::Elements::Lom::Title
element 'lomimscc:description', as: :description, class: CommonCartridge::Elements::Lom::Description
elements 'lomimscc:keyword', as: :keywords, class: CommonCartridge::Elements::Lom::Keyword
end

class Lom
include SAXMachine

element :general, class: CommonCartridge::Elements::Lom::General
element 'lomimscc:general', as: :general, class: CommonCartridge::Elements::Lom::General
element :rights, class: CommonCartridge::Elements::Lom::Rights
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/common_cartridge/elements/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class Manifest
element :metadata, class: CommonCartridge::Elements::Metadata
element :organizations, class: CommonCartridge::Elements::Organizations::RootOrganization, as: :root_organization
element :resources, class: CommonCartridge::Elements::Resources::RootResource, as: :root_resource
attribute :identifier, required: true
attribute :xmlns
attribute 'xmlns:lomimscc', as: :xmlns_lomimscc
attribute 'xmlns:lom', as: :xmlns_lom
attribute 'xmlns:xsi', as: :xmlns_xsi
attribute 'xsi:schemaLocation', as: :xsi_schema_location

def organizations
root_organization.organizations
Expand Down
2 changes: 1 addition & 1 deletion lib/common_cartridge/elements/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Metadata
element :schema
element :schemaversion

element :lom, class: CommonCartridge::Elements::Lom::Lom
element 'lomimscc:lom', as: :lom, class: CommonCartridge::Elements::Lom::Lom
end
end
end
2 changes: 0 additions & 2 deletions lib/common_cartridge/elements/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class RootItem
include SAXMachine

attribute :identifier
attribute :identifierref

elements :item, class: Item, as: :items

# todo: implement 'find_by' method here to quickly scan for particular items
Expand Down
4 changes: 3 additions & 1 deletion lib/common_cartridge/elements/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'common_cartridge/elements/resources/assignment'
require 'common_cartridge/elements/resources/assessment'
require 'common_cartridge/elements/resources/page'
require 'common_cartridge/elements/resources/basic_lti_link'

module CommonCartridge
module Elements
Expand All @@ -15,7 +16,8 @@ def self.type_mappings
WebLink.pattern => WebLink,
Assignment.pattern => Assignment,
Assessment.pattern => Assessment,
Page.pattern => Page
Page.pattern => Page,
BasicLtiLink::BasicLtiLink.pattern => BasicLtiLink::BasicLtiLink
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/common_cartridge/elements/resources/attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Attachment
class RootAttachment
include SAXMachine

elements :attachment, class: Attachment, as: :attachments
elements :'dt:attachment', class: Attachment, as: :attachments
end
end
end
Expand Down
66 changes: 66 additions & 0 deletions lib/common_cartridge/elements/resources/basic_lti_link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module CommonCartridge
module Elements
module Resources
module BasicLtiLink
class VendorContact
include SAXMachine

element 'lticp:email', as: :email
end

class Vendor
include SAXMachine

element 'lticp:code', as: :code
element 'lticp:name', as: :name
element 'lticp:description', as: :description
element 'lticp:url', as: :url
element 'lticp:contact', class: VendorContact, as: :contact
end

class ExtensionProperty
include SAXMachine

attribute :name
value :value
end

class Extension
include SAXMachine

attribute :platform
elements 'lticm:property', class: ExtensionProperty, as: :properties
end

class BasicLtiLink
attr_accessor :identifier

include SAXMachine

attribute :xmlns
attribute 'xmlns:blti', as: :xmlns_blti
attribute 'xmlns:lticm', as: :xmlns_lticm
attribute 'xmlns:lticp', as: :xmlns_lticp
attribute 'xmlns:xsi', as: :xmlns_xsi
attribute 'xsi:schemaLocation', as: :xsi_schema_location

element 'blti:title', as: :title
element 'blti:description', as: :description
element 'blti:secure_launch_url', as: :secure_launch_url
element 'blti:launch_url', as: :launch_url
element 'blti:vendor', class: Vendor, as: :vendor

elements 'blti:extensions', class: Extension, as: :extensions

def self.type
:basic_lti_link
end

def self.pattern
/imsbasiclti_xmlv1p/
end
end
end
end
end
end
8 changes: 4 additions & 4 deletions lib/common_cartridge/elements/resources/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Topic

include SAXMachine

element :title
element :text
element :text, value: :texttype, as: :text_type
element :attachments, class: Attachments::RootAttachment, as: :attachment_root
element 'dt:title', as: :title
element 'dt:text', as: :text
element 'dt:text', value: :texttype, as: :text_type
element 'dt:attachments', class: Attachments::RootAttachment, as: :attachment_root

def attachments
attachment_root.attachments
Expand Down
8 changes: 7 additions & 1 deletion lib/common_cartridge/parsers/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
module CommonCartridge
module Parsers
class Parser
class ManifestDocument
include SAXMachine

element :manifest, class: CommonCartridge::Elements::Manifest, required: true
end

def self.use_file(zipfile, path)
Zip::File.open(File.join(CommonCartridge.config.import_directory, zipfile)) do |file|
f = file.glob(path).first
Expand All @@ -25,7 +31,7 @@ def initialize(zipfile)

def parse
Parser.use_file(@zipfile, 'imsmanifest.xml') do |xml|
@package.manifest = CommonCartridge::Elements::Manifest.parse(xml)
@package.manifest = ManifestDocument.parse(xml).manifest
end

parse_content!
Expand Down
3 changes: 3 additions & 0 deletions lib/common_cartridge/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module CommonCartridge
VERSION = '2.0.0'.freeze
end
11 changes: 0 additions & 11 deletions lib/sax_machine/sax_handler.rb

This file was deleted.

4 changes: 4 additions & 0 deletions spec/elements/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module Elements
it "has resources" do
expect(@manifest.root_resource).to be_kind_of(CommonCartridge::Elements::Resources::RootResource)
end

it "has identifier" do
expect(@manifest.identifier).to eq('if33b9cbc13c56657b05bec722d30b84f')
end
end
end
end
29 changes: 29 additions & 0 deletions spec/elements/resources/basic_lti_link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

module CommonCartridge
module Elements
module Resources
describe BasicLtiLink do
before(:all) do
manifest = CommonCartridge.parse_from_zip('canvas_small_1.1.imscc').manifest
@resource = manifest.resources.detect { |r| r.identifier =~ /I_00015_R/ }
end

it 'is parsed correctly' do
expect(@resource.files.first.content).to be_kind_of(
CommonCartridge::Elements::Resources::BasicLtiLink::BasicLtiLink
)
end

it 'has a title' do
expect(@resource.files.first.content.title).to eq('Semester 1 Overview')
end

it 'has a secure_launch_url' do
expect(@resource.files.first.content.secure_launch_url).to eq('https://fakecollege.com/activity_lists/student-resources--122/activities/semester-1-overview--17?custom_course_id=275')
end
end
end
end
end

Binary file modified spec/files/canvas_small_1.1.imscc
Binary file not shown.