پودمان:Infobox road/route

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[ایجاد] [پاکسازی]
local p = {} 

local format = mw.ustring.format
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs	
local parserModule = require 'Module:Road data/parser/تمرین'
local parser = parserModule.parser

local function banner(args, bannerSize)
	if args.marker_image or args['تصویر نشانگر'] then return nil end
	
	if args.shielderr then return nil end
		
	local shield = parser(args, 'banner')
	if not shield or shield == '' then return nil end
	
	local alt = parser(args, 'banner')
	
	return mw.ustring.format('[[پرونده:%s|%s|جایگرین=%s]]', shield, bannerSize, alt)
end



local function shield(args, shieldSize)
	if args.marker_image then
		return args.marker_image
	elseif args['تصویر نشانگر'] then
		return args['تصویر نشانگر']
	end

	local shield = parser(args, 'shieldmain') or parser(args, 'shield')
	
	if not shield or shield == '' then return nil end
	
	local label = parser(args, 'name') or parser(args, 'abbr') or ''
	local alt = label .. ' marker'
	local orientation = parser(args, 'orientation')
	
	local function shield_size(image_name, orientation)
		local image = 'پرونده:' .. image_name
		local title = mw.title.new(image)

		local width = title.file.width
		local height = title.file.height
		
		if (orientation and orientation == 'upright') or height > width then
			return shieldSize
		else
			return 'x' .. shieldSize
		end
	end
	
	if type(shield) == 'table' then
		local res = {}
		local sizes = {}
		for i,v in ipairs(shield) do
			sizes[i] = v
			res[i] = mw.ustring.format('[[پرونده:%s|%s|جایگزین=%s]]', v, shield_size(v), alt)
		end
    	return table.concat(res, ' ')
	else
    	return mw.ustring.format('[[پرونده:%s|%s|جایگزین=%s]]', shield, shield_size(shield, orientation), alt)
	end
end

-- Links/abbreviations
local function name(args)
	local name = args.name or args['نام'] or parser(args, 'name') or parser(args, 'نام') or parser(args, 'abbr') or parser(args, 'ابهام‌زدایی')
	return name
end

function p._routeInfo(args)
	
	local style = args.style or args['سبک']
	local banner = banner(args, require('Module:Road data/size').size({style = style}))
	local shield = shield(args, require('Module:Road data/size').size({style = style}))
	local name = name(args)

	if not (args.type or args['نوع']) and not (args.route or args['مسیر']) and not (args.name or args['نام']) and not (args.marker_image or args['تصویر نشانگر']) then
		local container = nil
	else local container = mw.html.create('div'):cssText('text-align:center;')
		if shield == nil or args.marker_image == 'none' or args['تصویر نشانگر'] == 'none' or (args.name or args['نام']) and not (args.marker_image or args['تصویر نشانگر']) and not (args.type or args['نوع']) and not (args.route or args['مسیر']) then 
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
		elseif (args.marker_image ~= '' or args['تصویر نشانگر'] ~= '') and (args.name == '' or args['نام'] == '') or (args.name or args['نام']) == nil and not (args.type or args['نوع']) and not (args.route or args['مسیر']) then
			container:tag('p'):cssText('margin:0.1em;'):wikitext(shield)
		elseif (args.country or args['کشور']) == 'AUS' then
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
			container:tag('p'):cssText('margin:0.1em 0 0 0;'):wikitext(shield)
		else
			container:tag('p'):cssText('margin:0.1em 0 0 0;'):wikitext(banner)
			container:tag('p'):cssText('margin:0 0 0.1em;'):wikitext(shield)
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
		end
		return tostring(container)
	end
end

function p.routeInfo(frame)
	local args = getArgs(frame)
	return p._routeInfo(args);
end

return p