Module:grc-utilities/templates

Hello, you have come here looking for the meaning of the word Module:grc-utilities/templates. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:grc-utilities/templates, but we will also tell you about its etymology, its characteristics and you will know how to say Module:grc-utilities/templates in singular and plural. Everything you need to know about the word Module:grc-utilities/templates you have here. The definition of the word Module:grc-utilities/templates will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:grc-utilities/templates, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local m_table = require('Module:table')
local m_utils = require('Module:grc-utilities')
local m_data = require('Module:grc-utilities/data')
local tag = m_utils.tag
local link = m_utils.link
local tokenize = m_utils.tokenize
local diacritic = m_data.diacritic

local U = mw.ustring.char
local toNFD = mw.ustring.toNFD
local gsub = mw.ustring.gsub

local dottedCircle = U(0x25CC)

export.addDottedCircle = require("Module:Unicode data").add_dotted_circle

function export.printTokens(frame)
	text = frame.args
	local token_format = '<span class="Polyt" style="background-color: #E9E9E9;>%s</span>'
	local spacing = {
		 = "&para;",
		 = "&para;",
		 = "&ensp;",
	}
	
	if text then
		local tokens = m_table.shallowCopy(tokenize(text))
		for i, token in pairs(tokens) do
			tokens = token_format:format(string.gsub(token, "%s", spacing))
		end
		return "|-\n| " .. tag(text) .. " || " .. tag(table.concat(tokens, ", "))
	else
		error("Provide text to tokenize in first parameter.")
	end
end

function export.printDiacritics(frame)
	local functionToPrint = frame.args or error('Specify a function in the first parameter.')
	local term = frame.args or error('Add text in the second parameter.')
	
	local result = m_utils(term)
	
	-- Show diacritics above or below a dotted circle.
	content = {
		term = tag(term),
		term_decomposition = tag(export.addDottedCircle(toNFD(term))),
		result = tag(result),
		result_decomposition = tag(export.addDottedCircle(result)),
	}
	
	local output = ]
	
	local function addContent(item)
		return content or ""
	end
	
	return (output:gsub("+", addContent))
end

function export.decompose(frame)
	local params = {
		 = {},
		 = { type = "boolean" },
	}
	
	args = require("Module:parameters").process(frame.args, params)
	
	local text = args
	text = toNFD(text)
	local link = args.link
	local composed
	
	if link then
		composed = link(text, nil, nil, "-")
	else
		composed = tag(text)
	end
	
	local decomposed = export.addDottedCircle(text)
	
	if link then
		local result = {}
		for seat, letter in gmatch(decomposed, "(" .. dottedCircle .. "?)(.)") do
			local link
			if letter then
				link = linkNoTag(letter, seat .. letter)
			end
			
			table.insert(result, link)
		end
		decomposed = table.concat(result)
	end
	
	decomposed = tag(decomposed)
	
	return composed .. " (" .. decomposed .. ")"
end

function export.tokenize(frame)
	local map = require("Module:fun").map
	local token_format = '<span class="Polyt" style="background-color: #EFEFEF;>%s</span>'
	local spacing = {
		 = "&para;",
		 = "&para;",
		 = "&ensp;",
	}
	local _tokenize = tokenize
	local function tokenize(word, ...)
		return _tokenize(word)
	end
	local function print_tokens(tokens)
		if type(tokens) == "string" then
			return tokens
		end
		local output = {}
		for i, token in ipairs(tokens) do
			output = string.format(token_format, string.gsub(token, "%s", spacing))
		end
		return table.concat(output, " ")
	end
	return table.concat(map(print_tokens, map(tokenize, frame.args)), "<br>")
end

return export