Dota 2 Wiki
mNo edit summary
No edit summary
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 
local color = require('Module:Color')._main
 
local color = require('Module:Color')._main
local get_args = require('Module:Arguments').main
+
local getArgs = require('Module:Arguments').getArgs
 
local default = {
 
local defaults = {
 
 
['title-textcolor'] = 'white',
 
['title-textcolor'] = 'white',
 
['title-bgcolor'] = color({'wiki1'}),
 
['title-bgcolor'] = color({'wiki1'}),
Line 12: Line 11:
   
   
function p.main()
+
function p.main(frame)
local args = get_args()
+
local args = getArgs(frame, {
  +
wrappers = { 'Template:Infobox' },
return p._main(args)
 
  +
trim = false
  +
})
 
return p._main(args)
 
end
 
end
   
 
function p._main(args)
 
function p._main(args)
-- Add the default values to the arguments.
 
setmetatable(args, { __index = defaults })
 
 
 
local infobox = mw.html.create('table')
 
local infobox = mw.html.create('table')
 
:addClass('infobox')
 
:addClass('infobox')
Line 28: Line 27:
 
:tag('th')
 
:tag('th')
 
:attr('colspan', 2)
 
:attr('colspan', 2)
:css('background-color', args['title-bgcolor'])
+
:css('background', args['title-bgcolor'] or default['title-bgcolor'])
 
:css('text-align', 'center')
 
:css('text-align', 'center')
:css('color', args['title-textcolor'])
+
:css('color', args['title-textcolor'] or default['title-textcolor'])
 
:css('font-weight', 'bold')
 
:css('font-weight', 'bold')
 
:wikitext(args['title'])
 
:wikitext(args['title'])
Line 42: Line 41:
 
:tag('td')
 
:tag('td')
 
:attr('colspan', 2)
 
:attr('colspan', 2)
:wikitext(string.format('[[File:%s|%s]]', args['image'], args['image-size']))
+
:wikitext(string.format('[[File:%s|%s]]', args['image'], args['image-size'] or default['image-size']))
 
:done()
 
:done()
 
:done()
 
:done()
Line 56: Line 55:
 
:tag('td')
 
:tag('td')
 
:attr('colspan', 2)
 
:attr('colspan', 2)
:css('background-color', args['heading-bgcolor'])
+
:css('background', args['heading-bgcolor'] or default['heading-bgcolor'])
 
:css('text-align', 'center')
 
:css('text-align', 'center')
:css('color', args['heading-textcolor'])
+
:css('color', args['heading-textcolor'] or default['heading-textcolor'])
 
:css('font-weight', 'bold')
 
:css('font-weight', 'bold')
 
:wikitext(args['heading' .. i])
 
:wikitext(args['heading' .. i])
Line 66: Line 65:
 
end
 
end
   
if args["trait" .. i] == 'fullwidth' and args['value' .. i] then
+
if mw.text.trim(args["trait" .. i]) == 'fullwidth' and args['value' .. i] then
 
infobox
 
infobox
 
:tag('tr')
 
:tag('tr')
Line 80: Line 79:
 
:tag('tr')
 
:tag('tr')
 
:tag('th')
 
:tag('th')
:css('width', '50%')
+
:css('text-align', 'right')
:css('text-align', 'center')
 
 
:wikitext(args['trait' .. i] .. ':')
 
:wikitext(args['trait' .. i] .. ':')
 
:done()
 
:done()
 
:tag('td')
 
:tag('td')
:css('width', '50%')
 
 
:wikitext(args['value' .. i])
 
:wikitext(args['value' .. i])
 
:done()
 
:done()

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