Module:Potus work table/sandbox
Appearance
![]() | This is the module sandbox page for Module:Potus work table (diff). |
![]() | This module depends on the following other modules: |
Implements {{potus work table}}.
--[=[
Implements [[Template:Potus work table]]
]=]
require('strict')
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local TableTools = require('Module:TableTools')
local presidents = {
[1] = {'George Washington', 'Washington, George'},
[2] = {'John Adams (1735-1826)', 'Adams, John', 'John Adams'},
[3] = {'Thomas Jefferson', 'Jefferson, Thomas'},
[4] = {'James Madison', 'Madison, James'},
[5] = {'James Monroe', 'Monroe, James'},
[6] = {'John Quincy Adams', 'Adams, John Quincy'},
[7] = {'Andrew Jackson', 'Jackson, Andrew'},
[8] = {'Martin Van Buren', 'Buren, Martin Van'},
[9] = {'William Henry Harrison', 'Harrison, William Henry'},
[10] = {'John Tyler', 'Tyler, John'},
[11] = {'James K. Polk', 'Polk, James Knox'},
[12] = {'Zachary Taylor', 'Taylor, Zachary'},
[13] = {'Millard Fillmore', 'Fillmore, Millard'},
[14] = {'Franklin Pierce', 'Pierce, Franklin'},
[15] = {'James Buchanan', 'Buchanan, James'},
[16] = {'Abraham Lincoln', 'Lincoln, Abraham'},
[17] = {'Andrew Johnson', 'Johnson, Andrew'},
[18] = {'Ulysses S. Grant', 'Grant, Ulysses S.'},
[19] = {'Rutherford B. Hayes', 'Hayes, Rutherford B.'},
[20] = {'James Abram Garfield', 'Garfield, James Abram'},
[21] = {'Chester Alan Arthur', 'Arthur, Chester Alan'},
[22] = {'Grover Cleveland', 'Cleveland, Grover'},
[23] = {'Benjamin Harrison (1833-1901)', 'Harrison, Benjamin', 'Benjamin Harrison'},
[24] = {'Grover Cleveland', 'Cleveland, Grover'},
[25] = {'William McKinley', 'McKinley, William'},
[26] = {'Theodore Roosevelt', 'Roosevelt, Theodore'},
[27] = {'William Howard Taft', 'Taft, William Howard'},
[28] = {'Woodrow Wilson', 'Wilson, Woodrow'},
[29] = {'Warren G. Harding', 'Harding, Warren G.'},
[30] = {'Calvin Coolidge', 'Coolidge, Calvin'},
[31] = {'Herbert Hoover', 'Hoover, Herbert'},
[32] = {'Franklin Delano Roosevelt', 'Roosevelt, Franklin Delano'},
[33] = {'Harry S. Truman', 'Truman, Harry S.'},
[34] = {'Dwight D. Eisenhower', 'Eisenhower, Dwight D.'},
[35] = {'John F. Kennedy', 'Kennedy, John F.'},
[36] = {'Lyndon B. Johnson', 'Johnson, Lyndon B.'},
[37] = {'Richard Nixon', 'Nixon, Richard'},
[38] = {'Gerald Ford', 'Ford, Gerald'},
[39] = {'Jimmy Carter', 'Carter, Jimmy'},
[40] = {'Ronald Reagan', 'Reagan, Ronald'},
[41] = {'George Herbert Walker Bush', 'Bush, George Herbert Walker'},
[42] = {'William Jefferson Clinton', 'Clinton, William Jefferson'},
[43] = {'George Walker Bush', 'Bush, George Walker'},
[44] = {'Barack Obama', 'Obama, Barack Hussein'},
[45] = {'Donald John Trump', 'Trump, Donald John'},
[46] = {'Joseph Robinette Biden', 'Biden, Joe Robinette'},
[47] = {'Donald John Trump', 'Trump, Donald John'}
}
local author_subpages = {
{name = 'Proclamations', pages = {{'Presidential Proclamations', 'Proclamations'}}},
{name = 'Executive orders', pages = {{'Executive orders'}}},
{name = 'Memoranda', pages = {{'Presidential memoranda', 'Memoranda'}}},
{name = 'Letters', pages = {{'Letters'}}},
{name = 'Media', pages = {{'Podcasts'}, {'Presidential radio addresses', 'Radio addresses'}, {'Weekly addresses'}}}
}
local function link_td(president, subpages)
local links = {}
local br = mw.html.create('br')
for i, v in ipairs(subpages) do
local page = mw.title.new(president .. '/' .. v[1], 'Author')
if page.exists then
if #links > 0 then
table.insert(links, br)
end
local page_display
for j = #v, 1, -1 do
mw.logObject(j)
if v[j] then
page_display = v[j]
break
end
end
table.insert(links, '[[' .. page.fullText .. '|' .. page_display .. ']]')
end
end
local td = mw.html.create('td')
for i, v in ipairs(links) do
if type(v) == 'string' then
td:wikitext(v)
else
td:node(v)
end
end
return td
end
local function potus_tr(args)
local n = tonumber(args.n) or error('Parameter n must be a number')
if not presidents[n] then
error('No data for n=' .. n)
end
local tr = mw.html.create('tr')
:tag('td'):wikitext(n)
:allDone()
local president = presidents[n][1]
local president_sort = presidents[n][2]
local president_display = presidents[n][3] or president
local other = args.other
tr:tag('td')
:tag('span')
:css({['display'] = 'none'})
:wikitext(president_sort)
:done()
:wikitext('[[Author:' .. president .. '|' .. president_display .. ']]')
for i, v in ipairs(author_subpages) do
tr:node(link_td(president, v.pages))
end
tr:tag('td'):wikitext(other)
return tr
end
function p._potus_table(args)
local table_obj = mw.html.create('table')
:addClass('wikitable sortable')
:css({['margin'] = '0 auto'})
local header_row = table_obj:tag('tr')
header_row:tag('th'):wikitext('No.'):done()
header_row:tag('th'):wikitext('Name'):done()
for i, v in ipairs(author_subpages) do
header_row:tag('th'):wikitext(v.name)
end
header_row:tag('th'):wikitext('Other')
local other_table = {}
for k, v in pairs(args) do
if string.sub(k, 1, 5) == 'other' and tonumber(string.sub(k, 6)) then
other_table[tonumber(string.sub(k, 6))] = v
end
end
local row_table = {}
for i, v in ipairs(presidents) do
local row_args = {
['n'] = i,
['other'] = other_table[i]
}
row_table[i] = potus_tr(row_args)
end
row_table = TableTools.compressSparseArray(row_table)
for i, row in ipairs(row_table) do
table_obj:node(row)
end
return table_obj
end
function p.potus_table(frame)
return p._potus_table(getArgs(frame))
end
return p