Dota 2 Wiki
mNo edit summary
No edit summary
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local getArgs = require( 'Module:Arguments' ).main
 
local color = require('Module:Color')._main
 
 
local p = {}
 
local p = {}
 
local color = require('Module:Color')._main
 
local getArgs = require('Module:Arguments').getArgs
 
local default = {
 
['title-textcolor'] = 'white',
 
['title-bgcolor'] = color({'wiki1'}),
 
['heading-textcolor'] = 'black',
 
['heading-bgcolor'] = '#EADCDA',
 
['image-size'] = '256px',
  +
}
   
  +
function p.main( frame )
+
function p.main(frame)
local args = getArgs()
+
local args = getArgs(frame, {
return p._main( args )
 
  +
wrappers = { 'Template:Infobox' },
  +
trim = false
  +
})
 
return p._main(args)
 
end
 
end
   
function p._main( args )
+
function p._main(args)
  +
local infobox = mw.html.create('table')
local title_textcolor = args["title-textcolor"] or 'white'
 
  +
:addClass('infobox')
local title_background = args["title-bgcolor"] or color( {'wiki1'} )
 
  +
:newline()
local heading_textcolor = args["heading-textcolor"] or 'black'
 
  +
-- Add the infobox title.
local heading_background = args["heading-bgcolor"] or '#EADCDA'
 
  +
:tag('tr')
 
  +
:tag('th')
local infobox = '{| class="infobox"\n| colspan="2" style="text-align:center; color:' .. title_textcolor .. '; background-color:' .. title_background .. ';" | <span style="font-weight:bold;">' .. args["title"] .. '</span>\n|-\n| colspan="2" style="text-align:center;"|\n|-\n'
 
  +
:attr('colspan', 2)
 
  +
:css('background', args['title-bgcolor'] or default['title-bgcolor'])
if args["image"] then
 
  +
:css('text-align', 'center')
local image_size = args["image-size"] or '256px'
 
  +
:css('color', args['title-textcolor'] or default['title-textcolor'])
infobox = infobox .. '| colspan="2" | [[File:' .. args["image"] .. '|center|' .. image_size .. ']]\n|-\n'
 
  +
:css('font-weight', 'bold')
end
 
  +
:wikitext(args['title'])
 
  +
:done()
local n = 1
 
  +
:done()
while args["trait" .. n] do
 
  +
:newline()
if args["heading" .. n] then
 
infobox = infobox .. '| colspan="2" style="text-align:center; color:' .. heading_textcolor .. '; background-color:' .. heading_background .. '" | <span style="font-weight:bold;">' .. args["heading" .. n] .. '</span>\n|-\n'
 
end
 
 
if args["trait" .. n] == 'fullwidth' then
 
if args["value" .. n] then
 
local style = args["stylevalue" .. n] or 'text-align:center;'
 
infobox = infobox .. '| colspan="2" style="' .. style .. '" | ' .. args["value" .. n] .. '\n|-\n'
 
end
 
else
 
if args["value" .. n] then
 
infobox = infobox .. '!' .. args['trait' .. n] .. ':\n| ' .. args["value" .. n] .. '\n|-\n'
 
end
 
end
 
 
n = n + 1
 
end
 
   
 
if args['image'] then
infobox = infobox .. '|}'
 
 
infobox
 
  +
:tag('tr')
return infobox
 
  +
:tag('td')
  +
:attr('colspan', 2)
  +
:wikitext(string.format('[[File:%s|%s]]', args['image'], args['image-size'] or default['image-size']))
  +
:done()
  +
:done()
  +
:newline()
 
end
  +
  +
local i = 1
 
while args['trait' .. i] do
  +
-- Insert headings if necessary.
 
if args['heading' .. i] then
  +
infobox
  +
:tag('tr')
  +
:tag('td')
  +
:attr('colspan', 2)
  +
:css('background', args['heading-bgcolor'] or default['heading-bgcolor'])
  +
