Modul:Hiero/Cell

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:Hiero/Cell/Doku erstellt werden

local p = {}
local Cell = {}
-- order of special names part 1: by type, variable number of values
Cell.order1 = {
  "Horus",
  "Seth",
  "HorusSeth",
  "Nebti",
  "Thron",
  "Eigen"
}
-- order of listed Pharaohs: by row and column in primary source, one value each
Cell.order2 = {
  "Turin",
  "Sethos1",
  "Ramses2",
  "Sakkara"
}
-- list of  king lists
Cell.kingLoL = {
  Turin = {},
  Sethos1 = {{}},
  Ramses2 = {{}},
  Sakkara={{}}
}

local _, Parser = pcall(require, "Modul:SimpleStruct")
local _, Cartouche = pcall(require, "Modul:Hiero/Cartouche")
local trace = ''

local function pre(frame, code)
  return frame:preprocess('<hiero>' .. code .. '</hiero>')
end

-- Wiki
-- annotation cells for lists not for template use
Cell.Wiki = function(frame, content, span)
  if type(span) == 'number' then
    return '<td rowspan="' .. span .. '">' .. frame:preprocess(content) .. '</td>'
  end
  if span == 'col' then
    return '<td colspan="2">' .. frame:preprocess(content) .. '</td>'
  end
  return '<td>' .. frame:preprocess(content) .. '</td>'
end

p.Wiki = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.Wiki</td>'  
end

-- simple
-- hieros given in code
Cell.simple = function(frame, code)
  return '| class="hiero" | ' .. pre(frame, code)
end

function p.simple(frame)
  local hieros = frame.args[1] or ''
  return Cell.simple(frame, hieros)
end

-- name
-- hiero code + cartouche kind, symbol and border
Cell.name = function(frame, kind, code, symbol, border, colspan)
  assert(type(Cartouche) == 'table', '404 Module fehlen / missing (Hiero/Cartouche)')
  local result = Cartouche.name(frame, kind, code, symbol, border)
  mw.log(result)
  if colspan == 2 then return '<td class="hiero" colspan="2">' .. result .. '</td>' end
  return '<td class="hiero">' .. result .. '</td>'
end

function p.name(frame)
  -- mw.logObject(frame.args, 'args')
  local styles = frame.args.styles or ''
  return Cell.name(frame,
    frame.args.kind, frame.args.code, frame.args.symbol, frame.args.border,
    styles)
end

--spacedWiki
-- spaced cells for lists not for template use
Cell.spacedWiki = function(frame, content, span)
  local core = Cell.Wiki(frame, content, 1)
  if type(span) == 'number' and span > 1 then
    return core .. '<td rowspan="' .. span .. '"></td>'
  end
  return core .. '<td></td>'
end

p.spacedWiki = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.spacedWiki</td>'  
end

--spacedSimple
-- spaced cells for lists not for template use
Cell.spacedSimple = function(frame, code, span)
  if type(span) == 'number' and span > 1 then
    return Cell.simple(frame, code) .. '<td rowspan="' .. span .. '"></td>'
  end
  return Cell.simple(frame, code) .. '<td></td>'
end

p.spacedSimple = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.spacedSimple</td>'  
end

--spacedName
-- spaced cells for lists not for template use
Cell.spacedName = function(frame, kind, code, symbol, border, span)
  local core = Cell.name(frame, kind, code, symbol, border, 1)
  if type(span) == 'number' and span > 1 then
    return core .. '<td rowspan="' .. span .. '"></td>'
  end
  return core .. '<td></td>'
end

--annotatededWiki
-- spaced cells for lists not for template use
Cell.annotatededWiki = function(frame, content, content2, span)
  if type(span) == 'number' and span > 1 then
    return Cell.Wiki(frame, content, 1) .. Cell.Wiki(frame, content2, span)
  end
  return Cell.Wiki(frame, content, 1) .. Cell.Wiki(frame, content2, 1)
end

p.annotatededWiki = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.annotatededWiki</td>'  
end

--annotatedSimple
-- spaced cells for lists not for template use
Cell.annotatedSimple = function(frame, code, content, span)
  if type(span) == 'number' and span > 1 then
    return Cell.simple(frame, code) .. Cell.Wiki(frame, content, span)
  end
  return Cell.simple(frame, code) .. Cell.Wiki(frame, content, 1)
end

p.annotatedSimple = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.annotatedSimple</td>'  
end

--annotatedName
-- spaced cells for lists not for template use
Cell.annotatedName = function(frame, kind, code, symbol, border, content, span)
  local core = Cell.name(frame, kind, code, symbol, border, 1)
  if type(span) == 'number' and span > 1 then
    return core .. Cell.Wiki(frame, content2, span)
  end
  return core .. Cell.Wiki(frame, content2, 1)
end

p.annotatedName = function(frame)
  return '<td style="text-decoration:line-through">Hiero/Cell.annotatedName</td>'  
end

-- list
-- add valid data only
local function tdRow(nameType, tdTable, key, value, funct)
  if tdTable[value] == nil then
    return '<td>Cell.list.' .. nameType .. '.' .. key ..
           '.' .. value .. '={???}</td></tr><tr>'
  else
    return funct .. '</tr><tr>'
  end
end

-- list allready parsed contents without order into order
Cell.list = function(frame, content, language)
  assert(type(Cartouche) == 'table', 'Cell.list: -Cartouche')
  local result = '<tr>'
  -- order first part
  for i, v in Cell.order1 do
    local typeStruct = content[v]
    if type(typeStruct) == 'table' then
      -- name definition of type v found
      local title = Cartouche.Title(v, language)
      wm.log(title)
      wm.logTable(typeStruct)
      local count = 0
      local typeContent = ""
      for n, w in typeStruct do
        -- col 2 element found
        count = count + 1
        if type(w) == 'table' then
          if n == 'Wiki' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'Wikitext',
                 Cell.Wiki(frame, w.Wikitext, w.colspan))
          elseif n == 'simple' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.simple(frame, w.code))
          elseif n == 'name' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.name(frame, v, w.code, w.symbol, w.border, w.colspan))
          elseif n == 'spacedSimple' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.spacedSimple(frame, w.code, w.rowspan))
          elseif n == 'spacedName' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.spacedName(frame, v, w.code, w.symbol, w.border, w.rowspan))
          elseif n == 'annotatedSimple' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.annotatedSimple(frame, w.code, w.Wikitext, w.rowspan))
          elseif n == 'name' then
            typeContent = typeContent ..
              tdRow(v, w, n, 'code',
                 Cell.spacedName(frame, v, w.code, w.symbol,
                                 w.border, w.Wikitext, w.rowspan))
          end
        else
          typeContent = typeContent .. '<td>Cell.list.' ..
                        v .. '.' .. n .. '={???}</td>'
        end
      end
      if count < 1 then
        result = result .. '<td colspan="2">' .. v .. '{???}</td>'
      elseif count == 1 then
        result = result .. '<td>' .. title .. '</td>' .. typeContent
      else
        result = result .. '<td colspan="' .. count .. '">' ..
                 title .. '</td>' .. typeContent
      end
    end
  end
  -- add seccond part
  --2b done
  -- return alltogether
  return result .. '</tr>'
end

function p.list(frame)
  if frame.args[1] == nil then return '' end
  if frame.args[1] == '' then return '' end
  assert(type(Parser) == 'table', ' Parser: ' .. type(Parser))
  return Cell.list(frame, Parser.parse(frame.args[1]), frame.args[2])
 end

return p