Jump to content
Wikimedia Meta-Wiki

Module:Separated entries

From Meta, a Wikimedia project coordination wiki
Module documentation
You might want to create a documentation page for this Scribunto module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Please add categories to the /doc subpage. Subpages of this module.
 -- 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

 localfunctionlocalize(message,lang)
 iftype(message)=='table'andtype(message.inLanguage)=='function'then
 iftype(lang)=='string'andlang~=''then
 message=message:inLanguage(lang)
 end
 returnmessage:plain()
 else
 returnmessage
 end
 end

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

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

 returnp

AltStyle によって変換されたページ (->オリジナル) /