Module:Template link general: Difference between revisions
update from sandbox - fixes to _show_result and adding _expand |
m 1 revision imported: Content from Template:Location Map+ on Wikipedia |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
-- This implements Template: | -- This implements Template:Template link general and various other templates in its family | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
| Line 32: | Line 32: | ||
end | end | ||
-- Builds the link part | |||
local function linkTitle(args) | local function linkTitle(args) | ||
local titleObj | local titleObj | ||
if args['1'] then | if args['1'] then | ||
-- This handles :Page and other NS | -- This handles :Page and other NS | ||
| Line 45: | Line 41: | ||
titleObj = mw.title.getCurrentTitle() | titleObj = mw.title.getCurrentTitle() | ||
end | end | ||
local textPart = args.alttext | local textPart = args.alttext | ||
if not _ne(textPart) then | if not _ne(textPart) then | ||
| Line 69: | Line 62: | ||
textPart = nw('{') .. textPart .. nw('}') | textPart = nw('{') .. textPart .. nw('}') | ||
end | end | ||
titlePart = titlePart .. '|' .. textPart .. ']]' | local titlePart | ||
if _ne(args.nolink) then | |||
titlePart = textPart | |||
else | |||
titlePart = '[[' .. (titleObj ~= nil and titleObj.fullText or addTemplate(args['1'])) .. | |||
'|' .. textPart .. ']]' | |||
end | |||
if _ne(args.braceinside) then | if _ne(args.braceinside) then | ||
titlePart = nw('{') .. titlePart .. nw('}') | titlePart = nw('{') .. titlePart .. nw('}') | ||
end | |||
local bold = _ne(args.bold) or _ne(args.boldlink) or _ne(args.boldname) | |||
if bold then | |||
titlePart = "'''" .. titlePart .. "'''" | |||
end | |||
if _ne(args.nowrapname) then | |||
titlePart = '<span class="nowrap">' .. titlePart .. '</span>' | |||
end | end | ||
return titlePart | return titlePart | ||
| Line 86: | Line 92: | ||
function p._main(args) | function p._main(args) | ||
local italic = _ne(args.italic) or _ne(args.italics) | local italic = _ne(args.italic) or _ne(args.italics) | ||
local dontBrace = _ne(args.brace) or _ne(args.braceinside) | local dontBrace = _ne(args.brace) or _ne(args.braceinside) | ||
| Line 93: | Line 98: | ||
local expand = _ne(args._expand) | local expand = _ne(args._expand) | ||
local titlePart = linkTitle(args) | local titlePart = linkTitle(args) | ||
-- Build the arguments | -- Build the arguments | ||
| Line 137: | Line 139: | ||
ret = '<code>' .. ret .. '</code>' | ret = '<code>' .. ret .. '</code>' | ||
elseif _ne(args.plaincode) then | elseif _ne(args.plaincode) then | ||
ret = '<code style="border:none;background:transparent;">' .. ret .. '</code>' | ret = '<code style="border:none;background:transparent;color:inherit">' .. ret .. '</code>' | ||
end | end | ||
if _ne(args.nowrap) then ret = '<span class="nowrap">' .. ret .. '</span>' end | if _ne(args.nowrap) then ret = '<span class="nowrap">' .. ret .. '</span>' end | ||
| Line 148: | Line 150: | ||
if show_result then | if show_result then | ||
if _ne(args.nocat) then codeArguments['nocat'] = true end | |||
local result = mw.getCurrentFrame():expandTemplate{title = addTemplate(args[1]), args = codeArguments} | local result = mw.getCurrentFrame():expandTemplate{title = addTemplate(args[1]), args = codeArguments} | ||
ret = ret .. " → " .. result | ret = ret .. " → " .. result | ||