Module:User:Manuela/sandbox
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
This module is an interface for the template {{Location}}.
You can enter the coordinates in one stream e.g. 48° 24′ 55,84″ N 16° 38′ 16,61″ E or as two parameters 48° 24′ 55,84″ N| 16° 38′ 16,61″ E. If you omit the hemisphere letters (default: N and E), then you must enter two parameters otherwise you will get an incorrect result.
The seconds can be entered with comma or dot (or without any of it), comma will be converted to dot.
Examples:
{{#invoke:User:Manuela/sandbox|coords|48° 24′ 55,84″ N 16° 38′ 16 E}}
{{#invoke:User:Manuela/sandbox|coords|48° 24′ 55,84″ N|16° 38′ 16″ E}}
{{#invoke:User:Manuela/sandbox|coords|48heremightevenbeanyarbitraytextwithoutwhitespace 24 55.84|16° 38′ 16″ E}}
Code
local p = {} -- p stands for package
function p.alpha(frame)
-- erzeugt eine Liste mit alphabetisch sortierten Links zu Seiten mit einem bestimmten Anfangsbuchstaben
-- man kann entweder den Namensraum als Text oder als Nummer angeben
-- ns: Namensraum, z.B. MediaWiki oder Modul
-- nn: Namensraumnummer, hat Nachrang gegenüber ns
-- die Variable a enthält alle Parameter, die im #invoke: Statement stehen
-- die Variable b enthält die Parameter, die an die Vorlage übergeben werden, die das #invoke: Statement aufruft
-- z.B. die Vorlage {{Scheme}} ruft cats mit dem Parameter Scheme auf:
-- {{#invoke:Hili|cats|Scheme}} frame.args enthält i=1, v=Scheme
-- {{Scheme|Grobs}} frame:getParent().args i=1, v=Grobs
local a = frame.args -- direkt per #invoke: übergeben
local b = frame:getParent().args -- an die Vorlage übergebene Parameter
local _ = ""
local ns = a.ns or b.ns -- Namespace
local nn = a.nn or b.nn or 0 -- Namespace Number
ns = ns or frame:preprocess( "{{ns:" .. nn .. "}}" )
local was = a.link or b.link or "[[Special:Prefixindex/"
local i
local bet = { "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }
_ = was .. ns .. ":" .. "a|A]]"
for i=1,#bet do
_ = _ .. " · " .. was .. ns .. ":" .. bet[i] .. "|" .. bet[i]:upper() .. "]]"
end
return _
end
function p.coords (frame)
-- trying to interprate the parameters as input for template:location
local parm1 = frame.args[1]
local parm2 = frame.args[2]
if not parm1 or parm1 == '' then return '' end -- no parameter at all
deg, min, sec, hem, dege, mine, sece, heme = unpack( mw.text.split(parm1, "[%s]+") )
if not deg or deg == '' then return '' end -- parameter degree missing, no sense at all
deg, min, sec, hem = deg:match('%d+'), min:match('%d+') or '0', string.gsub(string.match(sec, '%d+[,.]*%d*') or '0', ',','.'), hem or 'N'
if parm2 and parm2 ~= '' then -- two Parameters
dege, mine, sece, heme = unpack( mw.text.split(parm2, "[%s]+") )
end
dege, mine, sece, heme = dege:match('%d+'), mine:match('%d+') or '0', string.gsub(string.match(sece, '%d+[,.]*%d*') or '0', ',','.'), heme or 'E'
if not dege or dege == '' then return '' end -- parameter degree missing, no sense at all
return frame:expandTemplate{ title = "Location", args = { deg, min, sec, hem, dege, mine, sece, heme } }
end
return p