« Module:Episode » : différence entre les versions
Aller à la navigation
Aller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 2 : | Ligne 2 : | ||
local p = {} | local p = {} | ||
local data = mw.loadData("Module:Episode/data") | local data = mw.loadData("Module:Episode/data") | ||
local TITLE_TEMPLATE = [[ | |||
* Article: %s | |||
* Title: %d | |||
]] | |||
-- Trim whitespace from args, and treat blank args as nil | |||
local function preprocessArg(s) | |||
if not s then | |||
return nil | |||
end | |||
s = s:match('^%s*(.-)%s*$') -- trim whitespace | |||
if s == '' then | |||
return nil | |||
else | |||
return s | |||
end | |||
end | |||
-- Retrieving full episode title | -- Retrieving full episode title | ||
function p.title(frame) | function p.title(frame) | ||
args[1] = | local args = lc.frame.args | ||
return | local article = preprocessArg(args[1]) | ||
local articleData = data[article] | |||
return string.format( | |||
TITLE_TEMPLATE, | |||
article, | |||
articleData.Article, | |||
articleData.Title | |||
) | |||
end | end | ||
return p | return p |
Version du 25 août 2022 à 11:56
Documentation module[créer]
Peut-être voulez-vous créer une page de documentation pour ce module Scribunto. Les éditeurs peuvent expérimenter dans les pages bac à sable (créer | miroir) et cas tests (créer) de ce module. Veuillez ajouter les catégories dans la sous-page /documentation. sous-pages de ce module. |
-- Used to extract the exact title of an episode
local p = {}
local data = mw.loadData("Module:Episode/data")
local TITLE_TEMPLATE = [[
* Article: %s
* Title: %d
]]
-- Trim whitespace from args, and treat blank args as nil
local function preprocessArg(s)
if not s then
return nil
end
s = s:match('^%s*(.-)%s*$') -- trim whitespace
if s == '' then
return nil
else
return s
end
end
-- Retrieving full episode title
function p.title(frame)
local args = lc.frame.args
local article = preprocessArg(args[1])
local articleData = data[article]
return string.format(
TITLE_TEMPLATE,
article,
articleData.Article,
articleData.Title
)
end
return p