Diff: Module:If preview
Comparing revision #1 (2021-05-05 19:01:42) with revision #2 (2023-02-02 05:39:41).
| Old | New |
|---|---|
local p = {} |
local p = {} |
local cfg = mw.loadData('Module:If preview/configuration') |
local cfg = mw.loadData('Module:If preview/configuration') |
--[[ |
--[[ |
main |
main |
This function returns either the first argument or second argument passed to |
This function returns either the first argument or second argument passed to |
this module, depending on whether the page is being previewed. |
this module, depending on whether the page is being previewed. |
]] |
]] |
function p.main(frame) |
function p.main(frame) |
if cfg.preview then |
if cfg.preview then |
return frame.args[1] or '' |
return frame.args[1] or '' |
else |
else |
return frame.args[2] or '' |
return frame.args[2] or '' |
end |
end |
end |
end |
--[[ |
--[[ |
pmain |
pmain |
This function returns either the first argument or second argument passed to |
This function returns either the first argument or second argument passed to |
this module's parent (i.e. template using this module), depending on whether it |
this module's parent (i.e. template using this module), depending on whether it |
is being previewed. |
is being previewed. |
]] |
]] |
function p.pmain(frame) |
function p.pmain(frame) |
return p.main(frame:getParent()) |
return p.main(frame:getParent()) |
end |
end |
local function warning_text(warning) |
local function warning_text(warning) |
return mw.ustring.format( |
return mw.ustring.format( |
cfg.warning_infrastructure, |
cfg.warning_infrastructure, |
cfg.templatestyles, |
cfg.templatestyles, |
warning |
warning |
) |
) |
end |
end |
function p._warning(args) |
function p._warning(args) |
local warning = args[1] and args[1]:match('^%s*(.-)%s*$') or '' |
local warning = args[1] and args[1]:match('^%s*(.-)%s*$') or '' |
if warning == '' then |
if warning == '' then |
return warning_text(cfg.missing_warning) |
return warning_text(cfg.missing_warning) |
end |
end |
if not cfg.preview then return '' end |
if not cfg.preview then return '' end |
return warning_text(warning) |
return warning_text(warning) |
end |
end |
--[[ |
--[[ |
warning |
warning |
This function returns a "preview warning", which is the first argument marked |
This function returns a "preview warning", which is the first argument marked |
up with HTML and some supporting text, depending on whether the page is being previewed. |
up with HTML and some supporting text, depending on whether the page is being previewed. |
disabled since we'll implement the template version in general |
disabled since we'll implement the template version in general |
]] |
]] |
--function p.warning(frame) |
--function p.warning(frame) |
-- return p._warning(frame.args) |
-- return p._warning(frame.args) |
--end |
--end |
--[[ |
--[[ |
warning, but for pass-through templates like {{preview warning}} |
warning, but for pass-through templates like {{preview warning}} |
]] |
]] |
function p.pwarning(frame) |
function p.pwarning(frame) |
return p._warning(frame:getParent().args) |
return p._warning(frame:getParent().args) |
end |
end |
return p |
return p |