A Wiki in the Desert
Log in

Difference between revisions of "Module:HerbGallery"

From A Wiki in the Desert
Line 1: Line 1:
 
local p = {} --p stands for package
 
local p = {} --p stands for package
 
local g = require('Gallery')
 
  
 
function p.gallery( frame )
 
function p.gallery( frame )
Line 8: Line 6:
 
end
 
end
  
if not g then
+
    if frame.args[1] == nil then
         return "mw.Gallery module not found"
+
         return "no parameter found"
 
     end
 
     end
 +
   
 +
    local queryResult = mw.smw.ask( frame.args )
  
     if frame:getParent().args[1] == nil then
+
     if queryResult == nil then
         return "no parameter found"
+
         return "(no values)"
 
     end
 
     end
      
+
 
    local myresult = ""
+
     if type( queryResult ) == "table" then
    for num, row in pairs( frame:getParent().args ) do
+
        local myResult = ""
    myresult = myresult .. ' ' .. num .. ' ' .. type(row) .. '\n'
+
        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, ', ', ' and ')
 +
                end
 +
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
 +
            end
 +
        end
 +
        return myResult
 
     end
 
     end
   
+
 
     return frame:getParent().args[1]
+
     return queryResult
 
end
 
end
  
 
return p
 
return p

Revision as of 02:57, 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.args[1] == nil then
        return "no parameter found"
    end
    
    local queryResult = mw.smw.ask( frame.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, ', ', ' and ')
                end
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
            end
        end
        return myResult
    end

    return queryResult
end

return p