Difference between revisions of "Module:Italic title"

From blackwiki
Jump to navigation Jump to search
blackwiki>Paine Ellsworth
(per edit request on talk page)
blackwiki>Mr. Stradivarius
(use mw.site.namespaces to get the namespace name without underscores; also use Module:Arguments and convert whitespace to tabs)
Line 1: Line 1:
 
-- This module implements {{italic title}}.
 
-- This module implements {{italic title}}.
+
 
 
local p = {}
 
local p = {}
+
 
 
function p.main(frame)
 
function p.main(frame)
    -- Process the arguments.
+
local args = require('Module:Arguments').getArgs(frame, {
    local args
+
wrappers = 'Template:Italic title'
    if frame == mw.getCurrentFrame() then
+
})
        args = frame:getParent().args
+
local title = mw.title.getCurrentTitle()
        for k, v in pairs(frame.args) do
+
 
            args = frame.args
+
-- Find the parts before and after the disambiguation parentheses, if any.
            break
+
local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
        end
+
 
    else
+
-- If parentheses were found, italicise only the part before them. Otherwise
        args = frame
+
-- italicise the whole title.
    end   
+
local result
+
if prefix and parentheses and args.all ~= 'yes' then
    local title = mw.title.getCurrentTitle() -- Get the current page object.
+
result = "''" .. prefix .. "'' " .. parentheses
    -- Find the parts before and after the disambiguation parentheses, if any.
+
else
    local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
+
result = "''" .. title.text .. "''"
    -- If parentheses were found, italicise only the part before them. Otherwise
+
end
    -- italicise the whole title.
+
 
    local result
+
-- Add the namespace if we're not in mainspace.
    if prefix and parentheses and args.all ~= 'yes' then
+
if title.namespace ~= 0 then
        result = "''" .. prefix .. "'' " .. parentheses
+
result = mw.site.namespaces[title.namespace].name .. ':' .. result
    else
+
end
        result = "''" .. title.text .. "''"
+
 
    end
+
-- Call displaytitle with the text we generated.
    -- Add the namespace if it exists.
+
return mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', result)
    if title.nsText and title.nsText ~= "" then
 
        result = title.nsText:gsub('_', ' ') .. ':' .. result
 
    end
 
    -- Call displaytitle with the text we generated.
 
    return mw.getCurrentFrame():callParserFunction( 'DISPLAYTITLE', result )
 
 
end     
 
end     
+
 
 
return p
 
return p

Revision as of 07:56, 21 August 2014

This module implements {{italic title}} and {{italic dab}}. Please see the template pages for documentation.


-- This module implements {{italic title}}.

local p = {}

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Italic title'
	})
	local title = mw.title.getCurrentTitle()

	-- Find the parts before and after the disambiguation parentheses, if any.
	local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')

	-- If parentheses were found, italicise only the part before them. Otherwise
	-- italicise the whole title.
	local result
	if prefix and parentheses and args.all ~= 'yes' then
		result = "''" .. prefix .. "'' " .. parentheses
	else
		result = "''" .. title.text .. "''"
	end

	-- Add the namespace if we're not in mainspace.
	if title.namespace ~= 0 then
		result = mw.site.namespaces[title.namespace].name .. ':' .. result
	end

	-- Call displaytitle with the text we generated.
	return mw.getCurrentFrame():callParserFunction('DISPLAYTITLE', result)
end    

return p