From Sandcat Browser

EDK: PreviewHandler

Sandcat 4.0 comes with response preview handlers for the most common web file formats. This includes CSS, Flash, HTML, common image formats (bmp, gif, ico, jpg, png and svg), JavaScript, JSON, text and XML files. This page explains how you can add support for additional response formats.

How to create a preview handler extension

In order to add a new preview handler, you must use the Sandcat:RegisterPreviewHandler() method. This method needs three parameters:


{
 "name": "My Preview Handler Extension",
 "version": "1.0",
 "author": "Syhunt Team",
 "script": {
  "filename": "mypreview.lua",
  "init": "MyPreview:register()",
 }
}

mypreview.lua:


MyPreview = {}

function MyPreview:register() -- will be called during startup
 Sandcat:RegisterPreviewHandler('mypreviewforfoo',self.HandleFoo,'foo','text/foo')
end

function MyPreview:HandleFoo(data)
 local source = data.responsetext
 -- do something with source here --
  data.previewhtml = '<b>Your preview html code</b>'
end

data will contain the following keys with details about the request being previewed:

contenttypestringThe content type extracted from the response headers
previewhtmlstringAllows you to set the HTML/CSS that will be loaded as the preview. JavaScript and TIScript are not allowed.
requestheadersstringAll the request headers
responsefilenamestringFilename of a temporary file containing the decompressed response stream
responseheadersstringAll the response headers
responsetextstringThe response as a text
urlstringThe request URL
warnemptybooleanIf set true, notifies Sandcat that the response is empty or incomplete
Retrieved from https://www.syhunt.com/sandcat/index.php?n=EDK.PreviewHandler
Page last modified on May 19, 2013, at 07:54 AM