From WikiChip
Difference between revisions of "Module:package"

(Set package properties.)
 
(4 intermediate revisions by one other user not shown)
Line 49: Line 49:
 
end
 
end
  
function p.pack(frame)
+
function p.pkg(frame)
 
 
 
p.frame = frame
 
p.frame = frame
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)
    if has_arg('developer') then
+
        local label, arg_name = unpack(a)
      local designers = mw.html.create('td'):attr('style', 'width: 99%;')
+
        if not has_arg(arg_name) then return end
      designers:wikitext('[[designer::' .. arg('developer') .. '| ]][[' .. arg('developer') .. ']]')
+
        local function text(i, value)
for i = 2, 10 do
+
            local prop_name = a.prop_name or arg_name -- {} for none
if not has_arg('developer ' .. i) then break end
+
            if type(prop_name) == 'table' then
designers:wikitext(', [[designer::' .. arg('developer ' .. i) .. '| ]][[' .. arg('developer ' .. i) .. ']]')
+
                if i > #prop_name then
end
+
                    if a.print then return a.print(value) end
    infobox:node(p.add_entry('Designer', designers))
+
                    return value
end
+
                end
+
                prop_name = prop_name[i]
-- release date
+
            end
if has_arg('first launched') or has_arg('first announced') then
+
            return '[[' .. prop_name .. '::' .. value ..
  local release = mw.html.create('td')
+
                (a.print and ('| ]]' .. a.print(value)) or ']]')
  if has_arg('first announced') then
+
        end
    release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
+
        local td = mw.html.create('td'):wikitext(text(1, arg(arg_name)))
  end
+
        for i = 2, (a.max_args or 1) do
  if has_arg('first launched') then
+
            local value = origArgs[arg_name .. ' ' .. i]
  if has_arg('first announced') then
+
            if not value or value == '' then break end
    release:wikitext('<br>')
+
            td:wikitext((a.sep or ', ') .. text(i, value))
  end
+
        end
    release:wikitext('[[first launched::' .. arg('first launched') .. ']] (launched)')
+
        if label then infobox:node(p.add_entry(label, td)) end
  end
+
        return td
  infobox:node(p.add_entry('Introduction', release))
+
    end
end
+
     local function link(s) return '[[' .. mw.ustring.lower(s) .. '|' .. s .. ']]' end
+
 
-- market segment
+
    local uarch_link
    if has_arg('market') then
+
    if has_arg('designer') then
p.set_val('market segment', arg('market'))
+
        uarch_link = function(s) return '[[' .. mw.ustring.lower(arg('designer') ..
      local markets = mw.html.create('td'):wikitext(arg('market'))
+
            '/microarchitectures/' .. s) .. '|' .. s .. ']]' end
      for i = 2, 5 do
+
        local td = entry{nil, 'designer', max_args=10, print=link}
  if not has_arg('market ' .. i) then break end
+
        infobox:node(p.add_entry('Designer', td:attr('style', 'width: 99%;')))
p.set_val('market segment', arg('market ' .. i))
+
    end
      markets:wikitext(', ' .. arg('market ' .. i))
+
 
      end
+
     if has_arg('first launched') or has_arg('first announced') then
    infobox:node(p.add_entry('Market', markets))
+
        local release, sep = mw.html.create('td'), ''
end
+
        if has_arg('first announced') then
+
            release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
-- microarch
+
            sep = '<br/>'
     if has_arg('microarch') then
+
        end
      local microarchs = mw.html.create('td')
+
        if has_arg('first launched') then
      p.set_val('microarchitecture', arg('microarch'))
+
            release:wikitext(sep .. '[[first launched::' .. arg('first launched') .. ']] (launched)')
      microarchs:wikitext('[[' .. mw.ustring.lower(arg('designer')) .. '/microarchitectures/' ..
+
        end
      mw.ustring.lower(arg('microarch')) .. '|' .. arg('microarch') .. ']]')
+
        infobox:node(p.add_entry('Introduction', release))
      for i = 2, 10 do
+
    end
      if not has_arg('microarch ' .. i) then break end
+
 
      p.set_val('microarchitecture', arg('microarch ' .. i))
+
    entry{'Market', 'market', max_args=5, prop_name='market segment'}
        microarchs:wikitext(', [[' .. mw.ustring.lower(arg('designer')) .. '/microarchitectures/' ..
+
    entry{'Microarchitecture', 'microarch', max_args=10,
      mw.ustring.lower(arg('microarch ' .. i)) .. '|' .. arg('microarch ' .. i) .. ']]')
+
        prop_name='microarchitecture', print=uarch_link}
      end
+
    entry{'Chipset', 'chipset', max_args=10}
    infobox:node(p.add_entry('Microarchitecture', microarchs))
+
    entry{'<abbr title="Thermal Design Power">TDP</abbr>', 'tdp', max_args=10}
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('dimension') then
 
      local dimension = mw.html.create('td'):wikitext(arg('dimension'))
 
      for i = 2, 10 do
 
      if not has_arg('dimension ' .. i) then break end
 
      dimension:wikitext(' × ' .. arg('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', package_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 15: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