Module:qualifier: Difference between revisions

From Linguifex
Jump to navigation Jump to search
(Created page with "local export = {} function export.format_qualifier(list) if type(list) ~= "table" then list = { list } end if #list == 0 then return '' end return '<span class="i...")
 
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
local export = {}
local export = {}


function export.format_qualifier(list)
local concat = table.concat
 
function export.wrap_css(text, classes)
return ("<i class=\"%s\">%s</i>"):format(classes, text)
end
 
function export.wrap_qualifier_css(text, suffix)
local css_classes = ("ib-%s qualifier-%s"):format(suffix, suffix)
return export.wrap_css(text, css_classes)
end
 
function export.format_qualifiers(list, open, close, opencontent, closecontent, no_ib_content)
if type(list) ~= "table" then
if type(list) ~= "table" then
list = { list }
list = {list}
end
end
 
if #list == 0 then
if not list[1] then
return ''
return ""
end
end


return '<span class="ib-brac qualifier-brac">(</span>' ..
local parts = {}
      '<span class="ib-content qualifier-content">' ..
local function ins(text)
      table.concat(list, '<span class="ib-comma qualifier-comma">,</span> ') ..
table.insert(parts, text)
  '</span><span class="ib-brac qualifier-brac">)</span>'
end
end


function export.qualifier_t(frame)
if open ~= false then
local params = {
ins(export.wrap_qualifier_css(open or "(", "brac"))
  [1] = {list = true, required = true},
end
}
if opencontent then
ins(opencontent)
local args = require("Module:parameters").process(frame:getParent().args, params)
end
local content = concat(list, export.wrap_qualifier_css(",", "comma") .. " ")
local subvarieties = mw.loadData("Module:qualifier/subvarieties")
if not no_ib_content then
content = export.wrap_qualifier_css(content, "content")
for i, label in ipairs(args[1]) do
if subvarieties[label] then
require("Module:debug").track("qualifier/subvarieties")
--[[
currently not working:
local lang = subvarieties[label].languages[1]
require("Module:debug").track("qualifier/subvarieties/" .. lang)
]]
end
end
end
ins(content)
if closecontent then
ins(closecontent)
end
if close ~= false then
ins(export.wrap_qualifier_css(close or ")", "brac"))
end
return concat(parts)
end


return export.format_qualifier(args[1])
function export.format_qualifier(list, open, close, opencontent, closecontent, no_ib_content)
return export.format_qualifiers(list, open, close, opencontent, closecontent, no_ib_content)
end
end


function export.sense(list)
local function format_qualifiers_with_clarification(list, clarification, open, close)
return export.format_qualifier(list)
local opencontent = export.wrap_css(clarification, "qualifier-clarification") ..
.. '<span class="ib-colon sense-qualifier-colon">:</span>'
export.wrap_css(open or "“", "qualifier-clarification qualifier-quote")
 
local closecontent = export.wrap_css(close or "”", "qualifier-clarification qualifier-quote")
 
return export.format_qualifiers(list, "(", ")", opencontent, closecontent)
end
end


function export.sense_t(frame)
function export.sense(list)
local params = {
return export.format_qualifiers(list) .. export.wrap_css(":", "ib-colon sense-qualifier-colon")
  [1] = {list = true, required = true},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return export.sense(args[1])
end
end


function export.gloss_t(frame)
function export.antsense(list)
local params = {
return format_qualifiers_with_clarification(list, "antonym(s) of ") ..
  [1] = {required = true},
export.wrap_css(":", "ib-colon sense-qualifier-colon")
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return '<span class="gloss-brac">(</span><span class="gloss-content">' ..
args[1] .. '</span><span class="gloss-brac">)</span>'
end
end


function export.non_gloss_definition_t(frame)
local params = {
  [1] = {required = true},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return '<span class="use-with-mention">' .. require("Module:links").english_links(args[1]) .. '</span>'
end
return export
return export

Latest revision as of 15:04, 7 August 2024



local export = {}

local concat = table.concat

function export.wrap_css(text, classes)
	return ("<i class=\"%s\">%s</i>"):format(classes, text)
end

function export.wrap_qualifier_css(text, suffix)
	local css_classes = ("ib-%s qualifier-%s"):format(suffix, suffix)
	return export.wrap_css(text, css_classes)
end

function export.format_qualifiers(list, open, close, opencontent, closecontent, no_ib_content)
	if type(list) ~= "table" then
		list = {list}
	end

	if not list[1] then
		return ""
	end

	local parts = {}
	local function ins(text)
		table.insert(parts, text)
	end

	if open ~= false then
		ins(export.wrap_qualifier_css(open or "(", "brac"))
	end
	if opencontent then
		ins(opencontent)
	end
	local content = concat(list, export.wrap_qualifier_css(",", "comma") .. " ")
	if not no_ib_content then
		content = export.wrap_qualifier_css(content, "content")
	end
	ins(content)
	if closecontent then
		ins(closecontent)
	end
	if close ~= false then
		ins(export.wrap_qualifier_css(close or ")", "brac"))
	end
	return concat(parts)
end

function export.format_qualifier(list, open, close, opencontent, closecontent, no_ib_content)
	return export.format_qualifiers(list, open, close, opencontent, closecontent, no_ib_content)
end

local function format_qualifiers_with_clarification(list, clarification, open, close)
	local opencontent = export.wrap_css(clarification, "qualifier-clarification") ..
		export.wrap_css(open or "“", "qualifier-clarification qualifier-quote")

	local closecontent = export.wrap_css(close or "”", "qualifier-clarification qualifier-quote")

	return export.format_qualifiers(list, "(", ")", opencontent, closecontent)
end

function export.sense(list)
	return export.format_qualifiers(list) .. export.wrap_css(":", "ib-colon sense-qualifier-colon")
end

function export.antsense(list)
	return format_qualifiers_with_clarification(list, "antonym(s) of ") ..
		export.wrap_css(":", "ib-colon sense-qualifier-colon")
end

return export