Перейти к содержанию

Модуль:Common: различия между версиями

м
нет описания правки
мНет описания правки
мНет описания правки
Строка 1: Строка 1:
local common = {} -- common functions package for common usage through Teopedia Library pages
local common = {} -- common functions package for common usage through Teopedia Library pages
local roman = require('Module:Roman') -- To deal with Roman numbers


-- Return TRUE if string is empty or not defined (null).
-- Return TRUE if string is empty or not defined (null).
Строка 18: Строка 19:
function common.page_id( frame )
function common.page_id( frame )
local vNum = frame.args['volume']
local vNum = frame.args['volume']
local pNum = string.format("%.3d", frame.args['page'])
local nFormat = '%.3d'
 
local pNum = string.format(nFormat, frame.args['page'])
-- Check if we should alter default values
-- Check if we should alter default values
if not isempty(frame.args['volume_digits']) then
if not isempty(frame.args['volume_digits']) then
local digitFormat = '%.'.. frame.args['volume_digits'] ..'d'
nFormat = '%.'.. frame.args['volume_digits'] ..'d'
vNum = string.format(digitFormat, frame.args['volume'])
vNum = string.format(nFormat, 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'
nFormat = '%.'.. frame.args['page_digits'] ..'d'
pNum = string.format(digitFormat, frame.args['page'])
pNum = string.format(nFormat, frame.args['page'])
end
-- Check if we deal with Roman number
if frame.args['page_number_type'] == 'roman' then
-- 1. Fill with zeros all places for arabic digits for correct sorting.
pNum = '000'
if not isempty(frame.args['page_digits']) then
nFormat = '%.'.. frame.args['page_digits'] ..'d'
pNum = string.format(nFormat, 0)
end
-- 2. Convert number from Roman to Arabic
local pArabic = roman.toArabic(value)
-- 3. Add zeros to this number
local nLenght = 3
if not isempty(frame.args['page_digits']) then
nLenght = frame.args['page_digits']
end
nFormat = '%.'.. nLenght ..'d'
pArabic = string.format(nFormat, pArabic)
-- 4. Add original Roman number after Arabic
pNum = pNum .. pArabic ..'('.. frame.args['page_digits'] ..')'
end
end