class CanvasCc::CanvasCC::ImsManifestGenerator

Constants

ALL_MODULES_IDENTIFIER
CANVAS_EXPORT_PATH
LOMIMSCC
MANIFEST_FILE_NAME
SCHEMA
SCHEMA_VERSION
SETTINGS_POSTFIX
SYLLABUS_POSTFIX
TYPE_LAR

Public Class Methods

new(work_dir, course) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 14
def initialize(work_dir, course)
  @work_dir = work_dir
  @course = course
end

Public Instance Methods

write() click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 19
def write
  xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    manifest(xml) do |xml|
      metadata(xml)
      organizations(xml)
      resources(xml, @course.all_resources)
    end
  end.to_xml
  File.open(File.join(@work_dir, MANIFEST_FILE_NAME), 'w') { |f| f.write(xml) }
end

Private Instance Methods

course_setting_resource(xml) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 112
def course_setting_resource(xml)
  course_setting_dir = CanvasCc::CanvasCC::CartridgeCreator::COURSE_SETTINGS_DIR
  export_file = File.join(course_setting_dir, CanvasCc::CanvasCC::CanvasExportWriter::CANVAS_EXPORT_FILE)
  course_setting_file = File.join(course_setting_dir, CanvasCc::CanvasCC::CourseSettingWriter::COURSE_SETTINGS_FILE)
  module_meta_file = File.join(course_setting_dir, CanvasCc::CanvasCC::ModuleMetaWriter::MODULE_META_FILE)
  grading_standards_file = File.join(course_setting_dir, CanvasCc::CanvasCC::GradingStandardWriter::GRADING_STANDARD_FILE)
  learning_outcomes_file = File.join(course_setting_dir, CanvasCc::CanvasCC::OutcomeWriter::LEARNING_OUTCOMES_FILE)
  xml.resource('identifier' => @course.identifier + SETTINGS_POSTFIX, 'type' => TYPE_LAR, 'href' => export_file) { |xml|
    xml.file('href' => course_setting_file)
    xml.file('href' => module_meta_file) if @course.canvas_modules.count > 0
    xml.file('href' => grading_standards_file)
    xml.file('href' => learning_outcomes_file) if @course.outcomes.count > 0
  }
end
course_syllabus_resource(xml) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 127
def course_syllabus_resource(xml)
  course_settings_dir = CanvasCc::CanvasCC::CartridgeCreator::COURSE_SETTINGS_DIR
  syllabus_file = File.join(course_settings_dir, CanvasCc::CanvasCC::CourseSyllabusWriter::COURSE_SYLLABUS_FILE)
  xml.resource('identifier' => @course.identifier + SYLLABUS_POSTFIX,
               'type' => TYPE_LAR,
               'href' => syllabus_file) do |xml|
    xml.file('href' => syllabus_file)
  end
end
manifest(xml) { |xml| ... } click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 32
def manifest(xml)
  xml.manifest(
      "identifier" => @course.identifier,
      "xmlns" => "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1",
      "xmlns:lom" => "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource",
      "xmlns:lomimscc" => "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest",
      "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
      "xsi:schemaLocation" => "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd"
  ) {
    yield xml
  }
end
metadata(xml) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 45
def metadata(xml)
  xml.metadata {
    xml.schema SCHEMA
    xml.schemaversion SCHEMA_VERSION
    ns = LOMIMSCC
    xml[ns].lom {
      xml[ns].general {
        xml[ns].title {
          xml[ns].string @course.title
        }
      }
      rights(xml)
    }
  }
end
organizations(xml) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 77
def organizations(xml)
  canvas_modules = @course.canvas_modules
  xml.organizations { |xml|
    if canvas_modules.count > 0
      xml.organization('identifier' => 'org_1', 'structure' => 'rooted-hierarchy') { |xml|
        xml.item('identifier' => ALL_MODULES_IDENTIFIER) do |xml|
          canvas_modules.each do |mod|
            xml.item('identifier' => mod.identifier) { |xml|
              xml.title mod.title
              mod.module_items.each do |module_item|
                xml.item('identifier' => module_item.identifier, 'identifierref' => module_item.identifierref ) { |xml|
                  xml.title(module_item.title)
                }
              end
            }
          end
        end
      }
    end
  }
end
resources(xml, resources) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 99
def resources(xml, resources)
  xml.resources { |xml|
    course_setting_resource(xml)
    course_syllabus_resource(xml)
    resources.each do |resource|
      xml.resource(resource.attributes) do |xml|
        resource.files.each { |file| xml.file(href: file) }
        resource.dependencies.each { |dependency| xml.dependency(identifierref: dependency) }
      end
    end
  }
end
rights(xml) click to toggle source
# File lib/canvas_cc/canvas_cc/ims_manifest_generator.rb, line 61
def rights(xml)
  ns = LOMIMSCC
  has_copyright = @course.copyright && !@course.copyright.empty?
  xml[ns].rights {
    xml[ns].copyrightAndOtherRestrictions {
      xml[ns].value (has_copyright || @course.files.any? { |f| f.usage_rights } ? 'yes' : 'no')
    }
    if has_copyright
      xml[ns].description {
        xml[ns].string @course.copyright
      }
    end
  }
end