Jump to content

Module:Version: Difference between revisions

no edit summary
(Created page with "-- Current stable version. Increment this when a new version is released. local STABLE = 32 local RECENT = 31 local p = {} -- Tries to parse a version number -- returns either a version number, "trunk", or nil (meaning unknown) local function parse_version(version) if type(version) == "number" or version == "trunk" then return version end local num = tonumber(version) if num then -- convert 0.17 to 17 if num < 1 then num = 100*num end...")
 
No edit summary
Line 1: Line 1:
-- Current stable version. Increment this when a new version is released.
-- Current stable version. Increment this when a new version is released.
local STABLE = 32
-- The version of Elin is made of <major version>.<minor version>
local RECENT = 31
local CURRENT = 23.67
 
local _, _, CURRENT_major, CURRENT_minor = string.find( CURRENT, "(%d+)%.(%d+)" )
local p = {}
local p = {}


-- This function assume the input is in the form of <major version>.<minor version>, but it doesn't give an error if minor version doesn't exist.
-- Return:
-- 1, the current version is greater; 0, the versions are the same
-- -1, the input version is greater
local function if_greater_function(test_version)
_, _, major, minor = string.find( test_version, "(%d+)%.(%d+)" )
if CURRENT_major > major then
return 1
elseif CURRENT_major < major then
return -1
elseif CURRENT_minor > minor then
return 1
elseif CURRENT_minor < minor then
return -1
else
return 0
end
end
-- Tries to parse a version number
-- Tries to parse a version number
-- returns either a version number, "trunk", or nil (meaning unknown)
-- returns either a version number, "trunk", or nil (meaning unknown)
Line 13: Line 32:
   local num = tonumber(version)
   local num = tonumber(version)
   if num then
   if num then
    -- convert 0.17 to 17
    if num < 1 then
      num = 100*num
    end
    if num > STABLE then
      return "trunk"
    else
       return num
       return num
    end
   end
   end
   return nil
   return nil
Line 28: Line 39:
function p.version_tag(frame)
function p.version_tag(frame)
   local version = parse_version(frame.args[1])
   local version = parse_version(frame.args[1])
   local current = version == STABLE
   local current = if_greater_function(version) == 0
   local previ = version == RECENT
   local previ = if_greater_function(version) == 1
   local trunk = version == "trunk"
   local trunk = if_greater_function(version) == -1
   local unknown = not version
   local unknown = not version
 
  local version_b = ""
  if version >= 23 then
  version_b = "EA"
  elseif version <= 22 then
  version_b = "Beta"
  end
   local bgcolor = "fc6"
   local bgcolor = "fc6"
   if current then
   if current then
Line 54: Line 70:
   result = result:format(bordercolor, bgcolor, bordercolor)
   result = result:format(bordercolor, bgcolor, bordercolor)
   if trunk then
   if trunk then
     result = result .. "'''''[[Trunk]]-only''': This article pertains to a feature of Crawl which is being tested. It will likely change before the next release, and may even be removed entirely.''"
     result = result .. "'''''This article pertains to a feature of Elin which is unrelease in stable version.''"
   else
   else
     result = result .. "'''''Version "
     result = result .. "'''''Version "
Line 64: Line 80:
     result = result .. "''': "
     result = result .. "''': "
     if current then
     if current then
       result = result .. "This article is up to date for the [[0." .. STABLE .. "|latest stable release]] of ''Dungeon Crawl Stone Soup''."
       result = result .. "This article is up to date for the [[Elin:Changelog|latest stable release]] of ''Elin''."
     else
     else
       result = result .. "This article '''may not be''' up to date for the [[0." .. STABLE .. "|latest stable release]] of Crawl.''"
       result = result .. "This article '''may not be''' up to date for the [[Elin:Changelog|latest stable release]] of Elin.''"
     end
     end
   end
   end
   result = result .. "</div>"
   result = result .. "</div>"
 
  -- The next part is used to add a category, we don't do that just yet.
   result = result .. "\n[[Category:"
   --result = result .. "\n[[Category:"
   if trunk then
   --if trunk then
    result = result .. "Trunk"
  --  result = result .. "Trunk"
   elseif unknown then
   --elseif unknown then
    result = result .. "Unknown"
  --  result = result .. "Unknown"
   else
   --else
    result = result .. "0." .. version
  --  result = result .. "0." .. version
   end
   --end
   result = result .. " articles]]"
   --result = result .. " articles]]"


   return result
   return result
346

edits