Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:TagQS: Difference between revisions

From Neodyland Wiki
Created page with '--[[ This module is intended to Authors and maintainers: * User:Jarekt - orig...'
 
No edit summary
Line 1: Line 1:
--[[   
--[[   
  _____            .___    .__              ___________              ________    _________
  /    \  ____  __| _/_ __|  |  ____  /\ \__    ___/____    ____ \_____  \  /  _____/
/  \ /  \ /  _ \ / __ |  |  \  | _/ __ \  \/  |    |  \__  \  / ___\ /  / \  \ \_____  \
/    Y    (  <_> ) /_/ |  |  /  |_\  ___/  /\  |    |  / __ \_/ /_/  >  \_/.  \/        \
\____|__  /\____/\____ |____/|____/\___  > \/  |____|  (____  /\___  /\_____\ \_/_______  /
        \/            \/              \/                    \//_____/        \__>      \/


                                                                              
                                                                              
This module is intended to  
This module is intended for creating invisible tags which can be used to pass
language independent data from some templates to infoboxes. Those tags are often
used by templates like [Template:Artwork]  to pass data to Wikidata


Authors and maintainers:
Authors and maintainers:
Line 28: Line 36:
end
end


function p.changeProperty(text, old, new)
function p.changeProperty(text, field, old, new)
if not old then
if not old then
old = '(^,)+'
old = '(^,)+'
end
end
local patrn = '%<div style="display: none;"%>((^ )+) QS:' .. old .. ',([^%<]+)%</div%>'
local patrn = '%<div style="display: none;"%>' .. field .. ' QS:' .. old .. ',([^%<]+)%</div%>'
local repl  = '<div style="display: none;">%1 QS:' .. new .. ',%1</div>'
local repl  =   '<div style="display: none;">' .. field .. ' QS:' .. new .. ',%1</div>'
return string.gsub(text, patrn, repl)
return string.gsub(text, patrn, repl)
end
end
Line 52: Line 60:
return p.createTag(frame.args[1], frame.args[2], frame.args[3])
return p.createTag(frame.args[1], frame.args[2], frame.args[3])
end
end


return p
return p

Revision as of 03:59, 15 January 2021

Module documentation[ create · purge ]
This documentation is transcluded from Module:TagQS/doc.
--[[  
   _____             .___    .__              ___________              ________    _________
  /     \   ____   __| _/_ __|  |   ____   /\ \__    ___/____     ____ \_____  \  /   _____/
 /  \ /  \ /  _ \ / __ |  |  \  | _/ __ \  \/   |    |  \__  \   / ___\ /  / \  \ \_____  \ 
/    Y    (  <_> ) /_/ |  |  /  |_\  ___/  /\   |    |   / __ \_/ /_/  >   \_/.  \/        \
\____|__  /\____/\____ |____/|____/\___  > \/   |____|  (____  /\___  /\_____\ \_/_______  /
        \/            \/               \/                    \//_____/        \__>       \/ 

                                                                             
This module is intended for creating invisible tags which can be used to pass 
language independent data from some templates to infoboxes. Those tags are often 
used by templates like [Template:Artwork]  to pass data to Wikidata

Authors and maintainers:
* User:Jarekt - original version 
]]

require('Module:No globals') -- used for debugging purposes as it detects cases of unintended global variables

-- ==================================================
-- === External functions ===========================
-- ==================================================
local p = {}

-- ===========================================================================
-- === Version of the function to be called from other LUA codes
-- ===========================================================================
function p.createTag(field, property, value)
	return string.format('<div style="display: none;">%s QS:%s,%s</div>\n', field, property or 'P', value)
end

function p.changeField(text, old, new)
	local patrn = '%<div style="display: none;"%>'.. old ..' QS:([^%<]+)%</div%>'
	local repl  = '<div style="display: none;">'.. new ..' QS:%1</div>'
	return string.gsub(text, patrn, repl)
end

function p.changeProperty(text, field, old, new)
	if not old then
		old = '(^,)+'
	end
	local patrn = '%<div style="display: none;"%>' .. field .. ' QS:' .. old .. ',([^%<]+)%</div%>'
	local repl  =   '<div style="display: none;">' .. field .. ' QS:' .. new .. ',%1</div>'
	return string.gsub(text, patrn, repl)
end

function p.readTag(text, field)
	local pat = '%<div style="display: none;"%>'..field..' QS:([^%<]+)%</div%>'
	local qs  = string.match(text, pat) -- find hidden tag with QS code
	local _, nMatch = string.gsub(text, pat, "") -- count matches
	if qs and nMatch==1 then -- allow only single matches
		return string.gsub(qs, ',', '|')
	end
end

-- ===========================================================================
-- === Versions of the function to be called from template namespace
-- ===========================================================================
function p.CreateTag(frame)
	return p.createTag(frame.args[1], frame.args[2], frame.args[3])
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.