gemeinsam neue Wege der Erkenntnis gehen
Eine freie Initiative von Menschen bei anthrowiki.at anthrowiki.at, anthro.world anthro.world, biodyn.wiki biodyn.wiki und steiner.wiki steiner.wiki
mit online Lesekreisen, Übungsgruppen, Vorträgen ...
Wie Sie die Entwicklung von AnthroWiki durch Ihre Spende unterstützen können, erfahren Sie hier.

Use Google Translate for a raw translation of our pages into more than 100 languages.
Please note that some mistranslations can occur due to machine translation.
Alle Banner auf einen Klick

Modul:Vorlage:Infoboxen Physik

Aus AnthroWiki

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:Infoboxen Physik/Doku erstellt werden

--[=[ 2016-11-13
{{Infobox Physikalische Einheit}}
{{Infobox Physikalische Größe}}
{{Infobox Physikalische Konstante}}
{{Infobox Physikalische Kennzahl}}
]=]



local Config = {
   E = {
      Selbst = "Infobox Physikalische Einheit",
      SI = {
         [1] = { Art = "Nicht-SI-Einheiten" ..
                       "|Zum Gebrauch mit dem SI zugelassen",
                 Kat = "Zum Gebrauch mit dem SI zugelassene Einheit" },
         [2] = { Art = "Internationales Einheitensystem",
                 Kat = "SI-Einheit" },
         [3] = { Art = "Internationales Einheitensystem",
                 Kat = "SI-Basiseinheit" }
      },
      Systeme = {
         Anglo = { Art = "Angloamerikanisches Maßsystem",
                   Kat = "Angloamerikanische Einheit" },
         CGS   = { Art = "CGS-Einheitensystem",
                   Kat = "CGS-Einheit",
                   CGS = false },
         EME   = { Art = "Elektromagnetisches CGS-Einheitensystem",
                   Kat = "CGS-Einheit",
                   CGS = true },
         ESE   = { Art = "Elektrostatisches CGS-Einheitensystem",
         	       Kat = "CGS-Einheit",
                   CGS = true },
         Gauss = { Art = "Gaußsches CGS-Einheitensystem",
         	       Kat = "CGS-Einheit",
                   CGS = true },
         HLE   = { Art = "Heaviside-Lorentz CGS-Einheitensystem",
         	       Kat = "CGS-Einheit",
                   CGS = true },
         mitSI = { SI  = 1 },
         SI    = { SI  = 2 },
         SIB   = { SI  = 3 }
      }
   },
   G = {
      Selbst = "Infobox Physikalische Größe"
   },
   K = {
      Selbst = "Infobox Physikalische Konstante"
   },
   Z = {
      Selbst = "Infobox Physikalische Kennzahl"
   },
   Selbst    = "Infoboxen Physik",
   errCatTop = "Wikipedia:Vorlagenfehler"
}
local Fun = { }



local function fehler( alert )
    local err = mw.html.create( "span" )
                       :addClass( "error" )
                       :wikitext( mw.text.nowiki( alert ) )
    local r   = tostring( err )
    if mw.title.getCurrentTitle().namespace == 0 then
        local s = Config.errCatTop
        if Config.self then
            s = string.format( "%s/%s", s, Config.self )
        end
        r = string.format( "%s[[Kategorie:%s]]", r, s )
    end
    return r
end -- fehler()



Fun.eSystem = function ( args )
    -- Einheit|System=
    --     args  -- table, with parameters
    -- Returns appropriate string
    local system = args.System or ""
    local r
    if system:match( "^%[%[" ) then
        r = system
    else
        local cnf   = Config.E
        local einh  = { }
        local kats  = { }
        local types = cnf.Systeme
        local si    = 0
        local cgs, params, typ, unknown
        system = system:gsub( "%+", " " )    -- temp / Migration
        system = system:gsub( "GB%-US", "Anglo" )    -- temp / Migration
        params = mw.text.split( system, "%s+" )
        for k, v in pairs( params ) do
            typ = types[ v ]
            if typ then
                if typ.SI then
                    if typ.SI > si then
                        si = typ.SI
                    end
                else
                    if type( typ.CGS ) == "boolean" then
                        if typ.CGS then
                            if type( cgs ) ~= "table" then
                                cgs = { }
                            end
                            table.insert( cgs, v )
                        elseif not cgs then
                            cgs = true
                        end
                    else
                        if typ.Art then
                            table.insert( einh, typ.Art )
                        end
                        if typ.Kat then
                            table.insert( kats, typ.Kat )
                        end
                    end
                end
            else
                if not unknown then
                    unknown = { }
                end
                table.insert( unknown, v )
            end
        end -- for k, v
        if unknown then
            r = fehler( "System= unbekannt: " ..
                         table.concat( unknown, " " ) )
        else
            if cgs then
                if cgs == true then
                    typ = types.CGS
                    table.insert( einh, 1, typ.Art )
                    table.insert( kats, 1, typ.Kat )
                else
                    for k, v in pairs( cgs ) do
                        typ = types[ v ]
                        table.insert( einh, 1, typ.Art )
                        if typ.Kat then
                            table.insert( kats, 1, typ.Kat )
                        end
                    end -- for k, v
                end
            end
            if si > 0 then
                typ = cnf.SI[ si ]
                table.insert( einh, 1, typ.Art )
                table.insert( kats, 1, typ.Kat )
            end
            for k, v in pairs( einh ) do
                if r then
                    r = r .. ", "
                else
                    r = ""
                end
                r = string.format( "%s[[%s]]", r, v )
            end
            if not r then    -- total mess outside
                r = fehler( "System=???????" )
            end
            for k, v in pairs( kats ) do
                r = string.format( "%s[[Kategorie:%s]]", r, v )
            end
        end
    end
    return r
end -- Fun.eSystem()


Fun.zTable = function ( args )
	--[[ makes table for quantities 
	gets input as e.g. <math>v</math> = Velocity,  <math>c</math>=Speed of light 
	returns appropriate string]]
	local tablehead="\n{|class=\"wikitable\""
	local tablecontent=string.gsub(","..args["Größentabelle"], ",%s*(.-)=%s*","\n|-\n| %1 ||")
	local tableend="\n|}"
	return tablehead..tablecontent..tableend
end --Fun.zTable


-- Export
local p = { }

p.main = function ( about, at, args )
    -- Invocation
    --     about  -- string, "E", "G", "K"
    --     at     -- string, parameter name
    --     args   -- table, with template parameters
    -- Returns appropriate string
    local r = Config[ about ]
    if r then
        local s = at or "?"
        if r.Selbst then
            Config.self = string.format( "Vorlage:%s", r.Selbst )
        end
        s = about:lower() .. s
        if type( Fun[ s ] ) == "function" then
            r = Fun[ s ]( args or { } )
        else
            r = fehler( "Unbekannte Funktion: " .. s )
        end
    else
        r = about or "?"
        r = fehler( "Unbekannter Vorlagentyp: " .. r )
    end
    return r
end -- p.main()



p.f = function ( frame )
    local lucky, r
    Config.frame = frame
    lucky, r = pcall( p.main, frame.args[ 1 ], frame.args[ 2 ],
                              frame:getParent().args )
    if not lucky then
        r = fehler( r )
    end
    return r
end -- p.f()

return p