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

local p = mw.InfoboxBuilderHF
local getArgs = require('Módulo:Arguments').getArgs

--------------------------------------------------------------------------------------------------
-- retorna o conteúdo da página
function p.get_content(pagename)
	local output = ''
	
	if not p.isempty(pagename)
		then output = mw.title.new(p.break_link(pagename,1)):getContent() or ''
	end
	
	return output
end

--------------------------------------------------------------------------------------------------
-- returns value of 'field' from 'page_content'
function p.get_field_value(page_content, field)
	local output = ''
	
	if not p.isempty(page_content) and not p.isempty(field)
		then 
			output = string.match(page_content, '|%s-'..field..'%s-=%s-(.-)\n|')
			if not p.isempty(output)
				then output = p.trim(output)
			end
	end

	return output
end

--------------------------------------------------------------------------------------------------
-- Check if 'text' is part of the 'list' or not
function p.in_list(list, text)
	local output = false

	if not p.isempty(list) and not p.isempty(text)
		then
			for i, v in ipairs( list ) do
				if v == text
					then 
						output = true 
						break
				end
			end
	end

	return output
end

--------------------------------------------------------------------------------------------------
-- adds all elements from 'table2' into 'table1'; first, second, both or none of them could be tables or strings
function p.join_tables(table1, table2)
	local output = {}
	
	if not p.isempty(table1)
		then 
			if type(table1) == "table"  
				then output = table1
				else table.insert(output, table1)
			end
	end

	if not p.isempty(table2)
		then
			if type(table2) == "table"
				then
					for i = 1, #table2 do
						table.insert(output, table2[i])
					end
				else
					table.insert(output, table2)
			end
	end

	return output
end

--------------------------------------------------------------------------------------------------
--checks if 'page' exists or not
function p.exists(page)
	local title
	local output = false
	
	if not p.isempty(page) 
		then 
			title = mw.title.new(page)
			if title ~= nil and title.exists
				then output = true
			end
	end
	title = nil
	return output
end

--------------------------------------------------------------------------------------------------
--returns true if text is a wikilink or false otherwise
function p.is_link(link)
	local i
	local j
	local output = false
 
	if not p.isempty(link)
		then
			i = string.find(link, "^%[%[")
			j = string.find(link, "%]%]$")
			if i ~= nil and j ~= nil
				then output = true
			end
	end
	
	return output
end

--------------------------------------------------------------------------------------------------
--Check if 'link' is a wikilink. If yes, then check if it has | inside. If yes, then return 'part' part of it. If 'link' is not a wikilink return 'link'.
function p.break_link(link, part)
	local i
	local j
	local k
	local output = ''
	
	if not p.isempty(link) and p.is_link(link)
		then
			i = string.find(link, "[[",1,true)
			j = string.find(link, "|",1,true)
			k = string.find(link, "]]",1,true)
			if j == nil 
				then output = string.sub(link, i+2, k-1) 
				elseif j < k
					then 
						if part == 2 
							then output = string.sub(link, j+1, k-1)
							else output = string.sub(link, i+2, j-1)
						end
				else output = string.sub(link, i+2, k-1)  
			end
		else output = link
	end

	return output
end


function p.breaklink(frame)
	return p.break_link(frame.args[1], tonumber(frame.args[2]))
end

--------------------------------------------------------------------------------------------------
-- retorna o número de páginas na "categoria", "tipo de página" pode ser '*', 'todos', 'páginas', 'subcategorias' ou 'arquivos'
function p.pages_in_category(category, pagetype)
	local output = 0
	pagetype = pagetype or 'pages'

	if not p.isempty(category)
		then
		output = string.gsub(category, '&#39;',"'")
		output = mw.site.stats.pagesInCategory(output, pagetype)
	end

	return output
end

--------------------------------------------------------------------------------------------------
-- adiciona cada elemento da tabela de 'categorys' como category com 'classificarnome'.
-- Elements of 'categorys' table could be strings or tables themselves with second element being a different classificarnome
function p.add_categories(categories, classificarnome)
	local i
	local category
	local output = {}
 
	if not p.isempty(categories) and type(categories) == 'table'
		then
			for i = 1,#categories do
				category = categories[i]
				if not p.isempty(category)
					then 
						if type(category) == 'table'
							then table.insert( output, p.Category(category[1], category[2]) )
							else table.insert( output, p.Category(category, classificarnome) )
						end
				end
			end
	end
 
	return table.concat(output)
end


--------------------------------------------------------------------------------------------------
--transform 'number' into ordinal number, for example '1' into '1st'
function p.numero_ordinal(numero)
	local output = ''
	
	numero = tonumber(numero)
	if not p.isempty(numero)
		then
			if numero % 10 == 1 and numero ~= 11 -- in (1,21,31,41,51,61,71)
				then output = numero..'ª'
				elseif numero % 10 == 2 and numero ~= 12 -- in (2,22,32,42,52,62,72)
					then output = numero..'ª'
					elseif numero % 10 == 3 and numero ~= 13 --in (3,23,33,43,53,63,73)
						then output = numero..'ª'
						else output = numero..'ª'
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p._HelpButton( args )
  if p.isempty( args.buttonsize ) then args.buttonsize = "10px" end
  local target = args.ArticleTarget or "Clique aqui para obter ajuda neste campo"
	local link = string.format(
		"[[Arquivo:Information-silk.png|%s|link=Clique aqui para obter ajuda neste campo#%s]] %s",
		args.buttonsize,
		args.Section or args.Label or '',
	args.Label or ''
	)
  return link
end


function p.HelpButton( frame )
	local args = getArgs( frame )
	return p._HelpButton( args )
end

--------------------------------------------------------------------------------------------------
function p.AddZeros( s, len )
  local output = ""

  local sLength = string.len( tostring( s ) )
  local diff = tonumber( len ) - tonumber( sLength )

  if diff > 0 then
    for i = 1, diff do
      output = string.format('%s0', output)
    end
  end

  output = string.format('%s%s', output, s)

  return output
end

return p
O conteúdo da comunidade está disponível sob CC-BY-SA salvo indicação em contrário.