Difference between revisions of "Module:String"
CommanderC (talk | contribs) |
CommanderC (talk | contribs) |
||
| Line 38: | Line 38: | ||
new_text, _ = string.gsub(text, "%%", "") | new_text, _ = string.gsub(text, "%%", "") | ||
return new_text | return new_text | ||
| + | end | ||
| + | |||
| + | -- Used in Template:Spellcaster016 | ||
| + | function p.make_spellcaster_table(frame) | ||
| + | local result = [=[<div style="margin: 1.0em; margin-top:0; margin-right:0; padding: 0px; float: left; border:none;"> | ||
| + | {| class="prettytable" style="border:none; margin:0; padding:0; width:16em;" | ||
| + | ! colspan="2" style="font-size:larger;" | Spell set {{{number|}}} | ||
| + | |-</div>]=] | ||
| + | local slots = {'slot1', 'slot2', 'slot3', | ||
| + | 'slot4', 'slot5', 'slot6'} | ||
| + | for i, slot in ipairs(slots) do | ||
| + | if frame.args[slot] then | ||
| + | result = result .. "! align=\"left\" | Slot<sup>" .. tostring(i) .. "</sup>\n| {{{" .. slot .. "|''none''}}}\n|-\n" | ||
| + | end | ||
| + | end | ||
| + | result = result .. "|}</div>[[Category:Spellcaster]]" | ||
| + | return result | ||
end | end | ||
return p | return p | ||
Revision as of 22:36, 18 March 2015
Small functions for string manipulation.
local p = {}
-- Used in Template:Monster by Property:Hit_dice
function p.first_word(frame)
local text = frame.args[1]
for token in string.gmatch(text, "[^%s,]+") do
return token
end
end
-- Used in Template:Monster by Property:Monster_magic_resistance
function p.fix_magic_resistance(frame)
local text = frame.args[1]
if text == "Immune" or text == "immune" then
return "1000"
end
return text
end
-- Used in Template:Monster by Property:Monster_size
function p.fix_monster_size(frame)
local text = frame.args[1]
found, _, token = string.find(text, "|([^%]]+)%]")
if found then
return token
end
return text
end
-- Used in Template:Monster by Property:Monster_intelligence
function p.fix_monster_intelligence(frame)
return p.fix_monster_size(frame)
end
-- Used in Template:Armour
function p.fix_gdr(frame)
local text = frame.args[1]
new_text, _ = string.gsub(text, "%%", "")
return new_text
end
-- Used in Template:Spellcaster016
function p.make_spellcaster_table(frame)
local result = [=[<div style="margin: 1.0em; margin-top:0; margin-right:0; padding: 0px; float: left; border:none;">
{| class="prettytable" style="border:none; margin:0; padding:0; width:16em;"
! colspan="2" style="font-size:larger;" | Spell set {{{number|}}}
|-</div>]=]
local slots = {'slot1', 'slot2', 'slot3',
'slot4', 'slot5', 'slot6'}
for i, slot in ipairs(slots) do
if frame.args[slot] then
result = result .. "! align=\"left\" | Slot<sup>" .. tostring(i) .. "</sup>\n| {{{" .. slot .. "|''none''}}}\n|-\n"
end
end
result = result .. "|}</div>[[Category:Spellcaster]]"
return result
end
return p