From WikiChip
Difference between revisions of "Module:chip"

Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
 +
function p.add_file_prefix(str)
 +
  if string.match(string.lower(str), '^file:') then
 +
    return str
 +
  else
 +
    return 'File:' .. str
 +
  end
 +
end
 +
 
function p.chip(frame)
 
function p.chip(frame)
 
     local infobox = mw.html.create('table')
 
     local infobox = mw.html.create('table')
Line 6: Line 15:
 
         :attr('class', 'chip-infobox')
 
         :attr('class', 'chip-infobox')
  
 +
        -- header
 
         :tag('tr')
 
         :tag('tr')
 
           :tag('td')
 
           :tag('td')
 
             :attr('class', 'chip-infobox-header')
 
             :attr('class', 'chip-infobox-header')
 
             :attr('colspan', '2')
 
             :attr('colspan', '2')
             :wikitext(frame.args.title)
+
             :wikitext('[[name::' .. frame.args.title .. ']]')
 +
 
 +
        -- image
 +
        :tag('tr')
 +
          :tag('td')
 +
            :attr('class', 'chip-infobox-pic')
 +
            :attr('colspan', '2')
 +
            :wikitext(add_file_prefix(frame.args.image))
 +
 
  
 
     return infobox
 
     return infobox
 
end
 
end
 +
 
return p
 
return p

Revision as of 17:25, 3 January 2017

To add this template, simple add
{{chip}}
to the page and save. The chip infobox will have a small [Edit Values] button at the top-right corner which can be used to add values using a form.
local p = {}

function p.add_file_prefix(str)
  if string.match(string.lower(str), '^file:') then
    return str
  else
    return 'File:' .. str
  end
end

function p.chip(frame)
    local infobox = mw.html.create('table')

    infobox
        :attr('class', 'chip-infobox')

        -- header
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-header')
            :attr('colspan', '2')
            :wikitext('[[name::' .. frame.args.title .. ']]')

        -- image
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-pic')
            :attr('colspan', '2')
            :wikitext(add_file_prefix(frame.args.image))


    return infobox
end

return p