มอดูล:Demography
หน้าตา
นี่เป็นมอดูลที่ถูกป้องกันถาวรเนื่องจากมีความเสี่ยงสูง กรุณาอภิปรายการเปลี่ยนแปลงใด ๆ ทางหน้าคุย คุณอาจส่งคำขอแก้ไขไปยังผู้ดูแลระบบเพื่อให้แก้ไขได้หากเป็นการแก้ไขที่ไม่มีการคัดค้านหรือมีความเห็นพ้องสนับสนุน คุณยังสามารถขอให้เลิกป้องกันหน้าได้ |
คู่มือการใช้งานมอดูล[สร้าง]
คุณอาจจะต้องการสร้างคู่มือการใช้งานของมอดูลนี้ ผู้เขียนสามารถทำการทดลองได้ที่กระบะทราย (สร้าง | คัดลอก) และชุดทดสอบ (สร้าง) ของมอดูลนี้ โปรดเพิ่มหมวดหมู่ไปที่หน้าย่อย /doc หน้าย่อยของมอดูลนี้ |
-- This module implements {{demography}}.
local getArgs = require('Module:Arguments').getArgs
local htmlBuilder = require('Module:HtmlBuilder')
local yesno = require('Module:Yesno')
local p = {}
-- Often-used functions.
local floor = math.floor
----------------------------------------------------------------------------
-- Helper functions
----------------------------------------------------------------------------
function p.isInteger(v)
if type(v) == 'number' and floor(v) == v then
return true
else
return false
end
end
function p.getArgNums(args)
local isInteger = p.isInteger
local nums = {}
for k, v in pairs(args) do
if isInteger(k) then
nums[#nums + 1] = k
end
end
table.sort(nums)
return nums
end
----------------------------------------------------------------------------
-- Main functions
----------------------------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local years = p.getArgNums(args)
local isEmbedded = yesno(args.embed)
local border = not isEmbedded and '1px solid #999'
local padding = not isEmbedded and '4px'
local dateRows = p.renderDateRows(args, years, border, padding)
local dateRowLength = #years + 1
local root
if isEmbedded then
root = htmlBuilder.create()
else
root = htmlBuilder.create('table')
root
.css('margin-left', 'auto')
.css('margin-right', 'auto')
.css('border', border)
.css('border-collapse', 'collapse')
.css('background-color', '#f3fff3')
if not args.noheader then
local currentTitle = mw.title.getCurrentTitle()
local source = args.source
root.tag('caption')
.css('margin-bottom', '0.5em')
.css('font-size', '1.1em')
.css('font-weight', 'bold')
.wikitext(
(args.caption or 'ประวัติประชากรของ' .. currentTitle.prefixedText)
.. (source and ' <br /><small>(แหล่งข้อมูล: ' .. source .. ')</small>' or '')
)
end
end
root.wikitext(dateRows)
local noDoubleYear = args.sansdoublescomptes or args.withoutdoublecount
if noDoubleYear then
local annualSurvey = args['enquêteannuelle'] or args.annualsurvey
root.tag('tr')
.tag('td')
.attr('colspan', dateRowLength)
.css('border', border)
.css('padding', padding)
.css('text-align', 'center')
.tag('small')
.wikitext(
'ตั้งแต่ปี ' .. noDoubleYear .. ': ไม่มีการนับเกิน — นับผู้ที่อยู่ในกลุ่มสังคมหลากหลาย (เช่นนักเรียนหรือทหาร) เพียงแค่ครั้งเดียว'
.. (
annualSurvey
and ' <br />' .. annualSurvey .. ': ประชากรชั่วคราว (สำรวจรายปี)'
or ''
)
)
end
return tostring(root)
end
function p.renderDateRows(args, years, border, padding)
local root = htmlBuilder.create()
local hrow = root.tag('tr')
hrow
.css('background', '#ddffdd')
.tag('th')
.attr('scope', 'row')
.css('border', border)
.css('padding', padding)
.wikitext('ปี')
for i, year in ipairs(years) do
if year < 0 then
year = '−' .. tostring(year * -1)
else
year = tostring(year)
end
hrow.tag('th')
.css('border', border)
.css('padding', padding)
.wikitext(year)
end
local drow = root.tag('tr')
drow
.tag('th')
.attr('scope', 'row')
.css('border', border)
.css('padding', padding)
.wikitext('ประชากร')
for i, year in ipairs(years) do
drow.tag('td')
.css('border', border)
.css('padding', padding)
.css('text-align', 'center')
.wikitext(args[year])
end
return tostring(root)
end
return p