17,230
edits
(saving WIP for gallery layout. realized this will be much easier if I first convert Tab (and maybe Gallery too)) |
(implement gallery mode (has a few bugs I think)) |
||
Line 1: | Line 1: | ||
local Box = require( 'Module:Box' ).Box | local Box = require( 'Module:Box' ).Box | ||
local Lazy = require( 'Module:Lazy' ) -- may load: Tabs, Gallery | |||
function getCategoryProps( categoryName ) | function getCategoryProps( categoryName ) | ||
Line 52: | Line 53: | ||
end | end | ||
function buildGallery( | function buildGallery( pages ) | ||
local | local Gallery = Lazy.load( 'Module:Gallery' ).Gallery | ||
local gallery = Gallery.new() -- TODO define appropriate args. CD/Header has: {{Gallery|size={{#ifeq:{{{size|}}}|large|95|62}}|pad=1|square={{{square|true}}}}} | |||
for _, page in ipairs( pages ) do | |||
defaultGallery:addFile( 'No Image.png', '[[' .. page.text .. '|' .. page.extra.name or page.text .. ']]', { | |||
link = page.text, | |||
alt = page.extra.name or page.text | |||
} ) | |||
end | |||
return gallery:render() | |||
end | |||
function buildGalleries( categoryProps, pageTree ) | |||
local Gallery = Lazy.load( 'Module:Gallery' ).Gallery | |||
local defaultGallery = nil | |||
if pageTree.default then | |||
defaultGallery = buildGallery( pageTree.default ) | |||
end | |||
if categoryProps.groups then | |||
local Tabs = Lazy.load( 'Module:Tabs' ).Tabs | |||
local tabs = Tabs.new() | |||
if defaultGallery then | |||
tabs:addTabTopWithContent{ | |||
contentId = 'General', | |||
content = defaultGallery | |||
} | |||
end | |||
-- coerce it to a table for easier processing | |||
local groups = type( categoryProps.groups ) == 'table' and categoryProps.groups or { categoryProps.groups } | |||
for index, group in ipairs( groups ) do | |||
if pageTree[group] then | |||
tabs:addTabTopWithContent{ | |||
contentId = group, | |||
content = buildGallery( pageTree[group] ) | |||
} | |||
end | |||
end | |||
return tabs:render() | |||
end | |||
return defaultGallery | |||
return | |||
end | end | ||
Line 93: | Line 109: | ||
for _, page in ipairs( pages ) do | for _, page in ipairs( pages ) do | ||
list:tag( 'li' ) | list:tag( 'li' ) | ||
:wikitext( '[[' .. page.text .. '|' .. (page.extra.name | :wikitext( '[[' .. page.text .. '|' .. (page.extra.name or page.text) .. ']]' ) | ||
end | end | ||
end | end | ||
Line 109: | Line 125: | ||
if categoryProps.groups then | if categoryProps.groups then | ||
-- coerce it to a table for easier processing | -- coerce it to a table for easier processing | ||
local groups = type(categoryProps.groups) == 'table' and categoryProps.groups or { categoryProps.groups } | local groups = type( categoryProps.groups ) == 'table' and categoryProps.groups or { categoryProps.groups } | ||
for index, group in ipairs(groups) do | for index, group in ipairs( groups ) do | ||
if | if pageTree[group] then | ||
local row = content:tag( 'tr' ) | local row = content:tag( 'tr' ) | ||
row:tag( 'th' ) | row:tag( 'th' ) |