模块:Dictionary/Entry.lua:修订间差异

来自「荏苒之境」
创建页面,内容为“local entry = {} entry.show = function() end return entry”
 
无编辑摘要
(未显示同一用户的10个中间版本)
第1行: 第1行:
local csv = require("Module:Csv.lua")
local dict_views = require("Module:Dictionary/Views.lua")
local dict_utils = require("Module:Dictionary/Utils.lua")
local html = mw.html
local cargo = mw.ext.cargo
local DICT_TABLE = dict_views.TABLE
local DICT_HEADER_PRIORITY = dict_utils.HEADER_PRIORITY
local entry = {}
local entry = {}


entry.show = function()
entry.show = function(frame)
end
    local args = frame.args
    local language = args.language
    local spelling = args.spelling
 
    local r = cargo.query(DICT_TABLE, "Spelling,Definition,Extra,Priority,_pageName", {
        where = string.format(
            [[Language="%s" AND (Spelling="%s" OR Priority=%d)]],
            language, spelling, DICT_HEADER_PRIORITY)
    })
   
    if #r ~= 2 then
        return "词典条目不存在:"..spelling
    end
 
    local header
    local word
 
    if r[1].Priority == DICT_HEADER_PRIORITY then
        header = r[1]
        word = r[2]
    else
        header = r[2]
        word = r[1]
    end
 
    local view = html.create('div')
        :tag('p'):wikitext(word.Definition):done()
        :tag('p'):wikitext("来源:[["..word._pageName.."]]"):done()
   
    local header_extra = csv.parse_row(header.Extra)
    local word_extra = csv.parse_row(word.Extra)
 
    for i = 1, #header_extra do
        local text = word_extra[i]
        if text ~= nil then
            local header_text = header_extra[i]
            view:tag('h2'):wikitext(header_text):done()
                :tag('p'):wikitext(text):done()
        end
    end
 
    return view
end


return entry
return entry

2025年8月5日 (二) 01:04的版本

此模块的文档可以在模块:Dictionary/Entry.lua/doc创建

local csv = require("Module:Csv.lua")
local dict_views = require("Module:Dictionary/Views.lua")
local dict_utils = require("Module:Dictionary/Utils.lua")

local html = mw.html
local cargo = mw.ext.cargo

local DICT_TABLE = dict_views.TABLE
local DICT_HEADER_PRIORITY = dict_utils.HEADER_PRIORITY

local entry = {}

entry.show = function(frame)
    local args = frame.args
    local language = args.language
    local spelling = args.spelling

    local r = cargo.query(DICT_TABLE, "Spelling,Definition,Extra,Priority,_pageName", {
        where = string.format(
            [[Language="%s" AND (Spelling="%s" OR Priority=%d)]],
            language, spelling, DICT_HEADER_PRIORITY)
    })
    
    if #r ~= 2 then
        return "词典条目不存在:"..spelling
    end

    local header
    local word

    if r[1].Priority == DICT_HEADER_PRIORITY then
        header = r[1]
        word = r[2]
    else
        header = r[2]
        word = r[1]
    end

    local view = html.create('div')
        :tag('p'):wikitext(word.Definition):done()
        :tag('p'):wikitext("来源:[["..word._pageName.."]]"):done()
    
    local header_extra = csv.parse_row(header.Extra)
    local word_extra = csv.parse_row(word.Extra)

    for i = 1, #header_extra do
        local text = word_extra[i]
        if text ~= nil then
            local header_text = header_extra[i]
            view:tag('h2'):wikitext(header_text):done()
                :tag('p'):wikitext(text):done()
        end
    end

    return view
end

return entry