Mudanças entre as edições de "Módulo:MapaJson"

De Wiki Gla
Ir para navegação Ir para pesquisar
 
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada)
Linha 2: Linha 2:


function p.getDados(frame)
function p.getDados(frame)
    -- Carrega o conteúdo da página JSON
     local pageName = frame.args[1] or ''
     local titulo = "Mapa:Blackmarket"
    local conteudo = mw.title.new(titulo):getContent()
      
      
     -- Transforma o texto JSON em uma tabela Lua
     if pageName == '' then
     local dados = mw.text.jsonDecode(conteudo)
        return ''
     end
      
      
     -- Exemplo: Pegar um valor específico chamado 'item'
     local title = mw.title.new(pageName)
     -- Você adapta isso conforme a estrutura do seu JSON
    if not title or not title.exists then
     return dados
        return ''
    end
   
    local jsonContent = title:getContent() or ''
   
     -- Apenas remover espaços extras
    jsonContent = jsonContent:gsub("\n", "")
    jsonContent = jsonContent:gsub("\r", "")
    jsonContent = jsonContent:gsub("\t", " ")
    jsonContent = jsonContent:gsub("  +", " ")
   
     return jsonContent
end
end


return p
return p

Edição atual tal como às 14h24min de 11 de abril de 2026

A documentação para este módulo pode ser criada em Módulo:MapaJson/doc

local p = {}

function p.getDados(frame)
    local pageName = frame.args[1] or ''
    
    if pageName == '' then
        return ''
    end
    
    local title = mw.title.new(pageName)
    if not title or not title.exists then
        return ''
    end
    
    local jsonContent = title:getContent() or ''
    
    -- Apenas remover espaços extras
    jsonContent = jsonContent:gsub("\n", "")
    jsonContent = jsonContent:gsub("\r", "")
    jsonContent = jsonContent:gsub("\t", " ")
    jsonContent = jsonContent:gsub("  +", " ")
    
    return jsonContent
end

return p