Modul:Portfolio
Aus Star Citizen Wiki
Weitere Optionen
Diese Dokumentation wird von Modul:Portfolio/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
| Function list |
|---|
| L 22 — smwToStr L 33 — methodtable.getInfoBox L 91 — methodtable.setSemanticProperties L 104 — methodtable.getSmwData L 133 — methodtable.setFrame L 141 — Portfolio.main L 151 — Portfolio.new |
require('strict')
--- Portfolio-Infobox für Comm-Link-Portfolios (Seiten unter Portfolios/).
--- Liest Erstelldatum und Quelle der zugehörigen Comm-Link-Seite per SMW und
--- rendert über Module:InfoboxLua. Aufrufer: Vorlage:Portfolio
--- ({{#invoke:Portfolio|main}}).
local Portfolio = {}
local metatable = {}
local methodtable = {}
metatable.__index = methodtable
-- Extensions
local common = require('Module:Common')
--- SMW liefert für mehrfach belegte Properties Tabellen; format() braucht Strings
---
--- @param value string|table|nil
--- @return string|nil
local function smwToStr(value)
if type(value) == 'table' then
return table.concat(value, ', ')
end
return value
end
--- Creates the infobox
---
--- @return string
function methodtable.getInfoBox(self)
local infobox = require('Module:InfoboxLua')
local smwData = self:getSmwData()
local title = string.format('Portfolio: %s', self.frameArgs['Name'])
-- Set Title of page
common.setDisplayTitle(self.currentFrame, title)
local information = {
{ label = 'ID', content = self.frameArgs['ID'] },
}
local erstelldatum = smwToStr(smwData['Erstelldatum'])
if erstelldatum ~= nil then
table.insert(information, { label = 'Veröffentlichung', content = erstelldatum })
end
local quellen = {
{
label = 'Wiki Comm-Link',
content = string.format('[[Comm-Link:%s]]', self.frameArgs['ID']),
},
{
label = 'Wiki API',
content = string.format('[https://api.star-citizen.wiki/rsi/comm-links/%s API]', self.frameArgs['ID']),
},
}
local quelle = smwToStr(smwData['Quelle'])
if quelle ~= nil then
table.insert(quellen, {
label = 'Robert Space Industries',
content = string.format('[%s RSI]', quelle),
})
end
return infobox.render({
-- Header-Titel ist ein Wikilink, damit das Portfolio-Ziel verlinkt bleibt
title = string.format('[[%s]] - Portfolio', self.frameArgs['Name']),
image = self.frameArgs['Bild'],
sections = {
{
label = 'Informationen',
columns = 2,
items = information,
},
{
label = 'Quellen',
items = quellen,
},
},
})
end
--- Add the Comm-Link ID as an attribute to the page
---
--- @return table SMW Result
function methodtable.setSemanticProperties(self)
local setObj = {
['Comm-Link'] = string.format('Comm-Link:%s', self.frameArgs['ID']),
}
return mw.smw.set(setObj)
end
--- Retrieve all attributes from the Comm-Link:ID page.
--- A missing Comm-Link no longer errors the whole box: the page is tracked
--- in a maintenance category and the affected rows drop out instead.
---
--- @return table
function methodtable.getSmwData(self)
-- Cache multiple calls
if self.smwData ~= nil then
return self.smwData
end
local data = mw.smw.ask({
'[[Comm-Link:' .. self.frameArgs['ID'] .. ']]',
'?#-=page',
'?Erstelldatum#-F[d.m.Y]=Erstelldatum',
'?Quelle#-',
'mainlabel=-',
})
if data == nil or data[1] == nil then
table.insert(self.categories, '[[Kategorie:Portfolio Artikel mit fehlendem Comm-Link]]')
self.smwData = {}
return self.smwData
end
self.smwData = data[1]
return self.smwData
end
--- Set the frame and load args
---
--- @param frame table
function methodtable.setFrame(self, frame)
self.currentFrame = frame
self.frameArgs = require('Module:Arguments').getArgs(frame)
end
--- Template entry
---
--- @return string
function Portfolio.main(frame)
local instance = Portfolio:new()
instance:setFrame(frame)
instance:setSemanticProperties()
return tostring(instance:getInfoBox()) .. table.concat(instance.categories, '') .. '[[Kategorie:Portfolio]]'
end
--- New Instance
--- Library entrance
function Portfolio.new(self)
local instance = {
smwData = nil,
categories = {},
}
setmetatable(instance, metatable)
return instance
end
return Portfolio
