Changes

Jump to: navigation, search

Module:Card gallery

4,960 bytes removed, 1 year ago
Restoring revision 5001485 by User:Becasita on 2022-06-14 18:46:58. "Fix."
-- <pre>
-- NOTES:-- input in the form of:-- «-- <card number>; <set>; <rarity>; <edition>; <alt>-- »-- Where "rarity" and "edition" can either be in full form or abbreviated.-- Example:-- «-- {{@name Card gallery|region=EN|-- TLM-EN012; The Lost Millennium; SR; 1E // extension::jpg-- TLM-EN012; The Lost Millennium; UtR; 1E // extension::jpg-- TLM-EN012; The Lost Millennium; SR; UE-- TLM-EN012; The Lost Millennium; UtR; UE-- SDJ-035; Starter Deck: Joey; C; UE; Reprint // @description::Spell-- S1; Yu-Gi-Oh! True Duel Monsters: Sealed Memories promotional cards; UR-- » -- Ideas:-- * propagate:-- «-- TLM-EN012; The Lost Millennium; SR; 1E-- *; *; UtR; *-- *; *; SR; UE-- *; *; UtR; *-- »-- Avoids repitition. Harder with Builds a card gallery section for a file replace scriptsingle region-- TODO:-- support for OP / GC / CT / etc. (<card number>; <set>; <rarity>; <edition>; <alt> @author [[User:: GC|CT) --------------------Becasita]]-- Global vairables@contact [[User talk:--------------------local CardGallery = {};local _D = {}; -- Global data object.Becasita]]
----------------
-- Load modules:
----------------
local getArgs DATA = require( 'Module:Data' );local UTIL = require( 'Module:ArgumentsUtil' ).getArgs; local DATA InfoWrapper = require( 'Module:DataInfoWrapper' );local getName StringBuffer = require( 'Module:NameStringBuffer' ).main;
----------------------- Utility functions:----------------------- mw functions:local split File = mw.text.split;local gsplit = mw.text.gsplit;local HTML = mw.html.createrequire( 'Module:Card gallery/File' );
-- @name _trim-------------------- Module variables:-- Trims white space from front and tail of string.-------------------- If This can be seen as the input is only white space, returns nil.ast:local function _trim( s ) if s and not s:matchCardGallery = InfoWrapper( '^%s*$Card gallery' ) then return mw.text.trim( s ); endend
-- @name _countParser state:-- @description Counts how many entries a table has.local PAGENAME,local function _count( t ) NAMESPACE, _frame, _args, local counter = 0;_region, for key_language, value in pairs( t ) do counter = counter + 1; _type, end_title, return counter_debug;endlocal _files = {};
-- @name _linkMethods:-- @description TODOlocal function _linkCardGallery:getRegion( ... ) -- TODO return_region;
end
-- @name _error-- Generates an error and places it on the error table.local function _error( message, default, category ) _D.errors.exists = true; local err = HTML( 'div' )CardGallery:cssgetLanguage( 'padding-left', '1.6em' ) :tag( 'strong' ):addClass( 'error' ) :wikitext( ('Error: %s'):format( message ) ) :done() :allDone(); local cat = category and ('[[Category:%s]]'):format( category ) or ''; table.insert( _D.errors, table.concat( { tostring( err ), cat } ) ); return default or ''_language;
end
---------------- File classfunction CardGallery:---------------- @name File-- @classAttr counter -> [static] Counts the number of File instances.local File = {};File.__index = File;File.counter = 0; -- @name new -> File constructor.-- @attr exists -> Control attribute; denotes if a file is to be printed.-- @attr number -> The card number getType(linked).-- @attr region -> The region.-- @attr setEn -> The English name for the set.-- @attr setLn -> The localized name for the set.-- @attr setAbbr -> The set abbreviation.-- @attr rarity -> The rarity name.-- @attr r -> The rarity abbreviation.-- @attr edition -> The full edition.-- @attr ed -> The edition abbreviation.-- @attr modifier -> The card modifier.-- @attr modifierAbbr -> The card modifier abbreviation (OP|GC|CT).-- @attr alt -> The alt value.-- @attr extension -> The file extension.function File.new( std, mod, opt ) -- @attr _standard -> Contains the trimmed input args for the standard input {enum-like}. -- @attr _modifier -> Contains the trimmed input arg for the modifier (OP|GC|CT). -- @attr _options -> Contains the trimmed input args for the options {map-like}. File.counter = File.counter + 1; local fileData = {}; fileData.exists = true; fileData._standard = std or {}; fileData._modifier = mod or ''; fileData._options = opt or {};  return setmetatable( fileData, File )_type;
end
-- @name setNumber--------------------- Utility functions:-- @description Sets the «number» and «setAbbr» attributes.-------------------function File-- mw functions:setNumber() local cardNumber HTML = selfmw.html._standard[ 1 ]create;
---------------------- Module functions:--------------------local function getCardGalleryType( t ) if cardNumber type( t ) == 'string' then self.exists return ( { ['anime'] = 'Anime', ['manga'] = 'Manga', ['ruhduel'] = 'Rush Duel', ['ruh'] = 'Rush Duel', -- "s" is trimmed ['game'] = 'Video games', ['vg'] = 'Video games', ['other'] = false;'Other', _error} )[ mw.text.trim( t ):lower():gsub( "[%s%-s]", 'No set abbreviation given for file input number «%d»!'):formatgsub( File.counter 'video', '' ) ); return '';]
end
 
if cardNumber and cardNumber:match( '^%w%w%w%w?%-%w%w%w%w?%w?$' ) then
-- Input like «TLM-EN012».
self.number = _link( cardNumber );
self.setAbbr = cardNumber:match( '^(%w%w%w%w?)%-%w%w%w%w?%w?$' );
else
-- Input like «S1».
self.number = nil;
self.setAbbr = cardNumber;
end
 
return self;
end
--[[function File:setSet()
self.
end
function File:setRarity()
self.
end
function File:setEdition()
self.
end
function File:setModifier()
self.
end
function File:setAlt()
self.
end
function File:setExtension()
self.
end]]
---------------------- Module functions:---------------------- @name getInfoinitInfo
-- @description Handles generic info.
local function getInfoinitInfo() -- Page: local mwTitle = mw.title.getCurrentTitle(); PAGENAME = mwTitle.text; NAMESPACE = mwTitle.nsText; 
-- Region and language:
_D.rg _region = DATA.getRggetRegion( _D.args_args[ 'region' ] ) or _errorCardGallery:error( ('Invalid «region»: «%s!'):format( _D.args_args[ 'region' ] or '(no region given)' ), DATA.getRggetRegion( 'en' )
);
_D.region = DATA.getRegion( _D.rg ); _D.ln = DATA.getLn( _D.rg ); _D.language _language = DATA.getLanguage( _D.rg ); -- Flags: _D.flags = {}; _D.flags.notEnglish = _D.ln ~= 'en'; -- TODO may not be needed! _D.flags.italics = not ((_D.ln == 'ja') or (_D.ln == 'zh') or (_D.ln == 'ko')) --[[and 'normal' or 'italic']]; -- Medium: _D.cg = _D.flags.italics and 'TCG' or 'OCG'; -- TODO Probably not gonna use that. -- Card and page: _D.PAGENAME = mw.title.getCurrentTitle().text; _D.NAMESPACE = mw.title.getCurrentTitle().nsText; _D.name = getName( _D.PAGENAME, _D_region.language index );
-- Type of gallery:
_type = getCardGalleryType( _args[ 'type' ] );
_title = _args[ 'title' ];
_debug = _args[ 'debug' ];
end
-- @name wrapInQuotesgetFiles-- @description Wraps «name» in proper quotation marksAssembles the file entries and prepares them to be parsed.local function wrapInQuotesinitFiles( name, std ) if not _trim( name ) _args[ 1 ] then return CardGallery:error( ( _frame.args[ 1 ] and 'Empty'or 'No' ) .. 'input provided for the gallery!' ); -- Return empty string.
end
return (std or (_D.ln ~= 'ja' and _D.ln ~= 'zh'))
and table.concat( { '"', name, '"' } )
or table.concat( { '「', name, '」' } )
;
end
-- @name printErrors-- @dascription Stringifies the errors table for inputEntry in mw.text.local function printErrorsgsplit(_args[ 1 ], '\n' )do local category entry = '[[Category:UTIL.trim(inputEntry ) and File.factory(Card galleryCardGallery, inputEntry )) transclusion to be checked]]'; if not _Dentry then table.errors.exists theninsert( _files, entry ); return '';end
end
table.insert( _D.errors, category );
return table.concat( _D.errors, '\n' );
end
-- @name buildHeader-- @description builds Builds the gallery mediawiki section header.local function buildHeadergetMwSectionHeader() return HTML( _type and 'div' ):addClass( 'gallery== %s -header%s ==' ):attr( 'id', (or '== %s_sections ==' ):format( _D.rg ) ) :tag( 'div' _type or _title) :wikitext( wrapInQuotes( _Dor _region.name ) ) :done() :tag( 'div' ) :wikitext( _Dfull, _region.region ) :done()full :allDone();
end
-- @description Builds the ToC skeleton.local function _buildStandardgetToC( arg, modifier ) local standard = {};return tostring(  if not _trim HTML( arg 'div' ) then return standard; end for value in gsplit:addClass( arg, '%s*;%s*card-gallery__toc' ) do if value then table.insert:tag( standard, _trim( value ) or 'ul' ); :done() end:allDone() end  return standard);
end
-- @description Builds the errors' log.local function _buildOptionsgetErrors( arg ) local options = {};return tostring(  if not _trim HTML( arg 'div' ) then return options; end  :addClass( 'card-- TODOgallery__errors' ) for option in gsplit :tag( tempOpt, '%s*;%s*ul' ) do local opt = _trim :node( CardGallery:dumpErrors( function( option err ); if opt then return tostring( local optTemp = split HTML( opt, '%s*li' ) :tag( 'strong' ) :%s*' wikitext( err ); local optName = _trim :done( optTemp[ 1 ] ); local optValue = _trim :allDone( optTemp[ 2 ] ); if optName and optValue then ) end ) options[ optName ] = optValue;) end:done() end:allDone() end  return options);
end
-- @name splitEntry-- @description Splits an input entry into Builds the standard valus, the modifier and the optionsgallery itself.local function splitEntrygetGallery( entry ) if not _trimlocal gallery = StringBuffer( entry ) then return {}, :addLine( '<gallery heights="175px" position="center" captionalign="center">') ; for _, {}file in ipairs( _files ) do gallery:addLine( file:render() );
end
gallery:addLine( '</gallery>' );
local temp1 = splitreturn tostring( HTML( entry, '%s*//%s*div' ); local tempOpt = temp1[ 2 ] or :addClass( 'card-gallery__gallery';) local temp2 = split :node( _debug and tostring( HTML( temp1[ 1 ], '%s*pre' ):node( gallery:toString() ):%s*' done(); local tempMod = temp2[ 2 ]; ) or _frame:preprocess( local tempStd = temp2[ 1 ]; gallery:toString() ) local modifier = _trim( tempMod ); local standard = _buildStandard :allDone( tempStd, modifier ); local options = _buildOptions( tempOpt );  return standard, modifier, options;
end
-- @name process-- @description Processes a gallery input entry and converts it into raw wikitext markupAggregates the categories.-- TODOlocal function processgetCategories( entry ) local standard, modifier, options = splitEntryreturn tostring( entry ); local fileObject = File.new HTML( standard, modifier, options 'div' ); -- TODO return table.concat :addClass( { 'card-- TODOgallery__categories' ) : TESTwikitext( table.concat CardGallery:dumpCategories( standard ), ) 'modifier: ' .. modifier or 'nil', type( options ) .. _countallDone( options ) }, '\n' );
end
-- @name buildInnerGallery-- TODOlocal function buildInnerGalleryrender() if local buffer = StringBuffer(_D.args[ 1 ] or '') == '' then :addLine( '<div id="card-gallery-- TODO: Error? return '.. _region.index .. ' end " class="card-- <card number>; <set>; <rarity>; <edition>; <alt> :: <modifier> // <option1>::<value1gallery">; <optionN>::<valueN> local galleryEntries = {}; for inputEntry in gsplit( _D.args[ 1 ], '\n' ) do local entry = _trim:addLine( getMwSectionHeader( inputEntry ) and process( inputEntry ); if entry then table.insert:addLine( getToC( galleryEntries, entry );) end end  return table.concat:addLine( getErrors( galleryEntries, '\n' );)end -- @name buildGallery-- TODOlocal function buildGallery :addLine( getGallery() ) local inner = buildInnerGallery :addLine( getCategories();) return table.concat :add( { '<gallery heights="175px" position="center" captionalign="center"/div>',) inner, ; '</gallery>' }, '\n' return buffer:toString();
end
-- @name main
-- @notes exportable
-- @description To be called through #invoke.
local function CardGallery.main( frame ) _D.errors _frame = {}frame; _D_args = UTIL.args = getArgs( frame, {
trim = true,
removeBlanks = true,
} );
getInfo();  local errors = printErrors(); local header = buildHeaderinitInfo(); local gallery = buildGalleryinitFiles();
return HTML( 'div' ):addClass( 'card-galleries' ) :node( tostring( header ) ) :newline() :node( errors ) :newline() :node( frame:preprocess( gallery ) ) :allDonerender();
end
------------ Return:------------ @exports return CardGallery{ ['main'] = main};-- </pre>
Bots, mover
37,923
edits

Navigation menu