Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Source
-- @brief
-- Generic wrapper for source templates.
--
-- @author
-- ]
local _module = {}
----------------------------------------
local Error = require( "Module:Error" )
-- @brief
-- Write the citation template for given source.
--
-- @param
-- frame The current frame object
--
-- @return
-- Preprocessed wikitext
function _module.print( frame )
local source = mw.text.trim( frame.args or "" )
if source == "" then
error( "Missing the first argument – name of the source module" )
end
local sourceTitle = frame:getTitle() .. "/" .. source
local sourceObjectExist, sourceObject = pcall( require, sourceTitle )
if not sourceObjectExist then
error( "Missing \"" .. sourceTitle .. "\" module" )
end
if sourceObject.editions and not sourceObject.editions.switch then
error( "\"switch\" field is missing in " .. sourceTitle .. ".editions" )
end
local output
local templateArgs = frame:getParent().args
local errorData = { template = source }
local args = {}
local errors = {}
local data = {}
local argumentDefaults = {
= {
description = "datum, kdy byl naposledy odkazovaný dokument skutečně viděn"
},
= {
description = "díl"
},
= {
description = "heslo",
fillIn = "kapitola"
},
= {
description = "kapitola"
},
= {
description = "rok vydání"
},
= {
description = "citovaná strana či strany"
},
= {
description = "odkaz na online verzi"
},
= {
description = "vydání"
}
}
for param, value in pairs( templateArgs ) do
value = mw.text.trim( value )
if value ~= "" then
args = value
end
end
for param, value in pairs( sourceObject.arguments or {} ) do
if value.required and not args then
table.insert( errors, { missingValue = { paramName = param, paramDesc = value.description or argumentDefaults.description } } )
end
end
if sourceObject.editions and args and not sourceObject.editions] then
table.insert( errors, { unknownValue = { paramName = sourceObject.editions.switch, paramDesc = sourceObject.arguments.description or argumentDefaults.description } } )
end
if sourceObject.fill then
sourceObject.data = {}
sourceObject.errors = {}
sourceObject.fill( args )
data = sourceObject.data
errors = sourceObject.errors
end
if next( errors ) then
local errorTexts = {}
local method = mw.title.getCurrentTitle().namespace == 0 and "getText" or "getMessage"
for index, err in ipairs( errors ) do
for key, value in pairs( err ) do
errorData = value
end
table.insert( errorTexts, Error( errorData ) )
end
output = table.concat( errorTexts, "<br />" )
output = frame:preprocess( output )
else
local citeArgs = {
= source
}
if not sourceObject.fill then
if sourceObject.common then
for param, value in pairs( sourceObject.common ) do
data = ( type( value ) == "function" and value( args ) or value )
end
end
if sourceObject.editions then
for param, value in pairs( sourceObject.editions] ) do
data = ( type( value ) == "function" and value( args ) or value )
end
end
if sourceObject.arguments then
for param, value in pairs( sourceObject.arguments ) do
data and argumentDefaults.fillIn or param )] = ( value.fill and value.fill( args ) or argumentDefaults and argumentDefaults.fill and argumentDefaults.fill( args ) or args )
end
end
end
for param, value in pairs( data ) do
citeArgs = value
end
output = frame:expandTemplate({
title = "Citace " .. sourceObject.cite,
args = citeArgs
})
end
return output
end
----------------------------------------
return _module