Module:Sports table/sub: Difference between revisions

From Chalo Chatu, Zambia online encyclopedia
(Created page with "-- Subfunctions for this module that are called from the style modules local ppp = {} function ppp.colhead(ttt,width,text) -- For individual column headers local head_strin...")
 
m (1 revision imported)
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
function ppp.hth(frame,Args,full_table,hth_id_list,hth_local,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val)
function ppp.hth(frame,Args,full_table,hth_id_list,hth_local,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val)
-- For head-to-head notes
-- For head-to-head notes
local hth_string,hth_local_num, hth_id
local hth_string, hth_local_num, hth_id, k, hth_loc = '', nil, nil, nil, nil
-- Check whether there is a head-to-head note or not, if so get text ready for it the same way as for the notes
-- Check whether there is a head-to-head note or not, if so get text ready for it the same way as for the notes
Line 25: Line 25:
-- Set global check for notes to true
-- Set global check for notes to true
notes_exist = true
notes_exist = true
if not Args['hth_'..hth_local] then
-- Option 1
-- Split the hth_local into a table if all the entries are valid
-- Now define the identifier for this
local multiref = 1
hth_id = '"table_hth_'..team_code_ii..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID)
local hth_local_table = mw.text.split(hth_local, '%s*,%s*')
hth_id_list[team_code_ii] = hth_id
if (#hth_local_table > 1) then
-- Call refn template
for k, hth_loc in ipairs(hth_local_table) do
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes',  name=hth_id, hth_local} }
multiref = multiref * (Args['hth_' .. hth_loc] and 1 or 0)
else
end
-- Option 2
else
hth_local_num = team_list[hth_local]
multiref = 0
if hth_id_list[hth_local] or ((hth_local_num >= ii_start) and (hth_local_num <= ii_end)) then
end
-- Option 2a
 
hth_id = '"table_hth_'..hth_local..rand_val..'"'
-- Split failed, so make a single entry table with hth_local inside
hth_string = frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = hth_id} }
if multiref < 1 then
else
hth_local_table = { hth_local }
-- Option 2b
end
hth_id = '"table_hth_'..hth_local..rand_val..'"' -- Add random end for unique ID
 
hth_id_list[hth_local] = hth_id
for k,hth_loc in ipairs(hth_local_table) do
if not Args['hth_'..hth_loc] then
-- Option 1
-- Now define the identifier for this
hth_id = '"table_hth_'..team_code_ii..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID)
hth_id_list[team_code_ii] = hth_id
-- Call refn template
-- Call refn template
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes',  name=hth_id, Args['hth_'..hth_local]} }
hth_string = hth_string .. frame:expandTemplate{ title = 'efn', args = { group='Table_notes',  name=hth_id, hth_loc} }
else
-- Option 2
hth_local_num = team_list[hth_loc] or -1
if hth_id_list[hth_loc] or ((hth_local_num >= ii_start) and (hth_local_num <= ii_end)) then
-- Option 2a
hth_id = '"table_hth_'..hth_loc..rand_val..'"'
hth_string = hth_string .. frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = hth_id} }
else
-- Option 2b
hth_id = '"table_hth_'..hth_loc..rand_val..'"' -- Add random end for unique ID
hth_id_list[hth_loc] = hth_id
-- Call refn template
hth_string = hth_string .. frame:expandTemplate{ title = 'efn', args = { group='Table_notes',  name=hth_id, Args['hth_'..hth_loc]} }
end
end
end
end
end
else
hth_string = '';
end
end

Latest revision as of 13:11, 22 September 2019

-- Subfunctions for this module that are called from the style modules local ppp = {}

function ppp.colhead(ttt,width,text) -- For individual column headers local head_string if width=='auto' then head_string = '! scope="col" |'..text..'\n' else head_string = '! scope="col" width='..width..'|'..text..'\n' end

ttt.count = ttt.count+1 table.insert(ttt.tab_text,head_string)

return ttt end

function ppp.hth(frame,Args,full_table,hth_id_list,hth_local,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val) -- For head-to-head notes local hth_string, hth_local_num, hth_id, k, hth_loc = , nil, nil, nil, nil

-- Check whether there is a head-to-head note or not, if so get text ready for it the same way as for the notes if hth_local and full_table then -- Set global check for notes to true notes_exist = true

-- Split the hth_local into a table if all the entries are valid local multiref = 1 local hth_local_table = mw.text.split(hth_local, '%s*,%s*') if (#hth_local_table > 1) then for k, hth_loc in ipairs(hth_local_table) do multiref = multiref * (Args['hth_' .. hth_loc] and 1 or 0) end else multiref = 0 end

-- Split failed, so make a single entry table with hth_local inside if multiref < 1 then hth_local_table = { hth_local } end

for k,hth_loc in ipairs(hth_local_table) do if not Args['hth_'..hth_loc] then -- Option 1 -- Now define the identifier for this hth_id = '"table_hth_'..team_code_ii..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID) hth_id_list[team_code_ii] = hth_id -- Call refn template hth_string = hth_string .. frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, hth_loc} } else -- Option 2 hth_local_num = team_list[hth_loc] or -1 if hth_id_list[hth_loc] or ((hth_local_num >= ii_start) and (hth_local_num <= ii_end)) then -- Option 2a hth_id = '"table_hth_'..hth_loc..rand_val..'"' hth_string = hth_string .. frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = hth_id} } else -- Option 2b hth_id = '"table_hth_'..hth_loc..rand_val..'"' -- Add random end for unique ID hth_id_list[hth_loc] = hth_id -- Call refn template hth_string = hth_string .. frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, Args['hth_'..hth_loc]} } end end end end

return {str=hth_string, list=hth_id_list, notes_exist=notes_exist} end

return ppp