Module:Short title/sandbox

From Wikisource
Jump to navigation Jump to search
local p = {}

local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
	local args = getArgs(frame, {wrappers = 'Template:Short-title', valueFunc = function(k, v)
		if v then
			v = mw.text.trim(v)
		end
		if v ~= '' or k == 'sn' or k == 'm' then
			return v
		end
	end })

	if not args.s then
		return '<span class="error">Error: No title passed to {{[[Template:Short-title|Short-title]]}}</span>'
	end
	local retval
	if false then -- if args.style == 'ref' then
		-- The original template has an error in its code that prevents this from ever working, so I'm not going to bother converting it for now.
		-- {{tag:ref|{{#if: {{{c|}}}|[[{{#if: {{{y|}}}|{{{s}}} {{{y}}}|{{{s}}} }}{{!}}{{{c}}}]]|{{#if: {{{the|}}}|The&nbsp;|}}{{#if: {{{link|}}}|[[{{#if: {{{y|}}}|{{{s}}} {{{y}}}|{{{s}}}}}{{!}}{{{s}}} {{#if: {{{y|}}}|{{#ifeq: {{{comma}}}|yes|,|}} {{{y}}}|}}]]| {{{s}}}  {{#if: {{{y|}}}|{{#ifeq: {{{comma}}}|yes|,|}} {{{y}}}|}}}}}}}}
	else
		if args.c then
			retval = string.format('[[%s %s%s%s|%s]]',
				args.s,
				args.y or '',
				args.a and '#' or '',
				args.a or '',
				args.c
			)
		else
			local maybeThe = args.the and 'The&nbsp;' or ''
			local maybeComma = args.comma == 'yes' and ',' or ''
			if args.link then
				retval = string.format('%s[[%s %s|%s%s]]',
					maybeThe,
					args.s,
					args.y or '',
					args.s,
					args.y and string.format('%s&nbsp;%s', maybeComma, args.y) or ''
				)
			else
				retval = string.format('%s%s %s',
					maybeThe,
					args.s,
					args.y and string.format('%s %s', maybeComma, args.y) or ''
				)
			end
		end
	end
	if not args.sn or args.sn == 'none' then
		if args.regnal == 'yes' then
			retval = string.format('%s (%s%s c.%s)', retval, args.r, args.m, args.chapter)
		end
	elseif args.sn == 'cl' then
		retval = retval .. frame:expandTemplate{title = 'cl-act-title', args = {
			'',
			string.format('%s%s c.%s', args.r, args.m, args.chapter),
			layout = args.layout or ''
		}}
	elseif args.sn ~= '' then
		retval = retval .. frame:expandTemplate{title = 'Outside ' .. args.sn, args = {
			string.format('%s c.%s', args.r, args.chapter)
		}}
	end
	return retval
end

return p