Jump to content

ମଡ୍ୟୁଲ:Separated entries

ଉଇକିପିଡ଼ିଆରୁ

Usage[ସମ୍ପାଦନା]

Module:Separated entriesserves as a template front-end tomw.text.listToText.It takesany numberof positional parameters andpieces them togetherwith|separator=.|conjunction=can be optionally defined if a different separator is desired between the last and second last items. Leading and trailing whitespace is stripped; if the|separator=should contain spaces, use the HTML escape code .Separated entries does not raise any errors by design.

{{#invoke:Separated entries|main|separator=...}}



-- This module takes positional parameters as input and concatenates them with
-- an optional separator. The final separator (the "conjunction" ) can be
-- specified independently, enabling natural-language lists like
-- "foo, bar, baz and qux". The starting parameter can also be specified.

localcompressSparseArray=require('Module:TableTools').compressSparseArray
localp={}

functionp._main(args)
localseparator=args.separator
-- Decode (convert to Unicode) HTML escape sequences, such as " " for space.
andmw.text.decode(args.separator)or''
localconjunction=args.conjunctionandmw.text.decode(args.conjunction)orseparator
-- Discard values before the starting parameter.
localstart=tonumber(args.start)
ifstartthen
fori=1,start-1doargs[i]=nilend
end
-- Discard named parameters.
localvalues=compressSparseArray(args)
returnmw.text.listToText(values,separator,conjunction)
end

localfunctionmakeInvokeFunction(separator,conjunction,first)
returnfunction(frame)
localargs=require('Module:Arguments').getArgs(frame)
args.separator=separatororargs.separator
args.conjunction=conjunctionorargs.conjunction
args.first=firstorargs.first
returnp._main(args)
end
end

p.main=makeInvokeFunction()
p.br=makeInvokeFunction('<br />')
p.comma=makeInvokeFunction(mw.message.new('comma-separator'):plain())

returnp