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

来自「荏苒之境」
无编辑摘要
无编辑摘要
 
(未显示同一用户的11个中间版本)
第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 html = mw.html
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


local dict_views = require("Module:Dictionary-Views.lua")
local DICT_TABLE = dict_views.TABLE
local DICT_TABLE = dict_views.TABLE
local DICT_HEADER_PRIORITY = tostring(dict_utils.HEADER_PRIORITY)


local entry = {}
local entry = {}
第12行: 第16行:
     local spelling = args.spelling
     local spelling = args.spelling


     local r = cargo.query(DICT_TABLE, "Definition,Category,Etymology,_pageName", {
     local rows = cargo.query(DICT_TABLE, "Spelling,Definition,Extra,Priority,_pageName", {
         where = string.format(
         where = string.format(
             [[Language="%s" AND Spelling="%s"]],
             [[Language="%s" AND (Spelling="%s" OR Priority=%s)]],
             language, spelling, tonumber(args.priority))
             language, spelling, DICT_HEADER_PRIORITY)
     })[1]
     })


     if r == nil then
     local header
        return "词典条目不存在:"..spelling
    local word
    end
   
    for i = 1, #rows do
    local row = rows[i]
    if row.Priority == DICT_HEADER_PRIORITY then
        header = row
    elseif row.Spelling == spelling then
    word = row
    end
end
if header == nil then
error("词典标题行不存在!")
elseif word == nil then
return "词条不存在:"..spelling
end


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


     if r.Category ~= nil and r.Category ~= "" then
     for i = 1, #header_extra do
         view:tag('h2'):wikitext('类别'):done()
        local text = word_extra[i]
            :tag('p'):wikitext(r.Category):done()
         if text ~= nil then
    end
            local header_text = header_extra[i]
    if r.Etymology ~= nil and r.Etymology ~= "" then
            view:tag('h2'):wikitext(header_text):done()
        view:tag('h2'):wikitext('词源'):done()
                :tag('p'):wikitext(text):done()
            :tag('p'):wikitext(r.Etymology):done()
        end
     end
     end



2025年8月5日 (二) 04:46的最新版本

此模块的文档可以在模块: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 = tostring(dict_utils.HEADER_PRIORITY)

local entry = {}

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

    local rows = cargo.query(DICT_TABLE, "Spelling,Definition,Extra,Priority,_pageName", {
        where = string.format(
            [[Language="%s" AND (Spelling="%s" OR Priority=%s)]],
            language, spelling, DICT_HEADER_PRIORITY)
    })

    local header
    local word
    
    for i = 1, #rows do
    	local row = rows[i]
    	if row.Priority == DICT_HEADER_PRIORITY then
	        header = row
	    elseif row.Spelling == spelling then
	    	word = row
	    end
	end
	
	if header == nil then
		error("词典标题行不存在!")
	elseif word == nil then
		return "词条不存在:"..spelling
	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