Dokumentation för denna modul finns på /dok (redigera), /test
Modulens syfte är att generera wikitabellkod som ska användas som byggstenar i grammatiktabeller. Med hjälp av modulen kan grammatikmoduler skapa grammatiktabeller på ett mer läsbart och överskådligt sätt.
local gt = require("Modul:grammar-table") local lang_code = "sv" local part_of_speech = "adj" local number_of_columns = 3 local has_warning = "false" local str = gt.getStart(number_of_columns, lang_code, part_of_speech, has_warning) .. gt.getRow({"!", "Rubrik"}, "böjningsform") .. gt.getRow({"!", "Rubrik"}, "böjningsform") .. gt.getEnd(number_of_columns, "Kommentar", "förled")
!
, |
, |class="min"
, |rowspan="2"
, |class="min" colspan="3"
<span class="infl">]</span>
20 tests failed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
mut.getRow({"!", "rubrik", '|rowspan="2"'}, "form1", "form2", "form3") | |-
!|rubrik |rowspan="2"|<span class="infl">[]</span> ||<span class="infl">[]</span> ||<span class="infl">[]</span> || |- !|rubrik |rowspan="2"|<span data-grammar-link="infl">[]</span> ||<span data-grammar-link="infl">[]</span> ||<span data-grammar-link="infl">[]</span> | ||
mut.getRow({"|", "], ]", type="adv"}, "], ]") | |-
||<span class="adv">[]</span>, <span class="adv">[]</span> ||<span class="infl">[]</span>, <span class="infl">[]</span> || |- ||<span data-grammar-link="adv">[]</span>, <span data-grammar-link="adv">[]</span> ||<span data-grammar-link="infl">[]</span>, <span data-grammar-link="infl">[]</span> | ||
mut.getRow("form1, form2") | |-
||<span class="infl">[]</span>, <span class="infl">[]</span> || |- ||<span data-grammar-link="infl">[]</span>, <span data-grammar-link="infl">[]</span> |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow("form1", "form2", "form3") | |-
||<span class="infl">[]</span> ||<span class="infl">[]</span> ||<span class="infl">[]</span> || |- ||<span data-grammar-link="infl">[]</span> ||<span data-grammar-link="infl">[]</span> ||<span data-grammar-link="infl">[]</span> |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow({"!"}, {"|rowspan=2"}, {'|class="min"'}) | |-
!| |rowspan="2"| [[Kategori:Wiktionary:Sidor med tomma celler]] |class="min"| [[Kategori:Wiktionary:Sidor med tomma celler]] || |- !| |rowspan="2"| [[Kategori:Wiktionary:Sidor med tomma celler]] |class="min"| [[Kategori:Wiktionary:Sidor med tomma celler]] |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow({"!", type="no-link"}, {'|rowspan="2"', type="no-link"}) | |-
!| |rowspan="2"| [[Kategori:Wiktionary:Sidor med tomma celler]] || |- !| |rowspan="2"| [[Kategori:Wiktionary:Sidor med tomma celler]] |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow("], form2") | |-
||<span class="infl">[]</span>, <span class="infl">[]</span> || |- ||<span data-grammar-link="infl">[]</span>, <span data-grammar-link="infl">[]</span> | ||
mut.getRow("]<sup>1</sup>") | |-
||<span class="infl">[]</span><sup>1</sup> || |- ||<span data-grammar-link="infl">[]</span><sup>1</sup> | ||
mut.getRow("], vard. ]") | |-
||<span class="infl">[]</span>, vard. <span class="infl">[]</span> || |- ||<span data-grammar-link="infl">[]</span>, vard. <span data-grammar-link="infl">[]</span> | ||
mut.getRow("(])") | |-
||'''('''<span class="infl">[]</span>''')''' || |- ||'''('''<span data-grammar-link="infl">[]</span>''')''' | ||
mut.getRow("]") | |-
||<span class="infl">[[form1|fōrm1]]</span> || |- ||<span data-grammar-link="infl">[[form1|fōrm1]]</span> | ||
mut.getRow("<nowiki/>form1, form2") Med nowiki i modul |
|-
||<nowiki/>form1, <span class="infl">[]</span> || |- ||<nowiki/>form1, <span data-grammar-link="infl">[]</span> | ||
mut.getRow("<nowiki/>form1, form2") Med nowiki i mall |
|-
||"`UNIQ--nowiki-00000001-QINU`"'form1, <span class="infl">[]</span> || |- ||"`UNIQ--nowiki-00000001-QINU`"'form1, <span data-grammar-link="infl">[]</span> |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow("ord1 ord2") | |-
||ord1 ord2 || |- ||ord1 ord2 |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow(nil) | |- | |- | |
mut.getRow("") | |-
|| [[Kategori:Wiktionary:Sidor med tomma celler]] || |- || [[Kategori:Wiktionary:Sidor med tomma celler]] | ||
mut.getRow("-") | |-
||– || |- ||– | ||
mut.getRow("?") | |-
||? || |- ||? | ||
", type="no-link"})) | |-
|| [[Kategori:Wiktionary:Sidor med tomma celler]] || |- || [[Kategori:Wiktionary:Sidor med tomma celler]] | ||
", "", type="no-link"})) | |-
|| [[Kategori:Wiktionary:Sidor med tomma celler]] || |- || [[Kategori:Wiktionary:Sidor med tomma celler]] | ||
", "-", type="no-link"})) | |-
||– || |- ||– | ||
", "?", type="no-link"})) | |-
||? || |- ||? |
Text | Expected | Actual | |
---|---|---|---|
mut.getRow("e-post") | |-
||<span class="infl">[[e-post]]</span> || |- ||<span data-grammar-link="infl">[[e-post]]</span> | ||
mut.getRow("word's") | |-
||<span class="infl">[[word's]]</span> || |- ||<span data-grammar-link="infl">[[word's]]</span> | ||
mut.getRow("words'") | |-
||<span class="infl">[[words']]</span> || |- ||<span data-grammar-link="infl">[[words']]</span> | ||
mut.getRow("tv:n") | |-
||<span class="infl">[[tv:n]]</span> || |- ||<span data-grammar-link="infl">[[tv:n]]</span> | ||
mut.getRow("]") | |-
||<span class="infl">[[Övriga_uppslagsord#EU:s|EU:s]]</span> || |- ||<span data-grammar-link="infl">[[Övriga_uppslagsord#EU:s|EU:s]]</span> | ||
mut.getRow("'']''") | |-
||''<span class="infl">[]</span>'' || |- ||''<span data-grammar-link="infl">[]</span>'' |
Text | Expected | Actual | |
---|---|---|---|
mut.setLanguage("de") | (nil) | (nil) | |
mut.getRow({"!", "rubrik", '|rowspan="2"'}, "form1", "form2", "form3") | |-
!|rubrik |rowspan="2"|<span class="infl">[[form1#Tyska|form1]]</span> ||<span class="infl">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span> || |- !|rubrik |rowspan="2"|<span data-grammar-link="infl">[[form1#Tyska|form1]]</span> ||<span data-grammar-link="infl">[[form2#Tyska|form2]]</span> ||<span data-grammar-link="infl">[[form3#Tyska|form3]]</span> | ||
mut.getRow({"|", "], ]", type="adv"}, "], ]") | |-
||<span class="adv">[[form1#Tyska|form1]]</span>, <span class="adv">[[form2#Tyska|form2]]</span> ||<span class="infl">[[form3#Tyska|form3]]</span>, <span class="infl">[[form4#Tyska|form4]]</span> || |- ||<span data-grammar-link="adv">[[form1#Tyska|form1]]</span>, <span data-grammar-link="adv">[[form2#Tyska|form2]]</span> ||<span data-grammar-link="infl">[[form3#Tyska|form3]]</span>, <span data-grammar-link="infl">[[form4#Tyska|form4]]</span> | ||
mut.getRow("form1, form2") | |-
||<span class="infl">[[form1#Tyska|form1]]</span>, <span class="infl">[[form2#Tyska|form2]]</span> || |- ||<span data-grammar-link="infl">[[form1#Tyska|form1]]</span>, <span data-grammar-link="infl">[[form2#Tyska|form2]]</span> |
local lk = require("Modul:link")
local glk = require("Modul:grammar-link")
local export = {}
local m_lang_code
local function getStart(number_of_columns, lang_code, part_of_speech, has_warning, minimize_width)
local class = minimize_width and "grammar min" or "grammar"
local str = '{| class="' .. class .. '" data-lang="' .. lang_code .. '" data-h3="' .. part_of_speech .. '" cellspacing="0" width="10"\n'
if has_warning then
local talk_page = mw.title.getCurrentTitle().talkPageTitle.fullText
str = str .. '|class="grammar-warning min" colspan="' .. number_of_columns .. '"|Faktakoll: Innehåller ifrågasatta uppgifter. Se ].\n'
end
return str
end
function export.getStart(number_of_columns, lang_code, part_of_speech, has_warning)
return getStart(number_of_columns, lang_code, part_of_speech, has_warning, false)
end
function export.getMinimalStart(number_of_columns, lang_code, part_of_speech, has_warning)
return getStart(number_of_columns, lang_code, part_of_speech, has_warning, true)
end
function export.getHiddenStart(number_of_columns, lang_code, part_of_speech, has_warning)
return "" --not implemented
end
function export.setLanguage(lc)
m_lang_code = lc
end
function export.getRow(...)
local row = "|-\n"
local cell = {}
local default_meta = "|"
local default_type = "infl"
local has_empty_cell = false
local function makeContentNonEmpty(str)
return (type(str) ~= "string" or str == "" or str == " ") and " " or str
end
local function isHeading(meta)
return mw.ustring.sub(meta, 1, 1) == "!"
end
local function addCell()
local extended_content = ""
if isHeading(cell.meta) then
extended_content = makeContentNonEmpty(cell.content)
else
extended_content = glk.link(cell.content, cell.type, m_lang_code)
if extended_content == " " then
has_empty_cell = true
extended_content = extended_content .. "]"
end
end
row = row .. cell.meta .. "|" .. extended_content .. "\n"
end
local arg = {...} -- this allows for the correct rendering when using more recent lua engines (post 5.0)
for _,v in pairs(arg) do
if type(v) == "table" then
cell.meta = v
cell.content = v
cell.type = v or default_type
addCell()
elseif type(v) == "string" then
cell.meta = default_meta
cell.content = v
cell.type = default_type
addCell()
end
end
return row
end
function export.getEnd(number_of_columns, note, as_first_part)
local str = ""
local note_exists = note ~= "-"
if as_first_part then
str = str .. '|-\n!colspan="' .. number_of_columns .. '" class="min"|' .. "''Som förled i sammansättningar används " .. (lk.isValidLinkTarget(as_first_part) and "'''" .. as_first_part .. "-'''" or as_first_part) .. "''.\n"
end
if note_exists then
str = str .. '|-\n|colspan="' .. number_of_columns .. '" class="note"|' .. "<div><table><tr><th>Not:</th><td>" .. note .. "</td></tr></table></div>\n"
end
str = str .. '|}'
return str
end
return export