Module:MOS scalesig: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local getArgs = require("Module:Arguments").getArgs
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs
local p = {}
-- Preprocess unparsed scalesig; if it's raw text, then it's a scalesig to be
-- parsed into a mos; if it's a mos as defined by the mos module, return it.
function p.preprocess_unparsed_scalesig(unparsed)
if unparsed.nL ~= nil and unparsed.ns ~= nil and unparsed.equave ~= nil then
return unparsed
else
return mos.parse(unparsed)
end
end
-- Function to format a string into a mos scalesig, with nonbreaking spaces.
-- Options are:
-- - is_long - Whether to use "xL ys<p/q>" or "xL ys (p/q-equivalent)". Only
--  applies for nonoctave mosses, as a scalesig without an equave is assumed to
--  be 2/1-equivalent.
-- - is_link - Whether the scalesig is a link to its wiki page.
-- NOTE: args are passed in individually rather than as a table as expected use
-- includes formatting scalesig text/links for other mos-related modules.
function p._mos_scalesig(unparsed, is_link, is_long)
local input_mos = p.preprocess_unparsed_scalesig(unparsed)
local is_link = yesno(is_link, false)
local is_long = yesno(is_long, false)
-- Link is the article name, if to be used
-- Text is the parsed scalesig
local link = mos.as_long_string(input_mos)
local text = is_long and mos.as_long_string(input_mos) or mos.as_string(input_mos)
if is_link then
if link == text then
return string.format("[[%s]]", link)
else
return string.format("[[%s | %s]]", link, text)
end
else
return text
end
end


-- Wrapper function for use with a template
-- Wrapper function; calls mos module's to-string and to-link functions
function p.mos_scalesig(frame)
function p.mos_scalesig(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local unparsed = args["name"]
local input_mos = mos.parse(args["scalesig"])
local is_link = yesno(args["link"], false)
local is_link = yesno(args["link"], false)
local is_long = yesno(args["long"], false)
local is_long = yesno(args["long"], false)
local result
return p._mos_scalesig(unparsed, is_link, is_long)
if is_link then
end
-- Text is a link to the mospage
 
-- Long link links to and displays "xL ys (p/q-equivalent)"
function p.tester()
-- (Short) link instead displays "xL ys<p/q>"
local input_mos = mos.new(5,2)
-- Has no effect if it's octave-equivalent.
return p._mos_scalesig(input_mos, true, true)
result = (is_long and mos.as_long_link(input_mos) or mos.as_link(input_mos))
else
-- Text is the scalesig, with nbsp and appropriate brackets added
-- Long string displays "xL ys (p/q-equivalent)"
-- (Short) string instead displays "xL ys<p/q>"
-- Has no effect if it's octave-equivalent.
result = (is_long and mos.as_long_string(input_mos) or mos.as_string(input_mos))
end
return frame:preprocess(result)
end
end


return p
return p