commoncartridge

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

README

Common Cartridge

Package for parsing IMSCC-compliant files. A CommonCartridge is a file used to export and import data from learning management systems such as Moodle, Canvas, Brightspace, Sakai, etc. In their own words:

Common Cartridge (CC) is a set of open standards developed by the IMS member community that enable interoperability between content and systems. Common Cartridge basically solves two problems. The first is to provide a standard way to represent digital course materials for use in online learning systems so that such content can be developed in one format and used across a wide variety of learning systems. The second is to enable new publishing models for online course materials and digital books that are modular, web-distributed, interactive, and customizable.

This package allows you to inspect and access specific parts of the cartridge, either through a command-line interface provided, or through a web interface accessible at viewer.commonsyllabi.org.

Installation

go get github.com/commonsyllabi/commoncartridge

Usage

CLI

You can use the command-line interface by passing it a .zip or .imscc file with a imsmanifest.xml, for instance, to access the metadata fields of the test file located in the test_files folder:

cosyl -m test_01.imscc

To list all commands:

cosyl --help
Package

You can use this package directly in your Go app by importing it in this way:

package main

import "github.com/commonsyllabi/commoncartridge"

func main(){
    cc, err := commoncartridge.Load("test_01.imscc")
    if err != nil {
        log.Fatal(err)
    }

    // prints the JSON representation of the cartridge
    obj, err := cc.MarshalJSON()
		if err != nil {
			log.Fatal(err)
		}

	fmt.Print(string(obj))
}

Alternatives

Credits

This work has been funded by the Prototype Fund and the Bundesministerium für Bildung und Forschung, and has been developed by Pierre Depaz, Tobias Schmidt and Pat Shiu.

Documentation

Overview

CommonCartridge allows you to manipulate IMSCC-compliant Common Cartridges through its manifest, resources and associated files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cartridge

type Cartridge interface {
	// MarshalJSON returns a serialized JSON representation
	MarshalJSON() ([]byte, error)

	//-- ParseManifest finds the imsmanifest.xml in the ZipReader and marshals it into a struct
	Manifest() (types.Manifest, error)

	// Title returns the title of the loaded cartridge
	Title() string

	// Metadata returns the metadata fields of the cartridge in a structured fashion
	Metadata() (string, error)

	// Items returns a slice of structs which include the Item, the Resources and the children Items it might have
	Items() ([]FullItem, error)

	// Resources returns a slice of structs which include the resource and, if found, the item in which the resource appears.
	Resources() ([]FullResource, error)
	Weblinks() ([]types.WebLink, error)
	Assignments() ([]types.Assignment, error)
	LTIs() ([]types.CartridgeBasicltiLink, error)
	QTIs() ([]types.Questestinterop, error)
	Topics() ([]types.Topic, error)

	// Find takes an identifier and returns the corresponding resource.
	Find(string) (interface{}, error)

	// FindFile takes an identifier and returns the fs.File that the corresponding node refers to.
	FindFile(string) (fs.File, error)
}

type FullItem

type FullItem struct {
	Resources []types.Resource
	Item      types.Item
	Children  []FullItem
}

FullItem is a union of an Item and all Resources that refer to it, along with possible children.

type FullResource

type FullResource struct {
	Resource interface{}
	Item     types.Item
}

FullResource is a union of a Resource and the Item that refers to it

type IMSCC

type IMSCC struct {
	Reader zip.Reader
	Path   string
	// contains filtered or unexported fields
}

IMSCC loads the IMSCC-specific cartridge into a zip.Reader from the given Path. It also stores the manifest for convenient access.

func Load

func Load(path string) (IMSCC, error)

Load returns a cartridge created from a given path, into a zip.Reader, and parses its `imsmanifest.xml` into a types.Manifest

func (IMSCC) Assignments

func (cc IMSCC) Assignments() ([]types.Assignment, error)

Assignments returns a slice of all resources of type assignment_xmlv1p\d, using a regular expression to account for different versions of the IMSCC standard. A necessary check of the actual XMLName is made for avoiding other files in the folder that are returned by the findResourcesByType() (e.g. `assignment.xml` also has `assignment_meta.html`)

func (IMSCC) Find

func (cc IMSCC) Find(id string) (interface{}, error)

Find takes an id, finds the resource associated with it, tries to marshall it into the appropriate type, or returns the resource itself if it's a webcontent or associated-resource.

func (IMSCC) FindFile

func (cc IMSCC) FindFile(id string) (fs.File, error)

FindFile takes an ID and returns the corresponding file as a `fs.File`, as specified on the `href` attribute of the first child `<file>` node.

func (*IMSCC) FindItem

func (cc *IMSCC) FindItem(id string) (types.Item, error)

FindItem loops over all Items in the manifest, and returns that the item that the argument ID points to, or returns `nil`.

func (IMSCC) Items

func (cc IMSCC) Items() ([]FullItem, error)

Items returns all items with their associated resources. It goes through each item at the top level and recursively looks for FullItems at the level n-1.

func (IMSCC) LTIs

func (cc IMSCC) LTIs() ([]types.CartridgeBasicltiLink, error)

LTIs returns a slice of all resources of type imsbasiclti_xmlv1p\d, using a regular expression to account for different versions of the IMSCC standard.

func (IMSCC) Manifest

func (cc IMSCC) Manifest() (types.Manifest, error)

func (IMSCC) MarshalJSON

func (cc IMSCC) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON-encoded string representation of the Manifest

func (IMSCC) Metadata

func (cc IMSCC) Metadata() (string, error)

Metadata returns a user-friendly, stringified, JSON-encoded version of the Metadata field.

func (IMSCC) QTIs

func (cc IMSCC) QTIs() ([]types.Questestinterop, error)

QTIs returns a slice of all resources of type imsqti_xmlv1p\d, using a regular expression to account for different versions of the IMSCC standard.

func (IMSCC) Resources

func (cc IMSCC) Resources() ([]FullResource, error)

Resources returns a slice of all FullResources, each containing a resource andeither the item it can belong to, or `nil`.

func (IMSCC) Title

func (cc IMSCC) Title() string

Title returns the name of the cartridge that is stored in the `<metadata>` node.

func (IMSCC) Topics

func (cc IMSCC) Topics() ([]types.Topic, error)

Topics returns a slice of all resources of type imsdt_xmlv1p\d, using a regular expression to account for different versions of the IMSCC standard.

func (cc IMSCC) Weblinks() ([]types.WebLink, error)

Weblnks returns a slice of all resources of type imswl_xmlv1p\d, using a regular expression to account for different versions of the IMSCC standard.

type Metadata

type Metadata struct {
	Title                string
	Schema               string
	SchemaVersion        string
	Language             string
	Description          string
	Keyword              string
	Date                 string
	Copyright            string
	CopyrightDescription string
}

Metadata is a user-friendly representation of the `<metadata>` node of the `imsmanifest.xml`

Directories

Path Synopsis
cmd
the types package consists of the autogenerated structs from the IMSCC template files, and of possible member functions for the associated structs (e.g.
the types package consists of the autogenerated structs from the IMSCC template files, and of possible member functions for the associated structs (e.g.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL