Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Transclude
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- <nowiki> -------------------------------------------------------------------------------- -- Module that allows transcluding a template with all parent arguments. -- Useful in `/i18n` template subpages that delegate to a `/layout` subpage. -- -- @module transclude -- @author [[User:ExE Boss]] -------------------------------------------------------------------------------- require('strict') local checkType = require('libraryUtil').checkType; local p = {} local INVALID_TITLES = { ["."] = true, [".."] = true, }; local function _ne(value) return value and value ~= '' end -------------------------------------------------------------------------------- -- Helper function that merges argument tables. -- -- @function mergeArgs -- @param {table} inArgs -- @param {table} outArgs -------------------------------------------------------------------------------- local function mergeArgs(inArgs, outArgs, opts) checkType("mergeArgs", 1, inArgs, "table"); checkType("mergeArgs", 2, outArgs, "table"); checkType("mergeArgs", 3, opts, "table", true); opts = opts or {} local ignoredParams = opts.ignoredParams; local ignoredPrefix = opts.ignoredPrefix; for name, value in pairs(inArgs) do if (type(name) == "string") then if not ( (ignoredParams and ignoredParams[name] == true) or (ignoredPrefix and ignoredPrefix == name:sub(1, ignoredPrefix:len())) ) then outArgs[name] = value; end else outArgs[name] = value; end end return outArgs; end -- Exported for testing: p['#mergeArgs'] = mergeArgs; local mt = {}; function mt.__index(_, name) if ( type(name) ~= "string" or INVALID_TITLES[name] or mw.ustring.find(name, "#", nil, true) ) then return nil; end local title = mw.title.new(name, "Template") if (not title) then return nil; end return function (frame) checkType('transclude["' .. name .. '"]', 1, frame, "table"); local parentFrame = frame:getParent(); local ignoredParams, ignoredPrefix; if _ne(frame.args["#ignoredParams"]) then ignoredParams = {}; for m in mw.text.gsplit(frame.args["#ignoredParams"], '|', true) do ignoredParams[mw.text.trim(m)] = true; end end if _ne(frame.args['#ignoredPrefix']) then ignoredPrefix = frame.args['#ignoredPrefix']; end local args = {}; if (parentFrame) then mergeArgs(parentFrame.args, args, { ignoredParams = ignoredParams, ignoredPrefix = ignoredPrefix, }); end mergeArgs(frame.args, args, { ignoredPrefix = "#", }); if (not title.exists) then return "[[:" .. title.fullText .. "]]"; end return frame:expandTemplate{ title = title, args = args, }; end end return setmetatable(p, mt);
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Transclude/doc
(
edit
)