From WikiChip
Difference between revisions of "Module:package"

(Set package properties.)
 
Line 84: Line 84:
 
     -- some general info first
 
     -- some general info first
 
     p.add_separator(infobox, 'General Info')
 
     p.add_separator(infobox, 'General Info')
      
+
 
    -- designer
+
     local function entry(a)
 +
        local label, arg_name = unpack(a)
 +
        if not has_arg(arg_name) then return end
 +
        local function text(i, value)
 +
            local prop_name = a.prop_name or arg_name -- {} for none
 +
            if type(prop_name) == 'table' then
 +
                if i > #prop_name then
 +
                    if a.print then return a.print(value) end
 +
                    return value
 +
                end
 +
                prop_name = prop_name[i]
 +
            end
 +
            return '[[' .. prop_name .. '::' .. value ..
 +
                (a.print and ('| ]]' .. a.print(value)) or ']]')
 +
        end
 +
        local td = mw.html.create('td'):wikitext(text(1, arg(arg_name)))
 +
        for i = 2, (a.max_args or 1) do
 +
            local value = origArgs[arg_name .. ' ' .. i]
 +
            if not value or value == '' then break end
 +
            td:wikitext((a.sep or ', ') .. text(i, value))
 +
        end
 +
        if label then infobox:node(p.add_entry(label, td)) end
 +
        return td
 +
    end
 +
    local function link(s) return '[[' .. mw.ustring.lower(s) .. '|' .. s .. ']]' end
 +
 
 +
    local uarch_link
 
     if has_arg('designer') then
 
     if has_arg('designer') then
      local designers = mw.html.create('td'):attr('style', 'width: 99%;')
+
        uarch_link = function(s) return '[[' .. mw.ustring.lower(arg('designer') ..
      designers:wikitext('[[designer::' .. arg('designer') .. '| ]][[' .. arg('designer') .. ']]')
+
            '/microarchitectures/' .. s) .. '|' .. s .. ']]' end
for i = 2, 10 do
+
        local td = entry{nil, 'designer', max_args=10, print=link}
if not has_arg('designer ' .. i) then break end
+
        infobox:node(p.add_entry('Designer', td:attr('style', 'width: 99%;')))
designers:wikitext(', [[designer::' .. arg('designer ' .. i) .. '| ]][[' .. arg('designer ' .. i) .. ']]')
+
    end
end
+
 
    infobox:node(p.add_entry('Designer', designers))
+
    if has_arg('first launched') or has_arg('first announced') then
end
+
        local release, sep = mw.html.create('td'), ''
+
        if has_arg('first announced') then
-- release date
+
            release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
if has_arg('first launched') or has_arg('first announced') then
+
            sep = '<br/>'
  local release = mw.html.create('td')
+
        end
  if has_arg('first announced') then
+
        if has_arg('first launched') then
    release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
+
            release:wikitext(sep .. '[[first launched::' .. arg('first launched') .. ']] (launched)')
  end
+
        end
  if has_arg('first launched') then
+
        infobox:node(p.add_entry('Introduction', release))
  if has_arg('first announced') then
+
    end
    release:wikitext('<br>')
+
 
  end
+
     entry{'Market', 'market', max_args=5, prop_name='market segment'}
    release:wikitext('[[first launched::' .. arg('first launched') .. ']] (launched)')
+
    entry{'Microarchitecture', 'microarch', max_args=10,
  end
+
         prop_name='microarchitecture', print=uarch_link}
  infobox:node(p.add_entry('Introduction', release))
+
     entry{'Chipset', 'chipset', max_args=10}
end
+
    entry{'<abbr title="Thermal Design Power">TDP</abbr>', 'tdp', max_args=10}
+
 
-- market segment
 
     if has_arg('market') then
 
p.set_val('market segment', arg('market'))
 
      local markets = mw.html.create('td'):wikitext(arg('market'))
 
      for i = 2, 5 do
 
  if not has_arg('market ' .. i) then break end
 
p.set_val('market segment', arg('market ' .. i))
 
      markets:wikitext(', ' .. arg('market ' .. i))
 
      end
 
    infobox:node(p.add_entry('Market', markets))
 
