Module:Mooc/TypeHandler

TypeHandler

edit

This module stores information about classes responsible to handle a MOOC item type.

constructor (init)

edit

Parameters:

  • [Mooc/Data/Item.Type] type: MOOC item type this handler is resposible for
  • [String] parserPath: path to the parser class
  • [String] templatePath: path to the template

Note: Paths are threaten like in module loading.

Example:

    local lessonHandler = TypeHandler(lesson, "Module:Mooc/Data/Lesson", "Module:Mooc/Template/Lesson")

getParser

edit

Returns: parser class that gets loaded if not preloaded in Lua yet

getTemplate

edit

Returns: template class that gets loaded if not preloaded in Lua yet


local inheritance = require("Module:Inheritance");

local TypeHandler = inheritance.extend(inheritance.Class);

function TypeHandler:init(type, parserPath, templatePath)
  self.type = type;
  self.parserPath = parserPath;
  self.templatePath = templatePath;
end

function TypeHandler:getType()
  return self.type;
end

function TypeHandler:getParser()
  if self.parser == nil then
    self.parser = require(self.parserPath);
  end
  return self.parser;
end

function TypeHandler:getTemplate()
  if self.template == nil then
    self.template = require(self.templatePath);
  end
  return self.template;
end

function TypeHandler:handlesType(typeIdentifier)
  return self.type:isType(typeIdentifier);
end

return TypeHandler;