:css('text-align', 'center')
  +
:css('color', args['heading-textcolor'] or default['heading-textcolor'])
  +
:css('font-weight', 'bold')
  +
:wikitext(args['heading' .. i])
  +
:done()
  +
:done()
  +
:newline()
 
end
  +
 
if mw.text.trim(args["trait" .. i]) == 'fullwidth' and args['value' .. i] then
  +
infobox
  +
:tag('tr')
  +
:tag('td')
  +
:attr('colspan', 2)
 
:cssText(args['stylevalue' .. i] or 'text-align: center;')
  +
:wikitext(args['value' .. i])
  +
:done()
  +
:done()
  +
:newline()
 
elseif args['value' .. i] then
  +
infobox
  +
:tag('tr')
  +
:tag('th')
  +
:css('text-align', 'right')
  +
:wikitext(args['trait' .. i] .. ':')
  +
:done()
  +
:tag('td')
  +
:wikitext(args['value' .. i])
  +
:done()
  +
:done()
  +
:newline()
 
end
  +
 
i = i + 1
 
end
  +
  +
return infobox
 
end
 
end
  +
   
 
return p
 
return p

Revision as of 01:38, 1 December 2018

Documentation for Module:Infobox Jump to code ↴ [ edit | purge ]

Reality Rift icon
▶️ Planeshift.
The documentation for this module can be found at Template:Infobox.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

local p = {}
local color = require('Module:Color')._main
local getArgs = require('Module:Arguments').getArgs
local default = {
  ['title-textcolor'] = 'white',
  ['title-bgcolor'] = color({'wiki1'}),
  ['heading-textcolor'] = 'black',
  ['heading-bgcolor'] = '#EADCDA',
  ['image-size'] = '256px',
}


function p.main(frame)
  local args = getArgs(frame, {
    wrappers = { 'Template:Infobox' },
    trim = false
  })
  return p._main(args)
end

function p._main(args)
  local infobox = mw.html.create('table')
    :addClass('infobox')
    :newline()
    -- Add the infobox title.
    :tag('tr')
      :tag('th')
        :attr('colspan', 2)
        :css('background', args['title-bgcolor'] or default['title-bgcolor'])
        :css('text-align', 'center')
        :css('color', args['title-textcolor'] or default['title-textcolor'])
        :css('font-weight', 'bold')
        :wikitext(args['title'])
        :done()
      :done()
    :newline()

  if args['image'] then
    infobox
      :tag('tr')
        :tag('td')
          :attr('colspan', 2)
          :wikitext(string.format('[[File:%s|%s]]', args['image'], args['image-size'] or default['image-size']))
          :done()
        :done()
      :newline()
  end

  local i = 1
  while args['trait' .. i] do
    -- Insert headings if necessary.
    if args['heading' .. i] then
      infobox
        :tag('tr')
          :tag('td')
            :attr('colspan', 2)
            :css('background', args['heading-bgcolor'] or default['heading-bgcolor'])
            :css('text-align', 'center')
            :css('color', args['heading-textcolor'] or default['heading-textcolor'])
            :css('font-weight', 'bold')
            :wikitext(args['heading' .. i])
            :done()
          :done()
        :newline()
    end

    if mw.text.trim(args["trait" .. i]) == 'fullwidth' and args['value' .. i] then
      infobox
        :tag('tr')
          :tag('td')
            :attr('colspan', 2)
            :cssText(args['stylevalue' .. i] or 'text-align: center;')
            :wikitext(args['value' .. i])
            :done()
          :done()
        :newline()
    elseif args['value' .. i] then
      infobox
        :tag('tr')
          :tag('th')
            :css('text-align', 'right')
            :wikitext(args['trait' .. i] .. ':')
            :done()
          :tag('td')
            :wikitext(args['value' .. i])
            :done()
          :done()  
        :newline()  
    end
    
    i = i + 1
  end

  return infobox
end


return p