end
 
 
-- microarch
 
    if has_arg('microarch') then
 
      local microarchs = mw.html.create('td')
 
      p.set_val('microarchitecture', arg('microarch'))
 
      microarchs:wikitext('[[' .. mw.ustring.lower(arg('designer')) .. '/microarchitectures/' ..
 
      mw.ustring.lower(arg('microarch')) .. '|' .. arg('microarch') .. ']]')
 
      for i = 2, 10 do
 
      if not has_arg('microarch ' .. i) then break end
 
      p.set_val('microarchitecture', arg('microarch ' .. i))
 
         microarchs:wikitext(', [[' .. mw.ustring.lower(arg('designer')) .. '/microarchitectures/' ..
 
      mw.ustring.lower(arg('microarch ' .. i)) .. '|' .. arg('microarch ' .. i) .. ']]')
 
      end
 
    infobox:node(p.add_entry('Microarchitecture', microarchs))
 
end
 
 
-- chipset
 
     if has_arg('chipset') then
 
p.set_val('chipset', arg('chipset'))
 
local chipset = mw.html.create('td'):wikitext(arg('chipset'))
 
for i = 2, 10 do
 
if not has_arg('chipset ' .. i) then break end
 
p.set_val('chipset', arg('chipset ' .. i))
 
chipset:wikitext(', ' .. arg('chipset ' .. i))
 
      end
 
infobox:node(p.add_entry('Chipset', chipset))
 
end
 
 
 
-- tdp
 
if has_arg('tdp') then
 
p.set_val('tdp', arg('tdp'))
 
local tdp = mw.html.create('td'):wikitext(arg('tdp'))
 
for i = 2, 10 do
 
  if not has_arg('tdp ' .. i) then break end
 
p.set_val('tdp', arg('tdp ' .. i))
 
  tdp:wikitext(', ' .. arg('tdp ' .. i))
 
end
 
  infobox:node(p.add_entry('<abbr title="Thermal Design Power">TDP</abbr>', tdp))
 
end
 
 
    -- ####################################################################
 
    -- package info
 
   
 
 
     if has_arg('package name') or has_arg('package type') then
 
     if has_arg('package name') or has_arg('package type') then
    p.add_separator(infobox, 'Package')
+
        p.add_separator(infobox, 'Package')
 +
        entry{'Name', 'package name', max_args=10, prop_name='package', sep=',<br/>'}
 +
        entry{'Type', 'package type'}
 +
        entry{'Contacts', 'package contacts'}
 +
        entry{'Dimension', 'package dimension', max_args=3, sep=' × ',
 +
            prop_name={'package length', 'package width', 'package height'}}
 +
        entry{'Pitch', 'package pitch', max_args=2, sep=' × '}
 
     end
 
     end
   
+
 
-- package
 
if has_arg('package name') then
 
local package_name =  mw.html.create('td'):wikitext(arg('package name'))
 
for i = 2, 10 do
 
  if not has_arg('package name ' .. i) then break end
 
  package_name:wikitext(',<br> ' .. arg('package name ' .. i))
 
end
 
  infobox:node(p.add_entry('Name', package_name))
 
end
 
 
-- type
 
if has_arg('package type') then
 
  infobox:node(p.add_entry('Type', mw.html.create('td'):wikitext( arg('package type'))))
 
end
 
 
-- contacts
 
if has_arg('package contacts') then
 
  infobox:node(p.add_entry('Contacts', mw.html.create('td'):wikitext( arg('package contacts'))))
 
end
 
 
-- dimension
 
    if has_arg('package dimension') then
 
      local dimension = mw.html.create('td'):wikitext(arg('package dimension'))
 
      for i = 2, 10 do
 
      if not has_arg('package dimension ' .. i) then break end
 
      dimension:wikitext(' × ' .. arg('package dimension ' .. i))
 
      end
 
    infobox:node(p.add_entry('Dimension', dimension))
 
end
 
 
-- pitch
 
