Module:Infobox/Widget/Row: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
local Row = {}
local Row = {}


function Row.make(rowName, value, frame)
function Row.make(rowName, value, link, prefix)
local container = mw.html.create('div')
local container = mw.html.create('div')
:addClass('ib-row')
:addClass('ib-row')
Line 13: Line 13:
return container:node(name):node(value)
return container:node(name):node(value)
end
end
mw.log(frame)
 
mw.logObject(frame)
if link ~= nil then
if frame then
        local path = value
mw.log('on frame')
        if prefix ~= nil then path = prefix .. path end
mw.log('value: ' .. value)
       
local pageExists = frame:callParserFunction('#ifexist', value, 'yes', 'no' )
        local toShow = Row.toShow(value)
if ( pageExists == 'yes' ) then
 
valueNode:wikitext('[[' .. value .. '|' .. value.. ']]')
        if toShow then path = path .. '|' .. toShow end
else
       
valueNode:wikitext(value)
valueNode:wikitext('[[' .. path .. '|' .. value .. ']]')
end
else  
else  
valueNode:wikitext(value)
valueNode:wikitext(value)
Line 29: Line 28:
return container:node(name):node(valueNode)
return container:node(name):node(valueNode)
end
function Row.person(rowName, value, flag)
local container = mw.html.create('div')
:addClass('ib-row')
local name = mw.html.create('div')
:addClass('ib-rowName')
:wikitext(rowName .. ': ')
local valueNode = mw.html.create('div')
local toShow = Row.toShow(value)
valueNode:wikitext(flag):wikitext('[[' .. value .. '|' .. toShow .. ']]')
return container:node(name):node(valueNode)
end
function Row.toShow(str)
    if mw.title.new(str) then return nil end
local toShow = mw.text.split(str, '/')
       
    if #toShow > 1 then
toShow = toShow[2]
else
toShow = toShow[1]
    end
    return toShow
end
end




return Row
return Row

Latest revision as of 19:49, 24 December 2023

Documentation for this module may be created at Module:Infobox/Widget/Row/doc

local Row = {}

function Row.make(rowName, value, link, prefix)
	local container = mw.html.create('div')
		:addClass('ib-row')
	local name = mw.html.create('div')
			:addClass('ib-rowName')
			:wikitext(rowName .. ': ')
	local valueNode = mw.html.create('div')
	
	-- If value is table
	if type(value) ~= 'string' then
		return container:node(name):node(value)
	end

	if link ~= nil then
        local path = value 
        if prefix ~= nil then path = prefix .. path end
        
        local toShow = Row.toShow(value)

        if toShow then path = path .. '|' .. toShow end
        
		valueNode:wikitext('[[' .. path .. '|' .. value .. ']]')
	else 
		valueNode:wikitext(value)
	end
	
	return container:node(name):node(valueNode)
end

function Row.person(rowName, value, flag)
	local container = mw.html.create('div')
		:addClass('ib-row')
	local name = mw.html.create('div')
			:addClass('ib-rowName')
			:wikitext(rowName .. ': ')
	local valueNode = mw.html.create('div')
	
	local toShow = Row.toShow(value)
	
	valueNode:wikitext(flag):wikitext('[[' .. value .. '|' .. toShow .. ']]')

	return container:node(name):node(valueNode)
end

function Row.toShow(str)
    if mw.title.new(str) then return nil end
	local toShow = mw.text.split(str, '/')
        
    if #toShow > 1 then
		toShow = toShow[2]
	else 
		toShow = toShow[1]
    end
    return toShow
end


return Row