Module:Mooc/Data/Item/doc

=Item= Item is a basic class in the MOOC. It servers as model holding data for a MOOC item and as parser. Therefore it does not only provide getters and setters promising to have certain data available for the template, but also methods to interprete lines from the MOOC index and fill itself with the content extracted. The item instance will be passed to the template which accesses the model to render the data the item instance contains.

TODO separate model and parser?

constructor (init)
Creates a new container filled with the fields of the header passed.

Parameters:
 * [ ] header: header of the item data will be hold for

getParams
Provides access to the parameters extracted from the index.

TODO add example of template accessing the item

Returns: table containing parameter values accessible via their name

load
Loads the item fields from the MOOC index lines left unparsed. Since the item was already created the header is not included in these lines and already assigned to the item. The default implementation extracts all parameters but ignores child items.

Parameters:
 * [ ] content: MOOC index lines representing the item

extractParams
Extracts all parameters from MOOC index lines for the current item ignoring children. This method is used once by the parser. Templates use  to get the table.

Parameters:
 * [ ] content: MOOC index lines representing the item

Returns: table containing parameter values accessible via their name

TYPE
Each model class has a field set to the item type the class represents. The field can be used to register a type handler for this class.

TODO add link to type handler registration page

Type
The item type class is responsible to link wiki page calls to parser and templating implementations. This is done using identifiers since Strings are the only possible script invocation arguments.

constructor (init)
Create a new type with the identifier specified.

Parameters:
 * [ ] identifier: identifier of the new item type

isType
Checks whether this type matches the identifier a user provided.

Parameters:
 * [ ] typeIdentifier: identifier of the type a user desires

Returns: true if this type matches the identifier or false otherwise

Header
The item header is a simple container holding data to identify an item within the MOOC.

constructor (init)
Creates a new item header.

Parameters:
 * [ ] name: item name
 * [ ] typeIdentifier: identifier determining the item type
 * [ ] path: item path within the MOOC

getLevel
Gets the item level within the MOOC depending on the number of leading "=".

Parameters:
 * [ ] itemHeader: item header line the level should be calculated for

Returns: item level starting with 1 or 0 if the passed line was no item header

parseHeader
Loads an instance of  from the item header line.

Parameters:
 * [ ] headerLine: item header line that should be loaded
 * [ ] parentPath: path of the item's parent

parseItem
Parses an item of the type the parser was registered for.

Parameters:
 * [ ] header: item header
 * [ ] load: determines whether  should be called or not. Only basic information is available if the item doesn't get loaded: name, type and path (URL)
 * [ ] typeHandlers: type handlers to parse additional items such as children if needed

Returns: parsed item that is fully loaded if specified

parseIndex
Gets called by the MOOC in order to parse all items associated to the item that will be rendered. The type of the targeted item is the type the parser was registered for.

Parameters:
 * [ ] index: extracted MOOC index including all associated items
 * [ ] typeHandlers: type handlers to parse additional items such as children if needed