A Wiki in the Desert
Log in

Difference between revisions of "Module:HerbGallery"

From A Wiki in the Desert
Line 19: Line 19:
 
         local myResult = ""
 
         local myResult = ""
 
         for num, row in pairs( queryResult ) do
 
         for num, row in pairs( queryResult ) do
            myResult = myResult .. '* This is result #' .. num .. '\n'
 
 
             for property, data in pairs( row ) do
 
             for property, data in pairs( row ) do
 
                 local dataOutput = data
 
                 local dataOutput = data
 
                 if type( data ) == 'table' then
 
                 if type( data ) == 'table' then
                     dataOutput = mw.text.listToText( data, ', ', ' and ')
+
                     dataOutput = mw.text.listToText( data )
 
                 end
 
                 end
 
                 myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
 
                 myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'

Revision as of 02:43, 15 May 2021

Documentation for this module may be created at Module:HerbGallery/doc

local p = {} --p stands for package

function p.gallery( frame )
	if not mw.smw then
        return "mw.smw module not found"
    end

    if frame:getParent().args[1] == nil then
        return "no parameter found"
    end
    
    local queryResult = mw.smw.ask( frame:getParent().args )
    
	if queryResult == nil then
        return "(no values)"
    end

    if type( queryResult ) == "table" then
        local myResult = ""
        for num, row in pairs( queryResult ) do
            for property, data in pairs( row ) do
                local dataOutput = data
                if type( data ) == 'table' then
                    dataOutput = mw.text.listToText( data )
                end
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
            end
        end
        return myResult
    end

    return queryResult
end

return p