Home Reference Source
public class | source

ui

Direct access to the HTML transcript.

Member Summary

Public Members
public

You may replace this property if you want to use a template language other than Nunjucks.

public
public

MarkdownIt instance used to render Markdown.

public

nunjucks instance used to render templates.

Method Summary

Public Methods
public

Make the given objects or values available to the template context.

public

Whenever a template is rendered, evaluate all these functions and make their return values available to the template context.

public

clear()

Remove all content from the transcript and start fresh.

public

presentChoices(arrayOfSituationIdsOrTags: string[]): *

Given an array of tags or situation IDs (can be both in the same array), present the relevant choices in the transcript using the logic in model.interpretChoices.

public

promptInput(options: Map<string, *>): Promise<string>

Force the user to enter some text to continue.

public

renderMarkdown(text: string, inline: Boolean): *

Render the given Markdown text to HTML.

public

renderMarkdownTemplate(src: string, args: Map<string, *>, inline: Boolean): *

Process the text as a template, render the resulting Markdown to HTML, and return the result.

public

Like renderMarkdownTemplate, but automatically sets inline flag based on presence of line breaks.

public

renderTemplate(src: string, args: Map<string, *> | null): *

Process the text as a template and return the result.

public

write(markdown: string, args: Map<string, *>)

Render the given HTML as a template and write it to the transcript WITHIN THE CURRENT SECTION.

public

writeHTML(html: string, args: Map<string, *>)

Render the given HTML as a template and write it to the transcript.

public

writeMarkdown(markdown: string, args: Map<string, *>)

Render the given string as a template, render the resulting Markdown as HTML, and write it to the transcript.

Public Members

public createTemplate(src: function(src: string): function): * source

You may replace this property if you want to use a template language other than Nunjucks.

It is a function that takes a string and returns a function that takes attrs and returns a rendered string. Like this:

(src) => (attrs) => render(src, attrs)

public director: * source

public md: MarkdownIt source

MarkdownIt instance used to render Markdown. You may use it to register additional plugins.

public nunjucks: * source

nunjucks instance used to render templates. You may use it to add custom tags, filters, or globals. (See the "Environment" section of this page.)

Public Methods

public addTemplateContext(fns: Map<string, function>) source

Make the given objects or values available to the template context.

Params:

NameTypeAttributeDescription
fns Map<string, function>

public addTemplateGetters(fns: Map<string, function>) source

Whenever a template is rendered, evaluate all these functions and make their return values available to the template context.

All template getters are called whenever you render any template.

Params:

NameTypeAttributeDescription
fns Map<string, function>

Example:


// If you add a getter like this:
jumbogrove.jumbogrove('#game', {
  init: (model, ui) => {
    ui.addTemplateGetters({
      randomNumber: () => Math.random()
    });
  }
});

// Then you may use it in a template like this:

`
{{ randomNumber }}
`

// and it will show the function's return value (in this case, a random
// number 0-1).

public clear() source

Remove all content from the transcript and start fresh.

public presentChoices(arrayOfSituationIdsOrTags: string[]): * source

Given an array of tags or situation IDs (can be both in the same array), present the relevant choices in the transcript using the logic in model.interpretChoices.

Params:

NameTypeAttributeDescription
arrayOfSituationIdsOrTags string[]

Array of strings containing either #tags or situation-ids.

Return:

*

public promptInput(options: Map<string, *>): Promise<string> source

Force the user to enter some text to continue.

Params:

NameTypeAttributeDescription
options Map<string, *>
options.placeholder string

Placeholder text for the input field

Return:

Promise<string>

public renderMarkdown(text: string, inline: Boolean): * source

Render the given Markdown text to HTML. Automatically dedents the text to the minimum indent level.

Params:

NameTypeAttributeDescription
text string
inline Boolean

If true, do not parse any block-level markup or wrap in a paragraph.

Return:

*

public renderMarkdownTemplate(src: string, args: Map<string, *>, inline: Boolean): * source

Process the text as a template, render the resulting Markdown to HTML, and return the result. Automatically dedents the text to the minimum indent level.

Params:

NameTypeAttributeDescription
src string
args Map<string, *>

Additional template context

inline Boolean

If true, do not parse any block-level markup or wrap in a paragraph.

Return:

*

public renderMarkdownTemplateMaybeInline(src: string, args: Map<string, *>, inline: Boolean): * source

Like renderMarkdownTemplate, but automatically sets inline flag based on presence of line breaks.

Params:

NameTypeAttributeDescription
src string
args Map<string, *>

Additional template context

inline Boolean

If true, do not parse any block-level markup or wrap in a paragraph.

Return:

*

public renderTemplate(src: string, args: Map<string, *> | null): * source

Process the text as a template and return the result.

Params:

NameTypeAttributeDescription
src string
args Map<string, *> | null

Additional template context

Return:

*

public write(markdown: string, args: Map<string, *>) source

Render the given HTML as a template and write it to the transcript WITHIN THE CURRENT SECTION. If you are writing HTML from inside an action function, this is probably what you want.

Params:

NameTypeAttributeDescription
markdown string
args Map<string, *>

Additional template context

public writeHTML(html: string, args: Map<string, *>) source

Render the given HTML as a template and write it to the transcript. Links are automatically bound to actions and situation transitions.

The output comes after ALL HTML in the current section, If you are presenting a choice, the HTML will be written BELOW the choice.

Params:

NameTypeAttributeDescription
html string
args Map<string, *>

Additional template contet

public writeMarkdown(markdown: string, args: Map<string, *>) source

Render the given string as a template, render the resulting Markdown as HTML, and write it to the transcript.

The output comes after ALL HTML in the current section, If you are presenting a choice, the text will be written BELOW the choice.

Params:

NameTypeAttributeDescription
markdown string
args Map<string, *>

Additional template context