模块:Dictionary/Vocabulary.lua:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第42行: | 第42行: | ||
local content = args.content | local content = args.content | ||
local rows | local rows | ||
if format == "csv" then | if format == "csv" then | ||
rows = csv.parse(content | rows = csv.parse(content) | ||
else | else | ||
mw.addWarning("无效的词典格式:"..tostring(format)) | mw.addWarning("无效的词典格式:"..tostring(format)) | ||
return | return | ||
end | end | ||
for i = 1, #rows do | for i = 1, #rows do | ||
第66行: | 第57行: | ||
entry[header[j]] = row[j] | entry[header[j]] = row[j] | ||
end | end | ||
cargo.store( | cargo.store("Dictionary", entry) | ||
end | end | ||
2025年8月2日 (六) 03:13的版本
此模块的文档可以在模块:Dictionary/Vocabulary.lua/doc创建
local csv = require("Module:Csv.lua")
local cargo = mw.ext.cargo
local html = mw.html
local section = {}
local function render(language, header, rows)
local view = html.create("div")
:attr("id", "dictionary_"..language)
:node(html.create("div")
:attr("class", "dictionary-header")
:node(html.create("h2"):wikitext("词典:"..language))
:node(html.create("p"):wikitext("本页面包含的词汇如下:")))
local words = view:tag("table")
local word_header = words:tag("tr")
for i = 1, #header do
word_header:node(html.create("th"):wikitext(header[i]))
end
for i = 1, #rows do
local row = rows[i]
local word_row = words:tag("tr")
for j = 1, #row do
local td = word_row:tag("td")
if j == 1 then
td:node(html.create("b"):wikitext(row[j]))
else
td:wikitext(row[j])
end
end
end
return view
end
section.show = function(frame)
local args = frame.args
local language = args.language
local format = args.format
local content = args.content
local rows
if format == "csv" then
rows = csv.parse(content)
else
mw.addWarning("无效的词典格式:"..tostring(format))
return
end
for i = 1, #rows do
local entry = {}
local row = rows[i]
for j = 1, #row do
entry[header[j]] = row[j]
end
cargo.store("Dictionary", entry)
end
return render(language, header, rows)
end
return section