PlaycityMap installer (토론 | 기여)님의 2025년 12월 19일 (금) 16:58 판 (Install PlaycityMap module)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
분류:

이 모듈에 대한 설명문서는 모듈:PlaycityMap/설명문서에서 만들 수 있습니다

local p = {}

local function normalizeArg(value)
  if value == nil then
    return nil
  end
  local text = tostring(value)
  if text == "" then
    return nil
  end
  return text
end

local function buildTagAttributes(args)
  local attrs = {}
  local base = normalizeArg(args.base)
  if base then
    attrs.base = base
  end
  if normalizeArg(args.mode) then
    attrs.mode = args.mode
  end
  if normalizeArg(args.x) then
    attrs.x = args.x
  end
  if normalizeArg(args.z) then
    attrs.z = args.z
  end
  if normalizeArg(args.center) then
    attrs.center = args.center
  end
  if normalizeArg(args.zoom) then
    attrs.zoom = args.zoom
  end
  local controlValue = normalizeArg(args.control) or normalizeArg(args.controls) or normalizeArg(args.interactive)
  if controlValue then
    attrs.control = controlValue
  end
  if normalizeArg(args.marker) then
    attrs.marker = args.marker
  end
  if normalizeArg(args.hash) then
    attrs.hash = args.hash
  end
  attrs.width = normalizeArg(args.width) or "100%"
  attrs.height = normalizeArg(args.height) or "420"
  attrs.loading = normalizeArg(args.loading) or "lazy"
  attrs.referrerpolicy = normalizeArg(args.referrerpolicy) or "no-referrer-when-downgrade"
  return attrs
end

function p.embed(frame)
  local args = (frame.getParent and frame:getParent() or frame).args or {}
  local tag = mw.html.create("playcitymap")
  local attrs = buildTagAttributes(args)
  for key, value in pairs(attrs) do
    tag:attr(key, value)
  end
  return tostring(tag)
end

return p

분류