Module:Pdf thumbnail

From Wikisphere
Jump to navigation Jump to search

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

local p = {}

local function trim(s)
	return mw.ustring.gsub(mw.ustring.gsub(s, '%s', ' '), '^%s*(.-)%s*$', '%1')
end


function p.main(frame)

	local origArgs = (type(frame.getParent) == 'function') and frame:getParent().args or frame
 --   local origArgs = frame:getParent().args
    

--{{Pdf thumbnail | filename | caption | float = left/right/none (default: none) | clear after = --true/false (default: false) }}


  if(origArgs[1] == nil) then
    return ''
  end

  origArgs[1] = trim(origArgs[1])

  if(origArgs[2] ~= nil) then
     origArgs[2] = trim(origArgs[2])
  else
     origArgs[2] = ''
  end

  if(origArgs.float == nil or (origArgs.float ~= "left" and origArgs.float ~= "right")) then
     origArgs.float = "none"    
  end

  local str = '<div style="clear:' .. origArgs.float .. '" class="thumb'

  if(origArgs.float ~= "none") then
    str = str .. " t" .. origArgs.float
  end

  local image_url = string.gsub( origArgs[1], " ", "_" )
  stringtoboolean={ ["true"]=true,["1"]=true,["yes"]=true, ["false"]=false, ["0"]=false, ["no"]=false }

  str = str .. '"><div class="thumbinner" style="width:302px;">[[File:' .. origArgs[1] .. '|300px|link=https://wikisphere.org/w/media/' .. image_url .. ']]<div class="thumbcaption"><div class="magnify"><a href="/wiki/File:'  .. image_url  .. '" class="internal" title="Enlarge"></a></div>' .. origArgs[2] .. '</div></div></div>'


   if(origArgs.clear ~= nil and stringtoboolean[origArgs.clear]) then 
     str = str .. '<div style="clear:both"></div>'
   end


	 mw.log('str')
	 mw.log(str)



   return str
 

end
-- =p.main({"filename a","caption a",float="left",clear="true"})
return p