Module:Footnotes: Difference between revisions
From All Skies Encyclopaedia
imported>Dragons flight No edit summary |
imported>Dragons flight No edit summary |
||
Line 19: | Line 19: | ||
} |
} |
||
}; |
}; |
||
function trim( str ) |
|||
if str == nil then |
|||
return nil; |
|||
end |
|||
return str:match( "^%s*(.-)%s*$"); |
|||
end |
|||
function core( args ) |
function core( args ) |
||
Line 67: | Line 74: | ||
args.pages_sep = frame.args.PagesSep or ""; |
args.pages_sep = frame.args.PagesSep or ""; |
||
args.ref = frame.args.REF or ""; |
args.ref = frame.args.REF or ""; |
||
args.P1 = frame.args[1] or ""; |
args.P1 = trim( frame.args[1] ) or ""; |
||
args.P2 = frame.args[2] or ""; |
args.P2 = trim( frame.args[2] ) or ""; |
||
args.P3 = frame.args[3] or ""; |
args.P3 = trim( frame.args[3] ) or ""; |
||
args.P4 = frame.args[4] or ""; |
args.P4 = trim( frame.args[4] ) or ""; |
||
args.P5 = frame.args[5] or ""; |
args.P5 = trim( frame.args[5] ) or ""; |
||
return core( args ); |
return core( args ); |
||
Line 86: | Line 93: | ||
args.location = frame.args.loc or ""; |
args.location = frame.args.loc or ""; |
||
args.ref = pframe.args.ref or pframe.args.REF or ""; |
args.ref = pframe.args.ref or pframe.args.REF or ""; |
||
args.P1 = pframe.args[1] or ""; |
args.P1 = trim( pframe.args[1] ) or ""; |
||
args.P2 = pframe.args[2] or ""; |
args.P2 = trim( pframe.args[2] ) or ""; |
||
args.P3 = pframe.args[3] or ""; |
args.P3 = trim( pframe.args[3] ) or ""; |
||
args.P4 = pframe.args[4] or ""; |
args.P4 = trim( pframe.args[4] ) or ""; |
||
args.P5 = pframe.args[5] or ""; |
args.P5 = trim( pframe.args[5] ) or ""; |
||
return core( args ); |
return core( args ); |
||
Line 103: | Line 110: | ||
args.location = frame.args.loc or ""; |
args.location = frame.args.loc or ""; |
||
args.ref = pframe.args.ref or pframe.args.REF or ""; |
args.ref = pframe.args.ref or pframe.args.REF or ""; |
||
args.P1 = pframe.args[1] or ""; |
args.P1 = trim( pframe.args[1] ) or ""; |
||
args.P2 = pframe.args[2] or ""; |
args.P2 = trim( pframe.args[2] ) or ""; |
||
args.P3 = pframe.args[3] or ""; |
args.P3 = trim( pframe.args[3] ) or ""; |
||
args.P4 = pframe.args[4] or ""; |
args.P4 = trim( pframe.args[4] ) or ""; |
||
args.P5 = pframe.args[5] or ""; |
args.P5 = trim( pframe.args[5] ) or ""; |
||
return core( args ); |
return core( args ); |
||
Line 121: | Line 128: | ||
args.location = frame.args.loc or ""; |
args.location = frame.args.loc or ""; |
||
args.ref = pframe.args.ref or pframe.args.REF or ""; |
args.ref = pframe.args.ref or pframe.args.REF or ""; |
||
args.P1 = pframe.args[1] or ""; |
args.P1 = trim( pframe.args[1] ) or ""; |
||
args.P2 = pframe.args[2] or ""; |
args.P2 = trim( pframe.args[2] ) or ""; |
||
args.P3 = pframe.args[3] or ""; |
args.P3 = trim( pframe.args[3] ) or ""; |
||
args.P4 = pframe.args[4] or ""; |
args.P4 = trim( pframe.args[4] ) or ""; |
||
args.P5 = pframe.args[5] or ""; |
args.P5 = trim( pframe.args[5] ) or ""; |
||
local result = core( args ); |
local result = core( args ); |
Revision as of 04:22, 31 March 2013
Documentation for this module may be created at Module:Footnotes/doc
f = {
args_default = {
bracket_left = "",
bracket_right = "",
bracket_year_left = "",
bracket_year_right = "",
postscript = "",
page = "",
pages = "",
location = "",
page_sep = ", p. ",
pages_sep = ", pp. ",
ref = "",
P1 = "",
P2 = "",
P3 = "",
P4 = "",
P5 = ""
}
};
function trim( str )
if str == nil then
return nil;
end
return str:match( "^%s*(.-)%s*$");
end
function core( args )
local result;
if args.P5 ~= "" then
result = args.P1 .. ' et al. ' .. args.bracket_year_left .. args.P5;
elseif args.P4 ~= "" then
result = args.P1 .. ', ' .. args.P2 .. ' & ' .. args.P3 .. ' ' .. args.bracket_year_left .. args.P4;
elseif args.P3 ~= "" then
result = args.P1 .. ' & ' .. args.P2 .. ' ' .. args.bracket_year_left .. args.P3;
else
result = args.P1 .. ' ' .. args.bracket_year_left .. args.P2
end
if args.ref ~= 'none' then
if args.ref ~= "" then
result = "[[#" .. args.ref .. "|" .. result .. "]]";
else
result = "[[#CITEREF" .. args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5 .. "|" .. result .. "]]";
end
end
if args.page ~= "" then
result = result .. args.page_sep .. args.page;
elseif args.pages ~= "" then
result = result .. args.pages_sep .. args.pages;
end
if args.location ~= "" then
result = result .. ", " .. args.location;
end
result = args.bracket_left .. result .. args.bracket_right .. args.postscript;
return result;
end
function f.harvard_core( frame )
local args = f.args_default;
args.bracket_left = frame.args.BracketLeft or "";
args.bracket_right = frame.args.BracketRight or "";
args.postscript = frame.args.Postscript or "";
args.page = frame.args.Page or "";
args.pages = frame.args.Pages or "";
args.location = frame.args.Location or "";
args.page_sep = frame.args.PageSep or "";
args.pages_sep = frame.args.PagesSep or "";
args.ref = frame.args.REF or "";
args.P1 = trim( frame.args[1] ) or "";
args.P2 = trim( frame.args[2] ) or "";
args.P3 = trim( frame.args[3] ) or "";
args.P4 = trim( frame.args[4] ) or "";
args.P5 = trim( frame.args[5] ) or "";
return core( args );
end
function f.harvard_citation( frame )
local args = f.args_default;
pframe = frame:getParent();
args.bracket_left = "(";
args.bracket_right = ")";
args.page = pframe.args.p or pframe.args.page or "";
args.pages = pframe.args.pp or pframe.args.pages or "";
args.location = frame.args.loc or "";
args.ref = pframe.args.ref or pframe.args.REF or "";
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";
return core( args );
end
function f.harvard_citation_no_bracket( frame )
local args = f.args_default;
pframe = frame:getParent();
args.page = pframe.args.p or pframe.args.page or "";
args.pages = pframe.args.pp or pframe.args.pages or "";
args.location = frame.args.loc or "";
args.ref = pframe.args.ref or pframe.args.REF or "";
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";
return core( args );
end
function f.sfn( frame )
local args = f.args_default;
pframe = frame:getParent();
args.postscript = pframe.args.postscript or pframe.args.ps or ".";
args.page = pframe.args.p or pframe.args.page or "";
args.pages = pframe.args.pp or pframe.args.pages or "";
args.location = frame.args.loc or "";
args.ref = pframe.args.ref or pframe.args.REF or "";
args.P1 = trim( pframe.args[1] ) or "";
args.P2 = trim( pframe.args[2] ) or "";
args.P3 = trim( pframe.args[3] ) or "";
args.P4 = trim( pframe.args[4] ) or "";
args.P5 = trim( pframe.args[5] ) or "";
local result = core( args );
result = "{{#tag:ref|" .. result .. "|name=FOOTNOTE" .. args.P1 .. args.P2 ..
args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location .. "}}";
return frame:preprocess( result );
end
return f;