Skip to main content

Class: PreviewDriver

ghostly-runtime.PreviewDriver

A utility class for rendering a template as HTML to an IFrame in a web browser (not using Ghostly Engine.

Hierarchy​

Constructors​

constructor​

β€’ new PreviewDriver(_target, _onGhostlyEvent?)

Parameters​

NameTypeDescription
_targetstringThe name of the IFrame to control.
_onGhostlyEvent?OnGhostlyEventThe default event handler to use. Defauts to just logging the event to the console.

Overrides​

TemplateDriver.constructor

Defined in​

ghostly-runtime/src/driver.ts:86

Properties​

_target​

β€’ Protected _target: string


_template​

β€’ Protected Optional _template: string

Inherited from​

TemplateDriver._template

Defined in​

ghostly-runtime/src/driver.ts:5

Methods​

clearPreview​

β–Έ clearPreview(): Promise<void>

Clears the preview IFrame by loading about:blank.

Returns​

Promise<void>

Defined in​

ghostly-runtime/src/driver.ts:163


ghostlyEnd​

β–Έ ghostlyEnd(): Promise<void>

This optional method is invoked when all processing of the model is done. May be used to purge caches and other resources.

Returns​

Promise<void>

Inherited from​

TemplateDriver.ghostlyEnd

Defined in​

ghostly-runtime/src/driver.ts:54


ghostlyFetch​

β–Έ ghostlyFetch(info): Promise<GhostlyTypes>

Asks the template to render an attachment. This call should not return or resolve until the attachment is stable and fully rendered.

Parameters​

NameType
infoAttachmentInfo<unknown>

Returns​

Promise<GhostlyTypes>

Inherited from​

TemplateDriver.ghostlyFetch

Defined in​

ghostly-runtime/src/driver.ts:39


ghostlyInit​

β–Έ ghostlyInit(model): Promise<undefined | ModelInfo>

Used to supply the model (data) that the template should render from.

Parameters​

NameType
modelModel

Returns​

Promise<undefined | ModelInfo>

Inherited from​

TemplateDriver.ghostlyInit

Defined in​

ghostly-runtime/src/driver.ts:12


ghostlyLoad​

β–Έ ghostlyLoad(template): Promise<void>

This optional method will be invoked once the template has been loaded by the browser, or each time the fragment part (hash) changes in a cached template.

Parameters​

NameType
templatestring

Returns​

Promise<void>

Inherited from​

TemplateDriver.ghostlyLoad

Defined in​

ghostly-runtime/src/driver.ts:7


ghostlyPreview​

β–Έ ghostlyPreview(command?): Promise<PreviewResult>

This method is used by the PreviewDriver to print and to find out the preferred size of the IFrame.

Parameters​

NameType
commandPreviewCommand

Returns​

Promise<PreviewResult>

Inherited from​

TemplateDriver.ghostlyPreview

Defined in​

ghostly-runtime/src/driver.ts:43


ghostlyRender​

β–Έ ghostlyRender(view): Promise<GhostlyTypes>

Asks the template to render a specific view. This call should not return or resolve until the view is stable and fully rendered.

Parameters​

NameType
viewView<unknown>

Returns​

Promise<GhostlyTypes>

Inherited from​

TemplateDriver.ghostlyRender

Defined in​

ghostly-runtime/src/driver.ts:35


print​

β–Έ print(): void

Prompt the user to print current view.

Returns​

void

Defined in​

ghostly-runtime/src/driver.ts:187


renderPreview​

β–Έ renderPreview(template, document, contentType, params?, onGhostlyEvent?): Promise<PreviewAttachment[]>

Renders the provided model as HTML to the target IFrame, and then returns all attachments.

Note that all attachments are returned as-is from the template, so if an attachment is supposed to be rendered by the engine, data will be null. Only attachments where the template returns actual data will work.

Note that ghostlyEnd will not be invoked by this method, since that would affect the preview result.

Parameters​

NameTypeDescription
templatestringThe URL to the Ghostly template to use.
documentstring | objectThe model data, as JSON or a string.
contentTypestringThe model's media type, used as an indication to the template how document should be parsed.
params?unknownOptional view params (as JSON).
onGhostlyEvent?OnGhostlyEventOptional event handler to use. Will fallback to the default event handler if unspecified.

Returns​

Promise<PreviewAttachment[]>

An array of PreviewAttachment objects representing all attachments the template produced.

Defined in​

ghostly-runtime/src/driver.ts:108


sendMessage​

β–Έ Protected sendMessage(request): Promise<GhostlyTypes>

A browser-only implementation that just sends the message and directly unpacks the response.

Parameters​

NameTypeDescription
requestGhostlyRequestThe raw request to send.

Returns​

Promise<GhostlyTypes>

The unpacked response.

Overrides​

TemplateDriver.sendMessage

Defined in​

ghostly-runtime/src/driver.ts:214


target​

β–Έ Protected target(): HTMLIFrameElement

Returns the target IFrame based on the _target constructor parameter. May be overridden.

Returns​

HTMLIFrameElement

The IFrame to preview the template in.

Defined in​

ghostly-runtime/src/driver.ts:198