Content deleted Content added
use a class-making function for new classes, use a _type field and _inherits table to track object type and inheritance, revamp checkObject and makeCheckSelfFunction |
make a start on the export method |
||
Line 15:
-- Helper functions
----------------------------------------------------------
-- Function allowing for consistent treatment of boolean-like wikitext input.
-- It works similarly to the template {{yesno}}.
local function yesno( val, default )
val = type( val ) == 'string' and mw.ustring.lower( val ) or val -- put in lower case
if not val or val == 'no' or val == 'n' or val == 'false' or tonumber( val ) == 0 then
return false
elseif val == true or val == 'yes' or val == 'y' or val == 'true' or tonumber( val ) == 1 then
return true
else
return default
end
-- Checks to see if a given variable is a non-blank string. Returns the string if true,
Line 739 ⟶ 752:
rowContentOutput = checkString( rowContentOutput )
-- Export the row
local ret = htmlBuilder.create()
if rowIconOutput and rowContentOutput then
Line 773 ⟶ 786:
if obj and type( obj.setFaGrade ) == 'function' then
self.qualityScale = obj
end
Line 937 ⟶ 950:
end
-- Sets the quality row.
function banner:setQualityRow( obj )
checkSelfBanner( self, 'setQualityRow' )
if checkObject( obj, 'qualityRow' ) then
self.rows = self.rows or {}
self.rows.qualityRow = obj
end
end
-- Gets the quality row, if it is set.
checkSelfBanner( self, 'getQualityRow' )
self.rows = self.rows or {}
return self.rows.qualityRow
end
-- Sets the importance row.
function banner:setImportanceRow( obj )
checkSelfBanner( self, 'setImportanceRow' )
if checkObject( obj, 'importanceRow' ) then
self.rows = self.rows or {}
self.rows.importanceRow = obj
end
end
-- Gets the importance row, if it is set.
▲function banner:export()
function banner:getImportanceRow()
checkSelfBanner( self, 'getImportanceRow' )
self.rows = self.rows or {}
return self.rows.importanceRow
end
-- Exports a header listing the project name and any applicable task forces.
function banner:exportProjectHeader( args )
checkSelfBanner( self, 'exportProjectHeader' )
-- TODO: add this code.
end
-- Exports the banner to wikitext. The args are the arguments passed from the template invocation.
function banner:export( args )
checkSelfBanner( self, 'export' )
args = type( args ) == 'table' and args or {}
for i, row in ipairs( banner.rows ) do▼
self.rows = self.rows or {}
▲ end
end
rowOutput = table.concat( rowOutput )
-- Build the banner table.
local root = htmlBuilder.create( 'table' )
root
.addClass( 'tmbox' )
.addClass( 'tmbox-notice' )
.addClass( 'collapsible' )
.addClass( 'innercollapse' )
.addClass( 'wpb' )
.addClass( yesno( args.small ) and 'mbox-small' )
.css( 'height', '0px' ) -- Valid HTML5 substitute for height="0"?
.tag( 'tr' )
.addClass( 'wpb-header' )
local projectHeader = root.tag( 'tr' )
if not self:getQualityRow() or not self:getImportanceRow() then
projectHeader
.tag( 'td' )
.addClass( 'mbox-empty-cell' )
.done()
.tag( 'th' )
.css( 'width', '100%' )
.css( 'padding', '0.3em' )
.wikitext( self:exportProjectHeader( args ) )
else
projectHeader
.tag( 'td' )
.css( 'text-align', 'right' )
.css( 'padding', '0.3em 1em 0.3em 0.3em' )
.css( 'width', '50%' )
.css( 'font-weight', 'bold' )
.wikitext( self:exportProjectHeader( args ) )
end
return tostring( root )
end
Line 968 ⟶ 1,049:
function p.test( frame )
local
return mybanner:export()
end
|