Module:Message box: Difference between revisions

remove the presentButBlank function, fix bug with blank date values, and trim whitespace from all arguments
en>Mr. Stradivarius
(change the smalltext logic to work with collapsible text fields)
en>Mr. Stradivarius
(remove the presentButBlank function, fix bug with blank date values, and trim whitespace from all arguments)
Line 13: Line 13:
local tinsert = table.insert
local tinsert = table.insert
local tconcat = table.concat
local tconcat = table.concat
local trim = mw.text.trim


local box = {}
local box = {}
Line 24: Line 25:
             return title
             return title
         end
         end
    end
end
local function presentButBlank(s)
    if type(s) ~= 'string' then return end
    if s and not mw.ustring.find(s, '%S') then
        return true
    else
        return false
     end
     end
end
end
Line 219: Line 211:
             self.issue = args.smalltext
             self.issue = args.smalltext
         else
         else
             local sect = args.sect
             local sect
             if presentButBlank(sect) then
             if args.sect == '' then
                 sect = 'This ' .. (cfg.sectionDefault or 'page')
                 sect = 'This ' .. (cfg.sectionDefault or 'page')
             elseif type(sect) == 'string' then
             elseif type(args.sect) == 'string' then
                 sect = 'This ' .. sect
                 sect = 'This ' .. sect
            else
                sect = nil
             end
             end
             local issue = args.issue
             local issue = args.issue
Line 240: Line 230:
         -- Get the self.talk value.
         -- Get the self.talk value.
         local talk = args.talk
         local talk = args.talk
         if presentButBlank(talk) and self.isTemplatePage then
         if talk == '' and self.isTemplatePage then
             talk = '#'
             talk = '#'
         end
         end
Line 267: Line 257:
         -- Get other values.
         -- Get other values.
         self.fix = args.fix
         self.fix = args.fix
         local date = args.date
         if args.date and args.date ~= '' then
        self.date = date and format(" <small>''(%s)''</small>", date)
            self.date = format(" <small>''(%s)''</small>", args.date)
         if presentButBlank(self.date) and self.isTemplatePage then
         elseif args.date == '' and self.isTemplatePage then
             self.date = lang:formatDate('F Y')
             self.date = lang:formatDate('F Y')
         end
         end
Line 536: Line 526:
         -- assume args are being passed directly in from the debug console
         -- assume args are being passed directly in from the debug console
         -- or from another Lua module.
         -- or from another Lua module.
         local args
         local origArgs
         if frame == mw.getCurrentFrame() then
         if frame == mw.getCurrentFrame() then
             args = frame:getParent().args
             origArgs = frame:getParent().args
             for k, v in pairs(frame.args) do
             for k, v in pairs(frame.args) do
                 args = frame.args
                 origArgs = frame.args
                 break
                 break
             end
             end
         else
         else
             args = frame
            origArgs = frame
        end
        -- Trim whitespace.
        local args = {}
        for k, v in pairs(origArgs) do
            if type(v) == 'string' then
                v = trim(v)
            end
             args[k] = v
         end
         end
         return makeBox(boxType, args)
         return makeBox(boxType, args)
Anonymous user