Module:Igenmod: Difference between revisions
From Neodyland Wiki
More actions
m format |
m test |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ||
-- get workdate (does | |||
-- get workdate (sometimes does not work properly) | |||
function p.wrkdate ( ) | function p.wrkdate ( ) | ||
local parse = require("Module:HTMLParser").parse | local parse = require("Module:HTMLParser").parse | ||
| Line 18: | Line 19: | ||
-- get extension text ( | -- get extension text (uppercased) | ||
function p.exttext ( ) | function p.exttext ( ) | ||
local page = mw.title.getCurrentTitle().text; | local page = mw.title.getCurrentTitle().text; | ||
local ptab = mw.text.split(page , '.', true) | local ptab = mw.text.split(page , '.', true) | ||
return mw.ustring.upper( table.concat(ptab, '', #ptab ) ) | |||
end -- end function extText | end -- end function extText | ||
| Line 29: | Line 29: | ||
-- get extension code: "s" for SVG, else "n" | -- get extension code: "s" for SVG, else "n" | ||
function p.extcode ( ) | function p.extcode ( ) | ||
if p.exttext () == " | if p.exttext () == "SVG" | ||
then return "s" | then return "s" | ||
else return "n" | else return "n" | ||
end | end | ||
end -- end function extCode | end -- end function extCode | ||
| Line 56: | Line 39: | ||
function p.inkscape ( frame ) | function p.inkscape ( frame ) | ||
local otab = {} | local otab = {} | ||
if p.exttext () ~= " | if p.exttext () ~= "SVG" then | ||
table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } ); | table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } ); | ||
else | else | ||
| Line 67: | Line 50: | ||
key = key .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9,10 )) ) | key = key .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9,10 )) ) | ||
table.insert(otab, frame:expandTemplate{ title = "Igen/cat", args = {cat, key } }); | table.insert(otab, frame:expandTemplate{ title = "Igen/cat", args = {cat, key } }); | ||
local msg = " Template [[Template:Inkscape|{{Inkscape}}]] without W3C-specification is deprecated ! " | |||
-- local msg = " Template [[Template:Inkscape|{{Inkscape}}]] without W3C-specification is deprecated ! " | |||
-- table.insert(otab, frame:expandTemplate{ title = "error", args = {msg} } ); | |||
else | else | ||
table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } ); | table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } ); | ||
| Line 107: | Line 91: | ||
----------------------- TEST ------------------------------------------ | ----------------------- TEST ------------------------------------------ | ||
-- check whether it is a new file | |||
function p.newfile ( frame ) | |||
if p.exttext () ~= "SVG" then | |||
return "n" | |||
else | |||
local leng = frame [1] or 7; | |||
local wdat = p.wrkdate () or "2020-00-00" | |||
local sdat = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} ) | |||
local leng = tonumber ( frame.args[1] or 7 ) | |||
if mw.ustring.sub (wdat, 1, leng) ~= mw.ustring.sub (sdat, 1, leng) | |||
then return "s" | |||
else return "newcat" | |||
end | |||
end | |||
end -- end function newFile | |||
function p.cattest (args) | function p.cattest (args) | ||
local categ = mw.ext.cattools | local categ = mw.ext.cattools | ||
Revision as of 14:59, 25 August 2020
This documentation is transcluded from Module:Igenmod/doc.
This module contains the functions needed by Image generation, and other templates and modules
* {{#Invoke:Igenmod|wrkdate}} returns the <s>"creation date"</s> of a file, the value given to the date parameter, yyyy-mm-dd
* {{#Invoke:Igenmod|invdate}} returns the <s>"creation date"</s> inverted: a string 20301231 - yyyymmdd
* {{#Invoke:Igenmod|exttext}} returns the file extension uppercased
* {{#Invoke:Igenmod|extcode}} returns either "s" for SVG, "n" for anything else
* {{#Invoke:Igenmod|default}} returns either "v" for SVG, "n" for anything else
* {{#Invoke:Igenmod|unspec }} returns nothing for SVG, "n" for anything else
* {{#Invoke:Igenmod|categ }} returns either "SVG" for SVG, "PNG" for anything else
* {{#Invoke:Igenmod|split }} transcludes the template of parm2 (def: cbox) with the "/"-split values of parm1
* {{#Invoke:Igenmod|c_split}} transcludes the template of parm1 with every value of the "/"-splitting of parm2
* {{#Invoke:Igenmod|g_split}} "/"-splitting of parm1, can handle an erroneous "?" in location parms
* {{#Invoke:Igenmod|q_split}} "/"-splitting of parm1, handles named parameters (for Igen) with "~"-splitting
* {{#Invoke:Igenmod|t_split}} "/"-splitting of parm1, transcludes the 1st split of parm1 with all the other values
* {{#Invoke:Igenmod|subst }} returns the input text with eventually the first character substitited
* {{#Invoke:Igenmod|gsubst }} returns the input text with all occurrences of "/" replaced by "|"
* {{#Invoke:Igenmod|catsort}} returns gsubstet linefeeds replaced by categories
* {{#Invoke:Igenmod|dotrepl}} returns the input text with eventually the last character substitited
* {{#Invoke:Igenmod|remprf }} returns the input text with eventually a special prefix removed
elseif mw.ustring.sub (gpar[1], 1, 1) == '_' then
return ' ' .. mw.ustring.sub (gpar[1], 2 ); -- leading space
* {{#Invoke:Igenmod|inkscape}}special categorization for NEW Inkscape files - to find new violations
------------ functions in alpha:
* {{#Invoke:Igenmod|sortkey}}
* {{#Invoke:Igenmod|getdate}}
* {{#Invoke:Igenmod|sysdate}}
* {{#Invoke:Igenmod|invtest}}
* {{#Invoke:Igenmod|cattest}}
* {{#Invoke:Igenmod|newfile|10}}
* {{#Invoke:Igenmod|compare}}
local p = {}
-----------------------------------------------------------------------
-- get workdate (sometimes does not work properly)
function p.wrkdate ( )
local parse = require("Module:HTMLParser").parse
local fname = mw.title.getCurrentTitle().text
local fulln = mw.title.new(fname, 6).prefixedText
local expnd = mw.getCurrentFrame():expandTemplate{title = ':' .. fulln, {} }
local root = parse ('<html>' .. expnd:gsub('<nowiki>.*?</nowiki>', '') .. '</html>')
local tdEl = root('#fileinfotpl_date')
for td in pairs(tdEl) do
local timeElem = td.parent('time')
for te in pairs(timeElem) do
return te.attributes['datetime']
end
end
end -- end function wrkDate
-- get extension text (uppercased)
function p.exttext ( )
local page = mw.title.getCurrentTitle().text;
local ptab = mw.text.split(page , '.', true)
return mw.ustring.upper( table.concat(ptab, '', #ptab ) )
end -- end function extText
-- get extension code: "s" for SVG, else "n"
function p.extcode ( )
if p.exttext () == "SVG"
then return "s"
else return "n"
end
end -- end function extCode
-- check whether it is a new Inkscape file
function p.inkscape ( frame )
local otab = {}
if p.exttext () ~= "SVG" then
table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } );
else
local wdat = p.wrkdate () or "2020-00-00"
local sdat = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} ) or "2020-08"
if mw.ustring.sub (wdat, 1, 7) == mw.ustring.sub (sdat, 1, 7) then
local cat = "Unspec new SVG created with Inkscape"
local key = string.format ( "%.4u" , 2030 - tonumber ( string.sub ( wdat, 1, 4 )) )
key = key .. string.format ( "%.2u" , 12 - tonumber ( string.sub ( wdat, 6, 7 )) )
key = key .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9,10 )) )
table.insert(otab, frame:expandTemplate{ title = "Igen/cat", args = {cat, key } });
-- local msg = " Template [[Template:Inkscape|{{Inkscape}}]] without W3C-specification is deprecated ! "
-- table.insert(otab, frame:expandTemplate{ title = "error", args = {msg} } );
else
table.insert(otab, frame:expandTemplate{ title = "=", args = {" "} } );
table.insert(otab, frame:expandTemplate{ title = "=", args = {wdat..sdat} } );
end
end
return table.concat (otab);
end -- end function inkscape
-- invert the workdate (for a descending sortkey)
function p.invdate ()
local invt = ""
local wdat = p.wrkdate () or "2020-00-00"
invt = string.format ( "%.4u" , 2030 - tonumber ( string.sub ( wdat, 1, 4 )) )
invt = invt .. string.format ( "%.2u" , 12 - tonumber ( string.sub ( wdat, 6, 7 )) )
invt = invt .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9, 10 )) )
return invt
end -- end function invDate
-- function: changes #/*/:/; to \35/\42/\58/\59
function p.subst ( frame )
local gpar = frame.args
local char = mw.text.trim ( gpar[1] )
if mw.ustring.sub ( char, 1, 1 ) == '#' then
return '#' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == '*' then
return '*' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == ':' then
return ':' .. mw.ustring.sub( char, 2, #char );
elseif mw.ustring.sub ( char, 1, 1 ) == ';' then
return ';' .. mw.ustring.sub( char, 2, #char );
else
return char;
end
end -- end function subst
----------------------- TEST ------------------------------------------
-- check whether it is a new file
function p.newfile ( frame )
if p.exttext () ~= "SVG" then
return "n"
else
local leng = frame [1] or 7;
local wdat = p.wrkdate () or "2020-00-00"
local sdat = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )
local leng = tonumber ( frame.args[1] or 7 )
if mw.ustring.sub (wdat, 1, leng) ~= mw.ustring.sub (sdat, 1, leng)
then return "s"
else return "newcat"
end
end
end -- end function newFile
function p.cattest (args)
local categ = mw.ext.cattools
local category = args[1] or "Category:Igen/top subtemplates"
local page = args[2] or "Template:Igen/top:d"
if categ.hasPage( category, page )
then return page .. " ist in category " .. category .. " enthalten"
else return page .. " gibt es nicht in " .. category .. " !"
end
end
function p.sysdate ( )
return os.date ( )
end
function p.compare ( )
local wdat = p.wrkdate () or "2020-00-00"
local sdat = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )
return "W="..wdat ..", S="..sdat.."."
end
-----------------------------------------------------------------------
return p