if has_arg('package pitch') then
 
  infobox:node(p.add_entry('Pitch', mw.html.create('td'):wikitext( arg('package pitch'))))
 
end
 
 
    -- ####################################################################
 
    -- socket info
 
   
 
 
     if has_arg('socket name') or has_arg('socket type') then
 
     if has_arg('socket name') or has_arg('socket type') then
    p.add_separator(infobox, 'Socket')
+
        p.add_separator(infobox, 'Socket')
 +
        entry{'Name', 'socket name', prop_name='socket', max_args=10, sep=',<br/>'}
 +
        entry{'Type', 'socket type', prop_name={}}
 
     end
 
     end
 
-- socket name
 
if has_arg('socket name') then
 
local socket_name =  mw.html.create('td'):wikitext(arg('socket name'))
 
for i = 2, 10 do
 
  if not has_arg('socket name ' .. i) then break end
 
  socket_name:wikitext(',<br> ' .. arg('socket name ' .. i))
 
end
 
  infobox:node(p.add_entry('Name', socket_name))
 
end
 
 
-- type
 
if has_arg('socket type') then
 
  infobox:node(p.add_entry('Type', mw.html.create('td'):wikitext( arg('socket type'))))
 
end
 
  
 
     -- ####################################################################
 
     -- ####################################################################

Latest revision as of 16:06, 16 March 2023

To add this template, simple add
{{package}}
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 add_header(box, str)
      box
        :tag('tr')
          :tag('td')
            :attr('class', 'header')
            :attr('colspan', '2')
            :wikitext(str)
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.set_val(prop, val)
	p.frame:preprocess('{{#set: ' .. prop .. '=' .. val .. '}}')	
end

