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β
β³
PreviewDriver
Constructorsβ
constructorβ
β’ new PreviewDriver(_target
, _onGhostlyEvent?
)
Parametersβ
Name | Type | Description |
---|---|---|
_target | string | The name of the IFrame to control. |
_onGhostlyEvent? | OnGhostlyEvent | The default event handler to use. Defauts to just logging the event to the console. |
Overridesβ
Defined inβ
ghostly-runtime/src/driver.ts:86
Propertiesβ
_targetβ
β’ Protected
_target: string
_templateβ
β’ Protected
Optional
_template: string
Inherited fromβ
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β
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β
Name | Type |
---|---|
info | AttachmentInfo <unknown > |
Returnsβ
Promise
<GhostlyTypes
>
Inherited fromβ
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β
Name | Type |
---|---|
model | Model |
Returnsβ
Promise
<undefined
| ModelInfo
>
Inherited fromβ
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β
Name | Type |
---|---|
template | string |
Returnsβ
Promise
<void
>
Inherited fromβ
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β
Name | Type |
---|---|
command | PreviewCommand |
Returnsβ
Promise
<PreviewResult
>
Inherited fromβ
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β
Name | Type |
---|---|
view | View <unknown > |
Returnsβ
Promise
<GhostlyTypes
>
Inherited fromβ
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β
Name | Type | Description |
---|---|---|
template | string | The URL to the Ghostly template to use. |
document | string | object | The model data, as JSON or a string. |
contentType | string | The model's media type, used as an indication to the template how document should be parsed. |
params? | unknown | Optional view params (as JSON). |
onGhostlyEvent? | OnGhostlyEvent | Optional 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β
Name | Type | Description |
---|---|---|
request | GhostlyRequest | The raw request to send. |
Returnsβ
Promise
<GhostlyTypes
>
The unpacked response.
Overridesβ
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.