Module:Citation/CS1: Difference between revisions

From All Skies Encyclopaedia
imported>Uncle G
(Added missing function parameter.)
imported>Uncle G
(Incorporated the logic of Template:sfn into a LUA function.)
Line 1: Line 1:
local p = {}
local p = {}

-- This is used by templates such as {{Harvard citation}} to create the Harvard footnote.
function p.Harvard()
function anchorid(frame)
local P1 = frame.args[1] or ""
return "PLACEHOLDER"
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
local P5 = frame.args[5] or ""
return "CITEREF" .. P1 .. P2 .. P3 .. P4 .. P5
end
end

function name(frame)
local P1 = frame.args[1] or ""
if ( frame.args[5] ~= nil) then
return P1 .. " et al."
else
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
if ( frame.args[4] ~= nil ) then
P4 = " & " .. P4
end
if ( frame.args[3] ~= nil ) then
P3 = " & " .. P3
end
if ( frame.args[2] ~= nil ) then
P2 = " & " .. P2
end
return P1 .. P2 .. P3 .. P4
end
end

function crossref(frame)
local LB = frame.BracketLeft or ""
local RB = frame.BracketRightt or ""
local anchor = frame.ref or frame.Ref or anchorid(frame)
local text = name(frame)
local loc = frame.loc or ""
local page = frame.p or frame.page or nil
local pages = frame.pp or frame.pages or nil
if ( page ~= nil ) then
local pagesep = frame.PageSep or ""
text = text .. pagesep .. page
end
if ( pages ~= nil ) then
local pagessep = frame.PagesSep or ""
text = text .. pagessep .. pages
end
local ps = frame.Postscript or ""
return LB .. "[[#" .. anchor .. "|" .. text .. "]]" .. RB .. ps
end

-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
function p.SFNID(frame)
function p.SFNID(frame)
local pframe = frame:getParent()
local pframe = frame:getParent()
local P1 = pframe.args[1] or ""
return anchorid(pframe)
end
local P2 = pframe.args[2] or ""

local P3 = pframe.args[3] or ""
-- This is used by templates such as {{Harvard citation}} to create the Harvard cross-reference text.
local P4 = pframe.args[4] or ""
function p.Harvard(frame)
local P5 = pframe.args[4] or ""
local pframe = frame:getParent()
return "CITEREF" .. P1 .. P2 .. P3 .. P4 .. P5
return crossref(pframe)
end

-- This is used by templates such as {{sfn}} to create the entire cross-reference.
function p.sfn(frame)
local pframe = frame:getParent()
local content = crossref(pframe)
local args = { name = anchorid(pframe) }
return mw.text.tag({name = "ref", contents = content, params = args})
end
end

return p
return p

Revision as of 12:03, 25 August 2012

<section begin=header />

Lua error: bad argument #1 to "get" (not a valid title).<section end=header /> This module and associated sub-modules support the Citation Style 1 and Citation Style 2 citation templates. In general, it is not intended to be called directly, but is called by one of the core CS1 and CS2 templates. <section begin=module_components_table /> These files comprise the module support for CS1|2 citation templates:

CS1 | CS2 modules
live sandbox diff description
Gold padlock Module:Citation/CS1 Module:Citation/CS1/sandbox [edit] diff Rendering and support functions
Module:Citation/CS1/Configuration Module:Citation/CS1/Configuration/sandbox [edit] diff Translation tables; error and identifier handlers
Module:Citation/CS1/Whitelist Module:Citation/CS1/Whitelist/sandbox [edit] diff List of active and deprecated CS1|2 parameters
Module:Citation/CS1/Date validation Module:Citation/CS1/Date validation/sandbox [edit] diff Date format validation functions
Module:Citation/CS1/Identifiers Module:Citation/CS1/Identifiers/sandbox [edit] diff Functions that support the named identifiers (ISBN, DOI, PMID, etc.)
Module:Citation/CS1/Utilities Module:Citation/CS1/Utilities/sandbox [edit] diff Common functions and tables
Module:Citation/CS1/COinS Module:Citation/CS1/COinS/sandbox [edit] diff Functions that render a CS1|2 template's metadata
Module:Citation/CS1/styles.css Module:Citation/CS1/sandbox/styles.css [edit] diff CSS styles applied to the CS1|2 templates
Silver padlock Module:Citation/CS1/Suggestions Module:Citation/CS1/Suggestions/sandbox [edit] diff List that maps common erroneous parameter names to valid parameter names

<section end=module_components_table />

Other documentation:

testcases


local p = {}

function anchorid(frame)
    local P1 = frame.args[1] or ""
    local P2 = frame.args[2] or ""
    local P3 = frame.args[3] or ""
    local P4 = frame.args[4] or ""
    local P5 = frame.args[5] or ""
    return "CITEREF" .. P1 .. P2 .. P3 .. P4 .. P5
end

function name(frame)
    local P1 = frame.args[1] or ""
    if ( frame.args[5] ~= nil) then
        return P1 .. " et al."
    else
        local P2 = frame.args[2] or ""
        local P3 = frame.args[3] or "" 
        local P4 = frame.args[4] or ""
        if ( frame.args[4] ~= nil ) then
            P4 = " & " .. P4
        end
        if ( frame.args[3] ~= nil ) then
            P3 = " & " .. P3
        end
        if ( frame.args[2] ~= nil ) then
            P2 = " & " .. P2
        end
        return P1 .. P2 .. P3 .. P4
    end 
end

function crossref(frame)
    local LB = frame.BracketLeft or ""
    local RB = frame.BracketRightt or ""
    local anchor = frame.ref or frame.Ref or anchorid(frame)
    local text = name(frame)
    local loc = frame.loc or ""
    local page = frame.p or frame.page or nil
    local pages = frame.pp or frame.pages or nil
    if ( page ~= nil ) then
        local pagesep = frame.PageSep or ""
        text = text .. pagesep .. page
    end
    if ( pages ~= nil ) then
        local pagessep = frame.PagesSep or ""
        text = text .. pagessep .. pages
    end        
    local ps = frame.Postscript or ""
    return LB .. "[[#" .. anchor .. "|" .. text .. "]]" .. RB .. ps
end

-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
function p.SFNID(frame)
    local pframe = frame:getParent()
    return anchorid(pframe)
end

-- This is used by templates such as {{Harvard citation}} to create the Harvard cross-reference text.
function p.Harvard(frame)
    local pframe = frame:getParent()
    return crossref(pframe)
end

-- This is used by templates such as {{sfn}} to create the entire cross-reference.
function p.sfn(frame)
    local pframe = frame:getParent()
    local content = crossref(pframe)
    local args = { name = anchorid(pframe) }
    return mw.text.tag({name = "ref", contents = content, params = args})
end

return p