function p.pkg(frame)
	
	p.frame = 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: left; font-weight: bold;')
            :wikitext('[[Special:FormEdit/package/' .. 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


    -- ####################################################################
    -- some general info first
    p.add_separator(infobox, 'General Info')

    local function entry(a)
        local label, arg_name = unpack(a)
        if not has_arg(arg_name) then return end
        local function text(i, value)
            local prop_name = a.prop_name or arg_name -- {} for none
            if type(prop_name) == 'table' then
                if i > #prop_name then
                    if a.print then return a.print(value) end
                    return value
                end
                prop_name = prop_name[i]
            end
            return '[[' .. prop_name .. '::' .. value ..
                (a.print and ('| ]]' .. a.print(value)) or ']]')
        end
        local td = mw.html.create('td'):wikitext(text(1, arg(arg_name)))
        for i = 2, (a.max_args or 1) do
            local value = origArgs[arg_name .. ' ' .. i]
            if not value or value == '' then break end
            td:wikitext((a.sep or ', ') .. text(i, value))
        end
        if label then infobox:node(p.add_entry(label, td)) end
        return td
    end
    local function link(s) return '[[' .. mw.ustring.lower(s) .. '|' .. s .. ']]' end

    local uarch_link
    if has_arg('designer') then
        uarch_link = function(s) return '[[' .. mw.ustring.lower(arg('designer') ..
            '/microarchitectures/' .. s) .. '|' .. s .. ']]' end
        local td = entry{nil, 'designer', max_args=10, print=link}
        infobox:node(p.add_entry('Designer', td:attr('style', 'width: 99%;')))
    end

    if has_arg('first launched') or has_arg('first announced') then
        local release, sep = mw.html.create('td'), ''
        if has_arg('first announced') then
            release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
            sep = '<br/>'
        end
        if has_arg('first launched') then
            release:wikitext(sep .. '[[first launched::' .. arg('first launched') .. ']] (launched)')
        end
        infobox:node(p.add_entry('Introduction', release))
    end

    entry{'Market', 'market', max_args=5, prop_name='market segment'}
    entry{'Microarchitecture', 'microarch', max_args=10,
        prop_name='microarchitecture', print=uarch_link}
    entry{'Chipset', 'chipset', max_args=10}
    entry{'<abbr title="Thermal Design Power">TDP</abbr>', 'tdp', max_args=10}

    if has_arg('package name') or has_arg('package type') then
        p.add_separator(infobox, 'Package')
        entry{'Name', 'package name', max_args=10, prop_name='package', sep=',<br/>'}
        entry{'Type', 'package type'}
        entry{'Contacts', 'package contacts'}
        entry{'Dimension', 'package dimension', max_args=3, sep=' × ',
            prop_name={'package length', 'package width', 'package height'}}
        entry{'Pitch', 'package pitch', max_args=2, sep=' × '}
    end

    if has_arg('socket name') or has_arg('socket type') then
        p.add_separator(infobox, 'Socket')
        entry{'Name', 'socket name', prop_name='socket', max_args=10, sep=',<br/>'}
        entry{'Type', 'socket type', prop_name={}}
    end

    -- ####################################################################
    -- ####################################################################
    -- Successon
	if has_arg('successor') or has_arg('predecessor') then
		add_header(infobox, 'Succession')
		
		local s = infobox:tag('tr')
		local td = s:tag('td'):attr('colspan', '2')
		local d1 = td:tag('div'):attr('style', 'display: inline-flex;')
		local d2 = td:tag('div'):attr('style', 'display: inline-flex; float: right;')
		if has_arg('predecessor') then
			
		    local list
		    if has_arg('predecessor link') then
				list = '[[' .. arg('predecessor link') .. '|' .. arg('predecessor') .. ']]'
			else
				list = '[[' .. arg('predecessor') .. ']]'
			end
		    for i = 2, 10 do
		    	if not has_arg('predecessor ' .. i) then break end
		    	if has_arg('predecessor ' .. i .. ' link') then
		    		list = list .. '<br>[[' .. arg('predecessor ' .. i .. ' link') .. '|' .. arg('predecessor ' .. i) .. ']]'
	    		else
		    		list = list .. '<br>[[' .. arg('predecessor ' .. i) .. ']]'
    			end
			end
			
			d1:tag('div')
				:attr('style', 'float: left; padding-right: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-left"></i>')
			d1:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
		end
		if has_arg('successor') then
			local list
		    if has_arg('successor link') then
				list = '[[' .. arg('successor link') .. '|' .. arg('successor') .. ']]'
			else
				list = '[[' .. arg('successor') .. ']]'
			end
		    for i = 2, 10 do
		    	if not has_arg('successor ' .. i) then break end
		    	if has_arg('successor ' .. i .. ' link') then
		    		list = list .. '<br>[[' .. arg('successor ' .. i .. ' link') .. '|' ..
		    			arg('successor ' .. i) .. ']]'
	    		else
		    		list = list .. '<br>[[' .. arg('successor ' .. i) .. ']]'
    			end
			end
			
			d2:tag('div')
				:attr('style', 'float: left;')
				:wikitext(list)
			d2:tag('div')
				:attr('style', 'float: right; padding-left: 10px; margin: auto 5px;')
				:wikitext('<i class="fa fa-chevron-right"></i>')
		end
	end
    -- Contemporary
	if has_arg('contemporary') then
		add_header(infobox, 'Contemporary')
		
		local s = infobox:tag('tr')
		local td = s:tag('td'):attr('colspan', '2')
		
		td:attr('style', 'text-align: center;')

	    local list
	    if has_arg('contemporary link') then
			list = '[[' .. arg('contemporary link') .. '|' .. arg('contemporary') .. ']]'
		else
			list = '[[' .. arg('contemporary') .. ']]'
		end
	    for i = 2, 10 do
	    	if not has_arg('contemporary ' .. i) then break end
	    	if has_arg('contemporary ' .. i .. ' link') then
	    		list = list .. '<br>[[' .. arg('contemporary ' .. i .. ' link') .. '|' .. arg('contemporary ' .. i) .. ']]'
    		else
	    		list = list .. '<br>[[' .. arg('contemporary ' .. i) .. ']]'
			end
		end
		
		td:wikitext(list)
	end


	infobox:wikitext('[[instance of::package| ]]')
	infobox:wikitext('[[Category:all ic packages]]')
	
    return infobox
end

return p