Difference between revisions of "Module:Spellbook"

From CrawlWiki
Jump to: navigation, search
(Created page with "local p = {} function p.spellbook_table(frame) local data = mw.loadData('Module:Table of spellbooks') local book = frame.args[1] if not book then return "" end ...")
 
Line 17: Line 17:
 
   end
 
   end
 
   result = result .. "|}\n"
 
   result = result .. "|}\n"
 +
  return result
 +
end
 +
 +
function p.short_spell_list(frame)
 +
  local data = mw.loadData('Module:Table of spellbooks')
 +
  local book = frame.args[1]
 +
  if not book then
 +
    return ""
 +
  end
 +
  local result = "'''[[" .. book .. "]]''': "
 +
  local spell_list = {}
 +
  for _,sp in ipairs(data[book]) do
 +
    table.insert(spell_list, "[[".. sp.name .. "]]")
 +
  end
 +
  result = result .. table.concat(spell_list, ", ")
 
   return result
 
   return result
 
end
 
end
  
 
return p
 
return p

Revision as of 19:21, 7 September 2013

This module generates the spellbook tables in the pages of the category Category:Book, and the lists of spells in the Book page.

Required by: Template:Spellbook and Template:Spellbook2.

Requires: Module:Table of spellbooks and Module:Table of spells


local p = {}

function p.spellbook_table(frame)
  local data = mw.loadData('Module:Table of spellbooks')
  local book = frame.args[1]
  if not book then
    return ""
  end
  local result = [==[{| cellpadding="5" border="1"
|- align="center"
! Tile || Spell || Type || Level
]==]
  for _,sp in ipairs(data[book]) do
    result = result .. "|-\n| " .. sp.image .. " || " ..
       sp.letter .. " - [[" .. sp.name .. "]] || " .. sp.schools .. 
       " || " .. sp.level .. "\n"
  end
  result = result .. "|}\n"
  return result
end

function p.short_spell_list(frame)
  local data = mw.loadData('Module:Table of spellbooks')
  local book = frame.args[1]
  if not book then
    return ""
  end
  local result = "'''[[" .. book .. "]]''': "
  local spell_list = {}
  for _,sp in ipairs(data[book]) do
    table.insert(spell_list, "[[".. sp.name .. "]]")
  end
  result = result .. table.concat(spell_list, ", ")
  return result
end

return p