From WikiChip
Module:gpu
Revision as of 00:26, 9 July 2017 by ChipIt (talk | contribs) (Created page with "local p = {} local origArgs function p.add_file_prefix(str) if string.match(string.lower(str), '^file:') then return str else return 'File:' .. str end end fun...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To add this template, simple add
{{gpu}}
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 = {}
local origArgs

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(box, title)
  box:tag('tr')
           :tag('td')
           :attr('class', 'header')
           :attr('colspan', '2')
           :wikitext(title)
end

function p.add_entry(value, right)
  local e = mw.html.create('tr')
  e:tag('td')
    :attr('class', 'label')
    :wikitext(value)
  e:node(right)
  return e   
end

function has_arg(name)
	-- The argument can exist and be empty or not exist at all
	return string.len(origArgs[name] or '') > 0
end

function arg(name)
	return origArgs[name]
end

function p.chip(frame)
	
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame.args
    end
	
	
    local infobox = mw.html.create('table')

    infobox
        :attr('class', 'infobox')
        
    infobox
    	:tag('tr')
			:tag('td'):attr('colspan', '2')
			:tag('small'):attr('style', 'float: right;')
            :wikitext('[[Special:FormEdit/gpu/' .. frame:preprocess('{{FULLPAGENAME}}') .. '|<i class="fa fa-edit"></i>Edit Values]]')
            
    -- header
    if has_arg('name') then
      infobox
        :tag('tr')
          :tag('td')
            :attr('class', 'header-main')
            :attr('colspan', '2')
            :wikitext('[[name::' .. arg('name') .. ']]')
    end
    
	-- type
	if has_arg('type') then
		if arg('type') == 'integrated' then
	  		infobox:node(p.add_entry('Type', mw.html.create('td'):wikitext('[[instance of::integrated graphics processor| ]] IGP')))
    		infobox:wikitext('[[Category:integrated graphics processor models]]')
		end
		if arg('type') == 'discrete' then
	  		infobox:node(p.add_entry('Type', mw.html.create('td'):wikitext('[[instance of::discrete graphics processor| ]] DGP')))
    		infobox:wikitext('[[Category:discrete graphics processor models]]')
		end
	end
    
    infobox:wikitext('[[full page name::' .. frame:preprocess('{{FULLPAGENAME}}') .. '| ]]')
    
    if has_arg('future') and
    	(string.lower(arg('future')) == 'yes' or string.lower(arg('future')) == 'true') then
    	infobox:wikitext('[[Category:future microprocessor models]][[ldate::3000| ]]')
	elseif has_arg('first launched') then
    	infobox:wikitext('[[ldate::' .. arg('first launched') .. '| ]]')
	elseif has_arg('first announced') then
    	infobox:wikitext('[[ldate::' .. arg('first announced') .. '| ]]')
	else --alright launched but no date?
    	infobox:wikitext('[[ldate::1000| ]]')
    end
	
    return infobox
end

return p