Module:form of/functions: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
--[=[ | --[=[ | ||
DISPLAY_HANDLERS is a list of one or more functions that provide special | DISPLAY_HANDLERS is a list of one or more functions that provide special handling for multipart tags. Each function | ||
handling for multipart tags. Each function takes formerly a single argument | takes formerly a single argument (the multipart tag), now temporarily two arguments (the multipart tag and the join | ||
(the multipart tag), now temporarily two arguments (the multipart tag and | strategy, which can be nil to use the default), and should either return the formatted display text or nil to check the | ||
the join strategy, which can be nil to use the default), and should either | next handler. If no handlers apply, there is a default handler that appropriately formats most multipart tags. | ||
return the formatted display text or nil to check the next handler. If no | |||
handlers apply, there is a default handler that appropriately formats most | |||
multipart tags. | |||
CAT_FUNCTIONS is a map from function names to functions of a single argument, | CAT_FUNCTIONS is a map from function names to functions of a single argument, as described in [[Module:form of/cats]]. | ||
as described in [[Module:form of/cats]]. There are two types of functions: | There are two types of functions: condition handlers (which return true or false) and spec handlers (which return a | ||
condition handlers (which return true or false) and spec handlers (which | specification, as described in [[Module:form of/cats]]). We need to put the functions here rather than in | ||
return a specification, as described in [[Module:form of/cats]]). We need to | [[Module:form of/cats]] because that module is loaded using mw.loadData(), which can't directly handle functions. | ||
put the functions here rather than in [[Module:form of/cats]] because that | |||
module is loaded using mw.loadData(), which can't directly handle functions. | |||
]=] | ]=] | ||
| Line 27: | Line 22: | ||
local function wrap_in_inflection_of_sep(text) | local function wrap_in_inflection_of_sep(text) | ||
return '<span>' .. text .. '</span>' | return '<span class="inflection-of-sep">' .. text .. '</span>' | ||
end | end | ||
| Line 42: | Line 37: | ||
return seq[1] .. wrap_in_inflection_of_sep(" and ") .. seq[2] | return seq[1] .. wrap_in_inflection_of_sep(" and ") .. seq[2] | ||
else | else | ||
local comma = '<span>,</span>' | local comma = '<span class="serial-comma">,</span>' | ||
local conj = '<span> and </span>' | local conj = '<span class="serial-and"> and </span>' | ||
return table.concat(seq, wrap_in_inflection_of_sep(", "), 1, length - 1) .. | return table.concat(seq, wrap_in_inflection_of_sep(", "), 1, length - 1) .. | ||
wrap_in_inflection_of_sep(comma .. conj) .. seq[length] | wrap_in_inflection_of_sep(comma .. conj) .. seq[length] | ||
| Line 72: | Line 67: | ||
error("Unrecognized multipart join strategy: " .. strategy) | error("Unrecognized multipart join strategy: " .. strategy) | ||
end | end | ||
return '<span>' .. retval .. '</span>' | return '<span class="inflection-of-conjoined">' .. retval .. '</span>' | ||
end | end | ||
| Line 93: | Line 88: | ||
strategy == "and" and "-]]" or "]]" | strategy == "and" and "-]]" or "]]" | ||
if tag == "first-person" then | if tag == "first-person" then | ||
table.insert(els, "[[Appendix:Glossary#first person|first" .. suffix) | table.insert(els, "[[wikt:Appendix:Glossary#first person|first" .. suffix) | ||
elseif tag == "second-person" then | elseif tag == "second-person" then | ||
table.insert(els, "[[Appendix:Glossary#second person|second" .. suffix) | table.insert(els, "[[wikt:Appendix:Glossary#second person|second" .. suffix) | ||
elseif tag == "third-person" then | elseif tag == "third-person" then | ||
table.insert(els, "[[Appendix:Glossary#third person|third" .. suffix) | table.insert(els, "[[wikt:Appendix:Glossary#third person|third" .. suffix) | ||
else | else | ||
return nil | return nil | ||
| Line 107: | Line 102: | ||
return export | return export | ||