Fiji Hindi editions of Wiki, an online encyclopedia

Documentation for this module may be created at Module:List/doc

-- This module outputs different kinds of lists. At the moment, bulleted,-- unbulleted, horizontal, ordered, and horizontal ordered lists are supported.local libUtil = require('libraryUtil')local checkType = libUtil.checkTypelocal mTableTools = require('Module:TableTools')local p = {}local listTypes = {['bulleted'] = true,['unbulleted'] = true,['horizontal'] = true,['ordered'] = true,['horizontal_ordered'] = true}function p.makeListData(listType, args)-- Constructs a data table to be passed to p.renderList.local data = {}-- Classesdata.classes = {}if listType == 'horizontal' or listType == 'horizontal_ordered' thentable.insert(data.classes, 'hlist')elseif listType == 'unbulleted' thentable.insert(data.classes, 'plainlist')endtable.insert(data.classes, args.class)-- Main div = Indent for horizontal listsif listType == 'horizontal' or listType == 'horizontal_ordered' thenlocal indent = tonumber(args.indent)indent = indent and indent * 1.6 or 0if indent > 0 thendata.marginLeft = indent .. 'em'endend-- List style types for ordered lists-- This could be "1, 2, 3", "a, b, c", or a number of others. The list style-- type is either set by the "type" attribute or the "list-style-type" CSS-- property.if listType == 'ordered' or listType == 'horizontal_ordered' then data.listStyleType = args.list_style_type or args['list-style-type']data.type = args['type']-- Detect invalid type attributes and attempt to convert them to-- list-style-type CSS properties.if data.type and not data.listStyleTypeand not tostring(data.type):find('^%s*[1AaIi]%s*$')thendata.listStyleType = data.typedata.type = nilendend-- List tag typeif listType == 'ordered' or listType == 'horizontal_ordered' thendata.listTag = 'ol'elsedata.listTag = 'ul'end-- Start number for ordered listsdata.start = args.startif listType == 'horizontal_ordered' then-- Apply fix to get start numbers working with horizontal ordered lists.local startNum = tonumber(data.start)if startNum thendata.counterReset = 'listitem ' .. tostring(startNum - 1)endend-- List style -- ul_style and ol_style are included for backwards compatibility. No -- distinction is made for ordered or unordered = args.list_style-- List items-- li_style is included for backwards compatibility. item_style was included-- to be easier to understand for = args.item_style or args.li_styledata.items = {}for i, num in ipairs(mTableTools.numKeys(args)) dolocal item = {}item.content = args[num] = args['item' .. tostring(num) .. '_style']or args['item_style' .. tostring(num)]item.value = args['item' .. tostring(num) .. '_value']or args['item_value' .. tostring(num)]table.insert(data.items, item)endreturn dataendfunction p.renderList(data)-- Renders the list HTML.-- Return the blank string if there are no list items.if type(data.items) ~= 'table' or #data.items < 1 thenreturn ''end-- Render the main div tag.local root = mw.html.create('div')for i, class in ipairs(data.classes or {}) doroot:addClass(class)endroot:css{['margin-left'] = data.marginLeft}if thenroot:cssText( Render the list tag.local list = root:tag(data.listTag or 'ul')list:attr{start = data.start, type = data.type}:css{['counter-reset'] = data.counterReset,['list-style-type'] = data.listStyleType}if data.listStyle thenlist:cssText(data.listStyle)end-- Render the list itemsfor i, t in ipairs(data.items or {}) dolocal item = list:tag('li')if data.itemStyle thenitem:cssText(data.itemStyle)endif thenitem:cssText({value = t.value}:wikitext(t.content)endreturn tostring(root)endfunction p.renderTrackingCategories(args)local isDeprecated = false -- Tracks deprecated parameters.for k, v in pairs(args) dok = tostring(k)if k:find('^item_style%d+$') or k:find('^item_value%d+$') thenisDeprecated = truebreakendendlocal ret = ''if isDeprecated thenret = ret .. '[[Category:List templates with deprecated parameters]]'endreturn retendfunction p.makeList(listType, args)if not listType or not listTypes[listType] thenerror(string.format("bad argument #1 to 'makeList' ('%s' is not a valid list type)",tostring(listType)), 2)endcheckType('makeList', 2, args, 'table')local data = p.makeListData(listType, args)local list = p.renderList(data)local trackingCategories = p.renderTrackingCategories(args)return list .. trackingCategoriesendfor listType in pairs(listTypes) dop[listType] = function (frame)local mArguments = require('Module:Arguments')local origArgs = mArguments.getArgs(frame)-- Copy all the arguments to a new table, for faster indexing.local args = {}for k, v in pairs(origArgs) doargs[k] = vendreturn p.makeList(listType, args)endendreturn p

This article uses material from the Wikipedia article Module:List, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply. (view authors). Content is available under CC BY-SA 3.0 unless otherwise noted. Images, videos and audio are available under their respective licenses.
#Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. Wiki ( is an independent company and has no affiliation with Wikimedia Foundation.