Модуль:Common: различия между версиями
(Новая страница: «local common = {} -- common functions package for common usage through Teopedia Library pages -- Return TRUE if string is empty or not defined (null). local func...») |
мНет описания правки |
||
Строка 10: | Строка 10: | ||
-- ID example: 1-017 | -- ID example: 1-017 | ||
-- Call examples: {{#invoke: Common | page_id | volume=1 | page=17 }} | -- Call examples: {{#invoke: Common | page_id | volume=1 | page=17 }} | ||
-- {{#invoke: Common | page_id | volume=1 | page=17 | -- {{#invoke: Common | page_id | volume=1 | page=17 | ||
-- | volume_digits=2 | page_digits=4 | -- | volume_digits=2 | page_digits=4 | ||
-- | page_number_type=roman | -- | page_number_type=roman | ||
-- }} | -- }} | ||
-- By default volume has 1 digit, page has 3 digits and page number in arabic | -- By default volume has 1 digit, page has 3 digits and page number in arabic | ||
Строка 23: | Строка 23: | ||
if not isempty(frame.args['volume_digits']) then | if not isempty(frame.args['volume_digits']) then | ||
local digitFormat = '%.'.. frame.args['volume_digits'] ..'d' | local digitFormat = '%.'.. frame.args['volume_digits'] ..'d' | ||
vNum = string.format(digitFormat, frame.args[' | vNum = string.format(digitFormat, frame.args['volume']) | ||
end | end | ||
if not isempty(frame.args['page_digits']) then | if not isempty(frame.args['page_digits']) then | ||
local digitFormat = '%.'.. frame.args['page_digits'] ..'d' | local digitFormat = '%.'.. frame.args['page_digits'] ..'d' | ||
pNum = string.format(digitFormat, frame.args[' | pNum = string.format(digitFormat, frame.args['page']) | ||
end | end | ||
Версия от 03:37, 1 февраля 2024
Для документации этого модуля может быть создана страница Модуль:Common/doc
local common = {} -- common functions package for common usage through Teopedia Library pages
-- Return TRUE if string is empty or not defined (null).
local function isempty(s)
return s == nil or s == ''
end
-- Create unique sortable page ID in multy-volume book: V:PPP
-- Used in: Шаблон:Исходный текст ТД начинается
-- ID example: 1-017
-- Call examples: {{#invoke: Common | page_id | volume=1 | page=17 }}
-- {{#invoke: Common | page_id | volume=1 | page=17
-- | volume_digits=2 | page_digits=4
-- | page_number_type=roman
-- }}
-- By default volume has 1 digit, page has 3 digits and page number in arabic
-- style, but this could be changed.
function common.page_id( frame )
local vNum = frame.args['volume']
local pNum = string.format("%.3d", frame.args['page'])
-- Check if we should alter default values
if not isempty(frame.args['volume_digits']) then
local digitFormat = '%.'.. frame.args['volume_digits'] ..'d'
vNum = string.format(digitFormat, frame.args['volume'])
end
if not isempty(frame.args['page_digits']) then
local digitFormat = '%.'.. frame.args['page_digits'] ..'d'
pNum = string.format(digitFormat, frame.args['page'])
end
return vNum .. ':' .. pNum
end
return common