Module:CarManufacturerData

local p = {} local type_img_data = mw.loadData( 'Module:CarManufacturerData/car_data.json' ) -- load json local getArgs = require('Dev:Arguments').getArgs local strlower = string.lower -- Convert to lower case -- Get data from json page given main type name and piece name function getCarInfo(manufacturer_name, car_data_piece) m_type = strlower(manufacturer_name) local car_DB = mw.loadData("Module:CarManufacturerData/car_data.json") local car_chunk = car_DB[m_type] if car_chunk and car_DB[m_type][car_data_piece] then return car_DB[m_type][car_data_piece] end end

function p.CarManufacturerData(frame) -- Implements local args = getArgs(frame, {       trim = false,        removeBlanks = false    }) local givename = false local givecat = false local givelogo = false local givealtname = false local testout = false if args["givename"] then givename = true end if args["givecat"] then givecat = true end if args["givelogo"] then givelogo = true end if args["givealtname"] then givealtname = true end if args["test"] then testout = true end

return p._CarManufacturerData(args, givename, givecat, givelogo, givealtname, testout) end

function p._CarManufacturerData( args, showname, showcat, showlogo, showaltname, testmode ) local m_index = args['manufacturer'] -- use manufacturer param for m_index if args['manufacturer'] == nil then -- use param 1, if no manufacturer= m_index = args[1] elseif args[1] == nil then -- blank type if no param 1 m_index = '' end if m_index ~= nil then -- if not nil, make lowercase m_index = string.lower(m_index) end

local name_text = "Unknown Manufacturer" local cat_text = "Unknown Cars" local logo_file = "Unknown_logo.jpg" local logo_size = "52px" local logo_link = "" local altname_text = "Unknown Alt Name" local img_wikitext = '' if m_index ~= nil then -- strip spaces for indexing m_index = mw.ustring.gsub(m_index, "%s", "") -- strip apostrophes for indexing m_index = mw.ustring.gsub(m_index, "\'", "") -- strip dashes for indexing m_index = mw.ustring.gsub(m_index, "\-", "") end -- Use new m_index, if alias found if m_index ~= nil and getCarInfo(m_index, "alias") ~= nil then m_index = getCarInfo(m_index, "alias") end

-- Get manufacturer name if m_index ~= nil and getCarInfo(m_index, "name") ~= nil then name_text = getCarInfo(m_index, "name") end -- Get manufacturer alt name if m_index ~= nil and getCarInfo(m_index, "altname") ~= nil then altname_text = getCarInfo(m_index, "altname") end -- Get manufacturer category if m_index ~= nil and getCarInfo(m_index, "category") ~= nil then cat_text = getCarInfo(m_index, "category") end -- Get image file name if m_index ~= nil and getCarInfo(m_index, "logofile") ~= nil then logo_file = getCarInfo(m_index, "logofile") end

-- Get image size change if it exists if m_index ~= nil and getCarInfo(m_index, "logosize") ~= nil then logo_size = getCarInfo(m_index, "logosize") end -- Get link (also for for image) if m_index ~= nil and getCarInfo(m_index, "logolink") ~= nil then logo_link = getCarInfo(m_index, "logolink") end

local final_data = "" if showname then final_data = name_text end if showcat then final_data = final_data .. ''       if testmode then final_data = final_data .. '&#91;&#91;'       else            final_data = final_data .. '[['        end        final_data = final_data .. 'Category:' .. cat_text        if testmode then            final_data = final_data .. '&#93;&#93;'        else            final_data = final_data .. ']]' end end if showlogo then final_data = final_data .. ''       if testmode then final_data = final_data .. '&#91;&#91;'       else final_data = final_data .. ''       end end if showaltname then final_data = final_data .. '' .. altname_text end -- Return final wikitext return final_data end return p