From WikiChip
Module:chip
Revision as of 20:38, 3 January 2017 by David (talk | contribs)

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.add_separator(title)
  return mw.html.create('tr')
           :tag('td')
           :attr('class', 'chip-infobox-sep')
           :attr('colspan', '2')
           :wikitext(title)
end

function p.add_entry(value, right)
  return mw.html.create('tr')
           :tag('td')
           :attr('class', 'chip-infobox-entry')
           :wikitext(value)
           :node(right)
end

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

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

    -- header
    if frame.args.title then
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-header')
            :attr('colspan', '2')
            :wikitext('[[name::' .. frame.args.title .. ']]')
    else
      infobox
        :tag('tr')
          :tag('td')
          :attr('style', 'font-weight: bold; font-size 2.5em; color: red;')
          :wikitext('ERROR: MISSING TITLE!')
    end

    -- image
    if frame.args.image or frame.args.no_image ~= 'true' then
      local image = frame.args.image and p.add_file_prefix(frame.args.image) or "File:no photo (ic).svg"
      local image_size = frame.args.image_size or "200px" 
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'chip-infobox-pic')
            :attr('colspan', '2')
            :wikitext('[[image::' .. image .. '| ]][[' .. image .. '|' .. image_size .. ']]')

      -- add a caption, if provided
      if frame.args.caption then
        infobox
          :tag('tr')
            :tag('td')
              :attr('class', 'chip-infobox-pic-caption')
              :attr('colspan', '2')
              :wikitext('[[image capation::' .. frame.args.caption .. ']]')
      end
    end

    -- some general info first
    infobox:node(p.add_separator('General Info'))
    
    -- designer
    if frame.args.designer then
      local designers = mw.html.create('td'):wikitext(frame.args.designer)
      for i = 2, 10 do
      	if not frame.args['designer ' .. i] then break end
      	designers:wikitext(',<br>[[designer::' .. frame.args['designer ' .. i] .. ']][[category:microprocessor models by ' .. mw.language.lc(frame.args['designer ' .. i]) .. ']]')
      end
   	  infobox:node(p.add_entry('Designer', designers))
	end

    return infobox
end

return p