Modulo:Mooc/Data/Item/man

Da Wikiversità, l'apprendimento libero.

Questa è la pagina di documentazione per Modulo:Mooc/Data/Item

Item[modifica]

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)[modifica]

Creates a new container filled with the fields of the header passed.

Parameters:

  • [Mooc/Data/Item.Header] header: header of the item data will be hold for

getParams[modifica]

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[modifica]

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:

  • [Table:String] content: MOOC index lines representing the item

extractParams[modifica]

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

Parameters:

  • [Table:String->String] content: MOOC index lines representing the item

Returns: table containing parameter values accessible via their name

TYPE[modifica]

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[modifica]

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)[modifica]

Create a new type with the identifier specified.

Parameters:

  • [String] identifier: identifier of the new item type

isType[modifica]

Checks whether this type matches the identifier a user provided.

Parameters:

  • [String] typeIdentifier: identifier of the type a user desires

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

Header[modifica]

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

constructor (init)[modifica]

Creates a new item header.

Parameters:

  • [String] name: item name
  • [String] typeIdentifier: identifier determining the item type
  • [String] path: item path within the MOOC

getLevel[modifica]

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

Parameters:

  • [String] 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[modifica]

Loads an instance of Mooc/Data/Item.Header from the item header line.

Parameters:

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

parseItem[modifica]

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

Parameters:

  • [Mooc/Data/Item.Header] header: item header
  • [Boolean] load: determines whether load should be called or not. Only basic information is available if the item doesn't get loaded: name, type and path (URL)
  • [Table:String->Mooc/TypeHandler] typeHandlers: type handlers to parse additional items such as children if needed

Returns: parsed item that is fully loaded if specified

parseIndex[modifica]

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:

  • [Table:String->Table] index: extracted MOOC index including all associated items
  • [Table:String->Mooc/TypeHandler] typeHandlers: type handlers to parse additional items such as children if needed