Constructor
new DocumentBuilder(inputopt, parentopt)
- Source:
Example
const doc = new DocumentBuilder()
.setTitle("Check this out!")
.setSubtitle("Example Service")
.setLogo("https://cdn.service.example/logo.png", 1)
.addFields(
{"name": "Name", "value": "Lady Sampleton", "inline": true},
{"name": "Age", "value": "42", "inline": true}
)
.addGallery(
"https://cdn.service.example/images/1",
"https://cdn.service.example/images/2",
);
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
input |
RichToken | Array.<RichToken> |
<optional> |
A rich token document to initialize this builder with. |
parent |
DocumentBuilder |
<optional> |
A parent |
Methods
add(token) → {DocumentBuilder}
- Source:
Add a token to the end of the document.
Parameters:
Name | Type | Description |
---|---|---|
token |
RichToken | The token to be added. |
Returns:
this
- Type
- DocumentBuilder
addConditional(mediaopt, nsfwopt, contentopt, alternativeopt) → {DocumentBuilder}
- Source:
Add a new conditional to the end of the document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
media |
Boolean |
<optional> |
Whether or not media is required to be true or false for this conditional. Media is ignored if this is null-ish. |
nsfw |
Boolean |
<optional> |
Whether or not NSFW is required to be true or false for this conditional. NSFW is ignored if this is null-ish. |
content |
String | Array.<RichToken> | DocumentBuilder |
<optional> |
Content to include when the condition passes. |
alternative |
String | Array.<RichToken> | DocumentBuilder |
<optional> |
Content to include when the condition fails. |
Returns:
this
- Type
- DocumentBuilder
addField(name, value, inlineopt) → {DocumentBuilder}
- Source:
Add a single field to the end of the document.
See DocumentBuilder#addFields
for more details.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String | Array.<RichToken> | The name to display for the field. |
||
value |
String | Array.<RichToken> | The value to display for the field. |
||
inline |
Boolean |
<optional> |
false
|
Whether or not the field should display in-line. |
Returns:
this
- Type
- DocumentBuilder
addFields(…fields) → {DocumentBuilder}
- Source:
Add fields to the end of the document, using the fieldset
token.
If the last token in the document is a fieldset, these fields will be added to that token. Otherwise, a new fieldset token will be added to the end of the document.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fields |
Field |
<repeatable> |
The fields to be added. |
Returns:
this
- Type
- DocumentBuilder
addHeader(titleopt, subtitleopt, imageopt, optsopt) → {DocumentBuilder}
- Source:
Add a new header to the end of the document.
See the header token in {@template responses} for more information. The header must have at least one of an image, title, or subtitle.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
title |
String | Array.<RichToken> |
<optional> |
The title for the header. |
||||||||||||||||
subtitle |
String | Array.<RichToken> |
<optional> |
The subtitle for the header. |
||||||||||||||||
image |
String | URL | RichToken |
<optional> |
The image for the header. |
||||||||||||||||
opts |
Object |
<optional> |
Options for the header token. Properties
|
Returns:
this
- Type
- DocumentBuilder
build(recurseopt) → {Array.<Object>}
- Source:
Return an object representing the content of this builder. May
be an array of tokens, a single token, or null
.
If this builder is the child of another builder, this method
will instead return an object representing the content of
that builder. Calling build()
on any part of a nested
structure of DocumentBuilder
s returns the entire
structure, unless you set recurse
to false
here.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
recurse |
Boolean |
<optional> |
true
|
Whether or not to return the entire document and not just this specific DocumentBuilder. |
Returns:
Rich Token Document
- Type
- Array.<Object>
content(attropt) → {DocumentBuilder}
- Source:
Drop into the content of the last token added to the builder.
Example
const data = new DocumentBuilder()
.addConditional(true)
.content()
.addImage(my_image)
.end()
.content('alternative)
.add('There was an image here, but you don\'t see those.')
.end()
.build();
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
attr |
String |
<optional> |
'content'
|
The name of the attribute to drop into. By
default this is just |
Returns:
A builder representing the content of the token.
- Type
- DocumentBuilder
done() → {DocumentBuilder}
- Source:
Return to the top level DocumentBuilder
.
Returns:
The top level of this builder tree.
- Type
- DocumentBuilder
end() → {DocumentBuilder}
- Source:
Return to the parent DocumentBuilder
. For use with content
.
Returns:
The parent builder
- Type
- DocumentBuilder
setBackground(background) → {DocumentBuilder}
- Source:
Set the background of this document's primary header. If no primary header exists, one will be created with this background.
See DocumentBuilder#setBackground
for more details.
Parameters:
Name | Type | Description |
---|---|---|
background |
String | RichToken | The background to set. This should be an image. |
Returns:
this
- Type
- DocumentBuilder
setCompactHeader(compactopt) → {DocumentBuilder}
- Source:
Set the compact flag of this document's primary header. If no primary header exists, one will be created with this flag.
See DocumentBuilder#setHeader
for more details.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
compact |
Boolean |
<optional> |
true
|
Whether or not the header should be compact. |
Returns:
this
- Type
- DocumentBuilder
setExtra(extra) → {DocumentBuilder}
- Source:
Set the extra of this document's primary header. If no primary header exists, one will be created with this extra.
See DocumentBuilder#setHeader
for more details.
Parameters:
Name | Type | Description |
---|---|---|
extra |
String | RichToken | Array.<RichToken> | The extra to set. Can be made of rich tokens. |
Returns:
this
- Type
- DocumentBuilder
setFooter(titleopt, subtitleopt, imageopt, optsopt) → {DocumentBuilder}
- Source:
Set the document's primary footer.
The primary footer is always the last token output from a builder,
no matter what other content is added to the builder. The footer
is a header
token. See the header token in {@template responses}
for more information.
The footer must have at least one of an image, title, or subtitle.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
title |
String | Array.<RichToken> |
<optional> |
The title for the header. |
|||||||||||||||||||||||||
subtitle |
String | Array.<RichToken> |
<optional> |
The subtitle for the header. |
|||||||||||||||||||||||||
image |
String | URL | RichToken |
<optional> |
The image for the header. |
|||||||||||||||||||||||||
opts |
Object |
<optional> |
Options for the header token. Properties
|
Returns:
this
- Type
- DocumentBuilder
setHeader(titleopt, subtitleopt, imageopt, optsopt) → {DocumentBuilder}
- Source:
Set the document's primary header.
The primary header is always the first token output from a builder,
no matter what other content is added to the builder. The header
is a header
token. See the header token in {@template responses}
for more information.
The header must have at least one of an image, title, or subtitle.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
title |
String | Array.<RichToken> |
<optional> |
The title for the header. |
||||||||||||||||||||||||
subtitle |
String | Array.<RichToken> |
<optional> |
The subtitle for the header. |
||||||||||||||||||||||||
image |
String | URL | RichToken |
<optional> |
The image for the header. |
||||||||||||||||||||||||
opts |
Object |
<optional> |
Options for the header token. Properties
|
Returns:
this
- Type
- DocumentBuilder
setLogo(url, optsopt) → {DocumentBuilder}
- Source:
Set the logo of this document's primary header. If no primary header exists, one will be created with this logo.
Logos are 48px tall for standard headers, and 24px tall for compact headers.
See DocumentBuilder#setHeader
for more details.
See the responses tutorial's section on Image Tokens for more.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | Object | The image to use for a logo. This can be an image
token, a pair of |
||||||||||||||||||||||||||
opts |
Object |
<optional> |
Options for the token. Properties
|
Returns:
this
- Type
- DocumentBuilder
setSFWLogo(url, optsopt) → {DocumentBuilder}
- Source:
Set the SFW logo of this document's primary header. If no primary header exists, one will be created with this SFW logo.
Logos are 48px tall for standard headers, and 24px tall for compact headers.
See DocumentBuilder#setHeader
for more details.
See the responses tutorial's section on Image Tokens for more.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | Object | The image to use for a logo. This can be an image
token, a pair of |
||||||||||||||||||||||||||
opts |
Object |
<optional> |
Options for the token. Properties
|
Returns:
this
- Type
- DocumentBuilder
setSubtitle(subtitle) → {DocumentBuilder}
- Source:
Set the subtitle of this document's primary header. If no primary header exists, one will be created with this subtitle.
See DocumentBuilder#setHeader
for more details.
Parameters:
Name | Type | Description |
---|---|---|
subtitle |
String | RichToken | Array.<RichToken> | The subtitle to set. Can be made of rich tokens. |
Returns:
this
- Type
- DocumentBuilder
setTitle(title) → {DocumentBuilder}
- Source:
Set the title of this document's primary header. If no primary header exists, one will be created with this title.
See DocumentBuilder#setHeader
for more details.
Parameters:
Name | Type | Description |
---|---|---|
title |
String | RichToken | Array.<RichToken> | The title to set. Can be made of rich tokens. |
Returns:
this
- Type
- DocumentBuilder