« Module:Person/class » : différence entre les versions
De Semantic MediaWiki - Sandbox
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 76 : | Ligne 76 : | ||
function person:getPersonVitae() | function person:getPersonVitae() | ||
local cbData, query = comicBooks.retrieveClassData( comicBooks, '[[Has comic book writer::' .. mw.title.getCurrentTitle().text .. ']]' ) | local cbData, query = comicBooks.retrieveClassData( comicBooks, '[[Has comic book writer::' .. mw.title.getCurrentTitle().text .. ']]' ) | ||
-- local pt = require( 'Module:TableTools' ).printTable | |||
cbData = cbData or {} | cbData = cbData or {} | ||
return '\n=== Works ===\n' .. self:extractWorks( cbData ) .. '\n' | return '\n=== Works ===\n' .. self:extractWorks( cbData ) .. '\n' | ||
.. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n' | .. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n' | ||
-- .. '<pre>' .. pt( cbData ) .. '\n\n' .. pt( query ) .. '</pre>' | |||
end | end | ||
Version du 26 décembre 2016 à 11:35
This module holds a lua class representing a person. It uses Module:SSC base for its functionality and gets its configuration from Module:Person/config.
Usage
local person = require( 'Module:Person/class' ):new()
-- for example, this call would be placed inside the main function called on the template:
return person:renderPage()
For available public methods see Module:SSC base.
local comicBooks = require( 'Module:Comic books/class' )
local config = mw.loadData( 'Module:Person/config' )
local class = require( 'Module:SSC base' )
local person = class:new( config )
function person:alterDataAfterStorage( data )
local data = data
if not data.profession then
data.profession = 'unknown'
end
if not data.firstname and not data.lastname then
data.firstname = 'John'
data.lastname = 'Doe'
data.name = data.firstname .. ' ' .. data.lastname
else
data.name = data.firstname or data.lastname
end
if data['date of birth'] and mw.ustring.find( data['date of birth'], '/', 1, true ) then
local date = mw.text.split( data['date of birth'], '/', true )
data['date of birth'] = date[2] .. '.' .. date[1] .. '.' .. date[3]
end
return data
end
function person:extractCollaborations( dataArray )
local collaborationData = {}
for _, row in pairs( dataArray ) do
if row.artist then
for _, artist in pairs( row.artist ) do
if not collaborationData[artist] then
collaborationData[artist] = {}
end
table.insert( collaborationData[artist], row._mainlabel )
end
end
end
local collaborations = {}
for artist, works in pairs( collaborationData ) do
table.insert(
collaborations,
comicBooks:getPrintout( 'artist', artist ) .. ' (on [[' .. mw.text.listToText( works, ']], [[', ']] and [[' ) .. ']])'
)
end
table.sort( collaborations )
if #collaborations == 0 then
return 'none'
else
return '\n* ' .. table.concat( collaborations, '\n* ' ) .. '\n'
end
end
function person:extractWorks( dataArray )
local works = {}
for _, row in pairs( dataArray ) do
local work = '[[' .. row._mainlabel .. ']]'
if row.publisher then
work = work
.. ' (for ' .. comicBooks:getPrintout( 'publisher', row.publisher )
.. ( row['publication year'] and (' in ' .. row['publication year']) or '' ) .. ')'
end
table.insert( works, work )
end
table.sort( works )
if #works == 0 then
return 'none'
else
return '\n* ' .. table.concat( works, '\n* ' ) .. '\n'
end
end
function person:getPersonVitae()
local cbData, query = comicBooks.retrieveClassData( comicBooks, '[[Has comic book writer::' .. mw.title.getCurrentTitle().text .. ']]' )
-- local pt = require( 'Module:TableTools' ).printTable
cbData = cbData or {}
return '\n=== Works ===\n' .. self:extractWorks( cbData ) .. '\n'
.. '=== Collaborations ===\n' .. self:extractCollaborations( cbData ) .. '\n'
-- .. '<pre>' .. pt( cbData ) .. '\n\n' .. pt( query ) .. '</pre>'
end
function person:renderPage()
return class.renderPage( self )
.. self:getPersonVitae()
end
return person