« Module:Person/class » : différence entre les versions
De Semantic MediaWiki - Sandbox
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
local config = mw.loadData( 'Module:Person/config' ) | local config = mw.loadData( 'Module:Person/config' ) | ||
local class = require( 'Module:SSC base' ) | local class = require( 'Module:SSC base' ) | ||
local classComicBook = require( 'Module:Comic books/class' ) | |||
local person = class:new( config ) | local person = class:new( config ) | ||
Ligne 23 : | Ligne 24 : | ||
return data | 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, | |||
classComicBook:getPrintout( 'artist', artist ) .. '(on [[' .. mw.test.listToText( works, ']], [[', ']] and [[' ) .. ']])' | |||
) | |||
end | |||
table.sort( collaborations ) | |||
if #collaborations == 0 then | |||
return 'none' | |||
else | |||
return mw.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 [[' .. classComicBook: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 mw.table.concat( works, '\n* ' ) .. '\n' | |||
end | |||
end | |||
function person:getPersonVitae() | |||
local cbData = classComicBook:retrieveClassData() | |||
return '== Works ==\n' .. self:extractWorks( cbData ) | |||
.. '== Collaborations ==\n' .. self:extractCollaborations( cbData ) | |||
end | |||
function person:renderPage() | |||
return class.renderPage( self ) | |||
.. self:getPersonVitae() | |||
end | end | ||
return person | return person |
Version du 25 décembre 2016 à 16:17
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 config = mw.loadData( 'Module:Person/config' )
local class = require( 'Module:SSC base' )
local classComicBook = require( 'Module:Comic books/class' )
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,
classComicBook:getPrintout( 'artist', artist ) .. '(on [[' .. mw.test.listToText( works, ']], [[', ']] and [[' ) .. ']])'
)
end
table.sort( collaborations )
if #collaborations == 0 then
return 'none'
else
return mw.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 [[' .. classComicBook: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 mw.table.concat( works, '\n* ' ) .. '\n'
end
end
function person:getPersonVitae()
local cbData = classComicBook:retrieveClassData()
return '== Works ==\n' .. self:extractWorks( cbData )
.. '== Collaborations ==\n' .. self:extractCollaborations( cbData )
end
function person:renderPage()
return class.renderPage( self )
.. self:getPersonVitae()
end
return person