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:Igenmod: Difference between revisions

From Neodyland Wiki
m corr
m +function
Line 53: Line 53:
end
end
end -- end function newFile
end -- end function newFile
-- return the workdate
function p.wrkdate ()
return workdat ()
end -- end function wrkDate




Line 62: Line 68:
invt = invt .. string.format ( "%.2u" , 12 - tonumber ( string.sub ( wdat, 6, 7 )) )
invt = invt .. string.format ( "%.2u" , 12 - tonumber ( string.sub ( wdat, 6, 7 )) )
invt = invt .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9, 10 )) )
invt = invt .. string.format ( "%.2u" , 31 - tonumber ( string.sub ( wdat, 9, 10 )) )
return invt .. wdat
return invt
end -- end function invDate
end -- end function invDate



Revision as of 10:08, 25 August 2020

Module documentation[ view · edit · history · purge ]
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 = {}
-----------------------------------------------------------------------
local function workdat ( )
	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 local function workDat

-----------------------------------------------------------------------

-- get extension text (lowercased) 
function p.exttext ( )
	local page = mw.title.getCurrentTitle().text;
	local ptab = mw.text.split(page , '.', true)
	local extd = mw.ustring.lower( table.concat(ptab, '', #ptab  ) )
	return extd
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 file
function p.newfile ( frame )
	if p.exttext () ~= "svg" then
		return "n"
	else 
		local leng = frame [1] or 7;
		local wdat = workdat ()
		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


-- return the workdate 
function p.wrkdate ()
	return workdat ()
end -- end function wrkDate


-- invert the workdate (for a descending sortkey)
function p.invdate ()
	local invt = ""
	local wdat = workdat ()	
	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 '&#35;' .. mw.ustring.sub( char, 2, #char );
	elseif	mw.ustring.sub ( char, 1, 1 ) == '*' then 
		return '&#42;' .. mw.ustring.sub( char, 2, #char );
	elseif	mw.ustring.sub ( char, 1, 1 ) == ':' then 
		return '&#58;' .. mw.ustring.sub( char, 2, #char );
	elseif	mw.ustring.sub ( char, 1, 1 ) == ';' then 
		return '&#59;' .. mw.ustring.sub( char, 2, #char );
	else
		return char;
	end
end -- end function subst


----------------------- TEST ------------------------------------------
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 = workdat()
	local sdat = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )
	return "W="..wdat ..",  S="..sdat.."."
end

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