new WithFragments()
Functions to access fragments: superclass for Document and Doc (from Group), not supposed to be created directly
- Source:
Methods
asHtml(linkResolver) → {string}
Transforms the whole document as an HTML output. Each fragment is separated by a <section> tag,
with the attribute data-field="nameoffragment"
Note that most of the time you will not use this method, but read fragment independently and generate
HTML output for StructuredText fragment with that class' asHtml method.
Parameters:
Name | Type | Description |
---|---|---|
linkResolver |
function |
- Source:
Returns:
- The HTML output
- Type
- string
asText() → {string}
Turns the document into a useable text version of it.
- Source:
Returns:
- basic text version of the fragment
- Type
- string
get(name) → {object}
Gets the fragment in the current Document object. Since you most likely know the type
of this fragment, it is advised that you use a dedicated method, like get StructuredText() or getDate(),
for instance.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.author" |
- Source:
Returns:
- The JavaScript Fragment object to manipulate
- Type
- object
getAll(name) → {array}
Builds an array of all the fragments in case they are multiple.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the multiple fragment to get, with its type; for instance, "blog-post.author" |
- Source:
Returns:
- An array of each JavaScript fragment object to manipulate.
- Type
- array
getBoolean(name) → {boolean}
Gets a boolean value of the fragment in the current Document object, for further manipulation.
This works great with a Select fragment. The Select values that are considered true are (lowercased before matching): 'yes', 'on', and 'true'.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.enableComments" |
- Source:
Returns:
- The boolean value of the fragment
- Type
- boolean
Example
if(document.getBoolean('blog-post.enableComments')) { ... }
getColor(name) → {string}
Gets the Color fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "product.color" |
- Source:
Returns:
- The string value of the Color fragment.
- Type
- string
Example
document.getColor('product.color')
getDate(name) → {Date}
Gets the date fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.publicationdate" |
- Source:
Returns:
- The Date object to manipulate
- Type
- Date
Example
document.getDate('blog-post.publicationdate').asHtml(linkResolver)
getGeoPoint(name) → {GeoPoint}
Gets the GeoPoint fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.location" |
- Source:
Returns:
- The GeoPoint object to manipulate
- Type
- GeoPoint
Example
document.getGeoPoint('blog-post.location').asHtml(linkResolver)
getGroup(name) → {Group}
Gets the Group fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "product.gallery" |
- Source:
Returns:
- The Group fragment to manipulate.
- Type
- Group
Example
document.getGroup('product.gallery').asHtml(linkResolver).
getHtml(name, linkResolver) → {string}
Shortcut to get the HTML output of the fragment in the current document.
This is the same as writing document.get(fragment).asHtml(linkResolver);
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.body" |
linkResolver |
function |
- Source:
Returns:
- The HTML output
- Type
- string
getImage(fragment) → {ImageEl}
Gets the image fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
fragment |
string | The name of the fragment to get, with its type; for instance, "blog-post.photo" |
- Source:
Returns:
- The Image object to manipulate
- Type
- ImageEl
Example
document.getImage('blog-post.photo').asHtml(linkResolver)
getImageView(name-) → {ImageView}
Gets the view within the image fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name- |
string | The name of the fragment to get, with its type; for instance, "blog-post.photo" |
- Source:
Returns:
view - The View object to manipulate
- Type
- ImageView
Example
document.getImageView('blog-post.photo', 'large').asHtml(linkResolver)
getLink(name) → {WebLink|DocumentLink|ImageLink}
Gets the Link fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.link" |
- Source:
Returns:
- The Link fragment to manipulate.
- Type
- WebLink | DocumentLink | ImageLink
Example
document.getLink('blog-post.link').url(resolver)
getNumber(name) → {number}
Gets the Number fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "product.price" |
- Source:
Returns:
- The number value of the fragment.
- Type
- number
Example
document.getNumber('product.price')
getStructuredText(name) → {StructuredText}
Gets the StructuredText fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.body" |
- Source:
Returns:
- The StructuredText fragment to manipulate.
- Type
- StructuredText
Example
document.getStructuredText('blog-post.body').asHtml(linkResolver)
getText(name, after) → {object}
Gets the text fragment in the current Document object, for further manipulation.
The method works with StructuredText fragments, Text fragments, Number fragments, Select fragments and Color fragments.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.label" |
after |
string | a suffix that will be appended to the value |
- Source:
Returns:
- either StructuredText, or Text, or Number, or Select, or Color.
- Type
- object
Example
document.getText('blog-post.label').asHtml(linkResolver).
getTimestamp(name) → {Date}
Gets the timestamp fragment in the current Document object, for further manipulation.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the fragment to get, with its type; for instance, "blog-post.publicationdate" |
- Source:
Returns:
- The Date object to manipulate
- Type
- Date
Example
document.getDate('blog-post.publicationdate').asHtml(linkResolver)
linkedDocuments() → {Array}
Linked documents, as an array of DocumentLink
- Source:
Returns:
- Type
- Array