Module:Gnoblin: Difference between revisions
From Deepest Lore
More actions
Arvid Varg (talk | contribs) No edit summary |
Arvid Varg (talk | contribs) No edit summary Tag: Reverted |
||
| Line 2: | Line 2: | ||
function p.gallery(frame) | function p.gallery(frame) | ||
local text = frame.args | local text = frame.args.text or "" | ||
local entries = {} | local entries = {} | ||
| Line 11: | Line 11: | ||
local separator = string.find(entry, "::", 1, true) | local separator = string.find(entry, "::", 1, true) | ||
local file | local file = entry | ||
local description | local description = "" | ||
if separator then | if separator then | ||
file = mw.text.trim(string.sub(entry, 1, separator - 1)) | file = mw.text.trim(string.sub(entry, 1, separator - 1)) | ||
description = mw.text.trim(string.sub(entry, separator + 2)) | description = mw.text.trim(string.sub(entry, separator + 2)) | ||
end | end | ||
if file ~= "" then | if file ~= "" then | ||
local | local image = mw.html.create("div") | ||
:addClass("gallery-image") | |||
:wikitext("[[File:" .. file .. "|frameless]]") | |||
local item = mw.html.create("div") | |||
:addClass("gallery-item") | |||
:node(image) | |||
if description ~= "" then | if description ~= "" then | ||
item:tag("div") | |||
:addClass("gallery-caption") | |||
:wikitext(description) | |||
end | end | ||
table.insert(entries, | table.insert(entries, tostring(item)) | ||
end | end | ||
end | end | ||
| Line 38: | Line 43: | ||
end | end | ||
return | return '<div class="character-gallery">' .. | ||
table.concat(entries) .. | |||
'</div>' | |||
end | end | ||
Revision as of 20:41, 29 August 2026
Module functions=
Unlink
House Dewülf House Dewülf Category:House
Templates using the module
Titles
! colspan="2" class="infobox-subheader" | Not on a character |-
! colspan="2" class="infobox-subheader" |
|-
| Gnoblin | |
|---|---|
| Using the template | |
| Gnoblin | |
|---|---|
| Simple name only | |
local p = {}
function p.gallery(frame)
local text = frame.args.text or ""
local entries = {}
for entry in mw.text.gsplit(text, ";") do
entry = mw.text.trim(entry)
if entry ~= "" then
local separator = string.find(entry, "::", 1, true)
local file = entry
local description = ""
if separator then
file = mw.text.trim(string.sub(entry, 1, separator - 1))
description = mw.text.trim(string.sub(entry, separator + 2))
end
if file ~= "" then
local image = mw.html.create("div")
:addClass("gallery-image")
:wikitext("[[File:" .. file .. "|frameless]]")
local item = mw.html.create("div")
:addClass("gallery-item")
:node(image)
if description ~= "" then
item:tag("div")
:addClass("gallery-caption")
:wikitext(description)
end
table.insert(entries, tostring(item))
end
end
end
if #entries == 0 then
return ""
end
return '<div class="character-gallery">' ..
table.concat(entries) ..
'</div>'
end
function p.processTitle(frame)
local input = frame.args[1] or ""
if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then
return input
end
return frame:expandTemplate{
title = "Title",
args = { name = input }
}
end
function p.stripHouse(frame)
local name = frame.args[1]
if not name or name == "" then
name = mw.title.getCurrentTitle().text
end
local prefixes = { "House", "Clan", "Family", "Dynasty" }
for _, prefix in ipairs(prefixes) do
local pattern = "^[" .. mw.ustring.sub(prefix,1,1):lower() .. mw.ustring.sub(prefix,1,1):upper() .. "]" ..
mw.ustring.sub(prefix,2):lower() .. "%s+"
name = mw.ustring.gsub(name, pattern, "")
end
return name
end
function p.unlink(frame)
local text = frame.args[1] or ""
text = mw.ustring.gsub(text, "[%[%]]", "")
return text
end
return p