This section describes the API used by Pageflow plugins to extend and integrate with the Pageflow editor. The editor object can be imported via:
import {editor} from 'pageflow/editor';
Interface for engines providing editor extensions.
Register a custom initializer which will be run before the boot initializer of the editor.
(any)
Add tabs to the configuration editor of all pages.
List of available file import plugins
Set up editor integration for file types
Navigate to the given path.
(any)
(any)
Set up editor integration for page types.
Configure editor for entry type.
(string)
Must match name of entry type registered in Ruby configuration.
(Object)
Name | Description |
---|---|
options.EntryModel function
|
Backbone model extending {Entry} to store entry state. |
options.EntryPreviewView function
|
Backbone view that will render the live preview of the entry. |
options.EntryOutlineView function
|
Backbone view that will be rendered in the side bar. |
options.isBrowserSupported function
|
Checks to see if the browser is supported. |
options.browserNotSupportedView function
|
Backbone view that will be rendered if the browser is not supported. |
options.supportsExtendedFileRights boolean?
|
Offer additional inputs for files to specify source url, license and default display location. |
File selection handlers let editor extensions use the files view to select files for usage in their custom models.
See selectFile method for details how to trigger file selection.
Example:
function MyFileSelectionHandler(options) { this.call =
function(file) { // invoked with the selected file };
this.getReferer = function() { // the path to return to
when the back button is clicked // or after file
selection return '/some/path'; } }
editor.registerFileSelectionHandler('my_file_selection_handler', MyFileSelectionHandler);
(any)
(any)
Register additional menu item to be displayed on the root sidebar view.
Supported options:
(any)
Extend the interface of page configuration objects. This is especially convenient to wrap structured data from the page configuration as Backbone objects.
Example:
editor.registerPageConfigurationMixin({
externalLinks: function() {
return new Backbone.Collection(this.get('external_links'));
}
}
state.pages.get(1).configuration.externalLinks().each(...);
(any)
Register additional router and controller for sidebar.
Supported options:
(any)
Tracking records that are currently being saved.
SavingRecordsCollection
:
Trigger selection of the given file type with the given handler. Payload hash is passed to selection handler as options.
((string | {name: string, filter: string} | {defaultTab: string, filter: string}))
Either collection name of a file type or and object containing
the collection name a file type and a the name of a file type
filter or an object containingn a defaultTab property that controls
which tab will visible initially, while allowing selecting files of
any type.
(Object)
Options passed to the file selection handler.
editor.selectFile('image_files',
'my_file_selection_handler',
{some: 'option for handler'});
editor.selectFile({name: 'image_files', filter: 'some_filter'},
'my_file_selection_handler',
{some: 'option for handler'});
Returns a promise which resolves to a page selected by the user.
Supported options:
(any)
Set the name of the help entry that shall be selected by default when the help view is opened. This value is automatically reset when navigation occurs.
(any)
Set the file that is the parent of nested files when they are uploaded. This value is automatically set and unset upon navigating towards the appropriate views.
(any)
Display the Pageflow-Preview inside the main panel.
Display Backbone/Marionette View inside the main panel of the editor.
(any)
Setup editor integration for widget types.
API to allow access to failure UI and recovery.
Can watch collections for errors saving models and display the error allong with a retry button.
editor.failures.watch(collection);
It's possible to add failures to the UI by adding instances of subclasses of Failure:
editor.failures.add(new OrderingFailure(model, collection));
Failure and subclasses are used in the failures api.
Subclasses that represent failures that are can not be retried should
override catRetry
with false.
Retryable failures should implement retryAction
.
Watch Backbone collections to track which models are currently being saved. Used to update the notifications view displaying saving status/failutes.
Listen to events of models in collection to track when they are being saved.
(Backbone.Collection)
Collection to watch.
This section describes mixins and utilities that can be used in Backbone models and collection.
Mixins for models with a nested configuration model.
Triggers events on the parent model of the form
change:configuration
and change:configuration:<attribute>
, when
the configuration changes.
(Object?
= {}
)
Name | Description |
---|---|
options.configurationModel Function?
|
Backbone model to use for nested configuration model. |
options.autoSave Boolean?
|
Save model when configuration changes. |
options.includeAttributesInJSON (Boolean | Array<String>)?
|
Include all or specific attributes of the parent model in the
data returned by
toJSON
besides the
configuration
property.
|
Object
:
Mixin to be included in model.
import {configurationContainer} from 'pageflow/editor';
const Section = Backbone.Model.extend({
mixins: [configurationContainer({autoSave: true})]
});
const section = new Section({configuration: {some: 'value'}});
section.configuration.get('some') // => 'value';
Remove model from collection only after the DELETE
request has
succeeded. Still allow tracking that the model is being destroyed
by triggering a destroying
event and adding a isDestroying
method.
Trigger destroying
event and send DELETE
request. Only remove
model from collection once the request is done.
Get whether the model has been destroyed.
Get whether the model is currently being destroyed.
Mixins for Backbone models and collections that use entry type
specific editor controllers registered via the editor_app
entry
type option.
Mixins for Backbone collections that defines url
method.
import {editor, entryTypeEditorControllerUrls} from 'pageflow/editor';
editor.registerEntryType('test', {
// ...
});
export const ItemsCollection = Backbone.Collection.extend({
mixins: [entryTypeEditorControllerUrls.forCollection({resources: 'items'})
});
new ItemsCollection().url() // => '/editor/entries/10/test/items'
Mixins for Backbone models that defines urlRoot
method.
import {editor, entryTypeEditorControllerUrls} from 'pageflow/editor';
editor.registerEntryType('test', {
// ...
});
export const Item = Backbone.Model.extend({
mixins: [entryTypeEditorControllerUrls.forModel({resources: 'items'})
});
new Item({id: 20}).url() // => '/editor/entries/10/test/items/20'
Mixin for Backbone models that shall be watched by modelLifecycleTrackingView mixin.
A Backbone collection that is automatically updated to only contain models with a foreign key matching the id of a parent model.
(Object)
Name | Description |
---|---|
options.parentModel Backbone.Model
|
Model whose id is compared to foreign keys. |
options.parent Backbone.Collection
|
Collection to filter items with matching foreign key from. |
options.foreignKeyAttribute String
|
Attribute to compare to id of parent model. |
options.parentReferenceAttribute String
|
Set reference to parent model on models in collection. |
Editor specific Backbone views that can be used together with ConfigurationEditorView:
import {FileInputView} from 'pageflow/editor';
import {ConfigurationEditorView} from 'pageflow/ui';
// ...
this.configurationEditor = new ConfigurationEditorView({
model: this.model
});
this.configurationEditor.tab('files', function() {
this.input('image', FileInputView, {
// ...
});
});
Base view to edit configuration container models. Extend and
override the configure
method which receives a ConfigurationEditorView to define the tabs and inputs that shall
be displayed.
Add a translationKeyPrefix
property to the prototype and define
the following translations:
<translationKeyPrefix>.tabs
: used as tabTranslationKeyPrefix
of the ConfigurationEditorView
.
<translationKeyPrefix>.attributes
: used as one of the
attributeTranslationKeyPrefixes
of the
ConfigurationEditorView
.
<translationKeyPrefix>.back
(optional): Back button label.
<translationKeyPrefix>.destroy
(optional): Destroy button
label.
<translationKeyPrefix>.confirm_destroy
(optional): Confirm
message displayed before destroying.
<translationKeyPrefix>.save_error
(optional): Header of the
failure message that is displayed if the model cannot be saved.
<translationKeyPrefix>.retry
(optional): Label of the retry
button of the failure message.
Override the destroyModel
method to customize destroy behavior.
Calls destroyWithDelay
by default.
(Object)
Name | Description |
---|---|
options.model Backbone.Model
|
Model including the configurationContainer , failureTracking and delayedDestroying mixins. |
Base class for input views that reference models.
Returns a promise for some identifying attribute.
Default attribute name is perma_id. If the attribute is named
differently, you can have your specific ReferenceInputView
implement chooseValue()
accordingly.
Will be used to set the chosen Model for this View.
Input view to reference a file.
General purpose Backbone views and mixins exported by pageflow/editor
.
Mixin for Marionette Views that sets css class names according to life cycle events of its model.
(Object)
Name | Description |
---|---|
options.classNames Object
|
|
options.classNames.creating String
|
Class name to add to root element while model is still being created. |
options.classNames.destroying String
|
Class name to add to root element while model is being destroyed. |
options.classNames.failed String
|
Class name to add to root element while model is in failed state. Model needs to include failureTracking mixin. |
options.classNames.failureMessage String
|
Class name of the element that shall be updated with the failure message. Model needs to include failureTracking mixin. |
options.classNames.retryButton String
|
Class name of the element that shall act as a retry button. |
A button that displays a drop down menu on hover.
(Object)
Name | Description |
---|---|
options.label String
|
Button text. |
options.items Backbone.Collection
|
Collection of menu items. See below for supported attributes. |
options.fullWidth boolean?
|
Make button and drop down span 100% of available width. |
options.openOnClick boolean?
|
Require click to open menu. By default, menu opens on when the mouse enters the button. |
options.alignMenu String?
|
"right" to align menu on the right. Aligned on the left by default. |
options.buttonClassName String?
|
CSS class name for button element.
Item ModelsThe following model attributes can be used to control the appearance of a menu item:
If the menu item model provdised a |
A generic list view with items consisting of a thumbnail, text and possibly some buttons or a navigation arrow.
Models inside the collection must implement the following methods:
(Object)
Name | Description |
---|---|
options.collection Backbone.Collection
|
|
options.label string
|
Text of the label to display above the list. |
options.highlight boolean
(default false )
|
|
options.sortable boolean
(default false )
|
|
options.itemDescription (string | function)?
|
|
options.itemTypeName (string | function)?
|
|
options.itemTypeDescription (string | function)?
|
|
options.itemIsInvalid (string | function)?
|
|
options.onEdit function?
|
|
options.onRemove function?
|
Base thumbnail view for models supporting a thumbnailFile
method.
Backbone views that can be used together with ConfigurationEditorView. pageflow/ui
.
import {ConfigurationEditorView, TextInputView} from 'pageflow/ui';
// ...
this.configurationEditor = new ConfigurationEditorView({
model: this.model
});
this.configurationEditor.tab('general', function() {
this.input('text', TextInputView, {
// ...
});
});
Mixin for input views handling common concerns like labels, inline help, visiblity and disabling.
By default #labelText
and #inlineHelpText
are defined through
translations. If no attributeTranslationKeyPrefixes
are given,
translation keys for labels and inline help are constructed from
the i18nKey
of the model and the given propertyName
option. Suppose the model's i18nKey
is "page" and the
propertyName
option is "title". Then the key
activerecord.attributes.page.title
will be used for the label. And the key
pageflow.ui.inline_help.page.title_html
pageflow.ui.inline_help.page.title
will be used for the inline help.
The attributeTranslationKeyPrefixes
option can be used to supply
an array of scopes in which label and inline help translations
shall be looked up based on the propertyName
option.
Suppose the array ['some.attributes', 'fallback.attributes']
is
given as attributeTranslationKeyPrefixes
option. Then, in the
example above, the first existing translation key is used as label:
some.attributes.title.label
fallback.attributes.title.label
activerecord.attributes.post.title
Accordingly, for the inline help:
some.attributes.title.inline_help_html
some.attributes.title.inline_help
fallback.attributes.title.inline_help_html
fallback.attributes.title.inline_help
pageflow.ui.inline_help.post.title_html
pageflow.ui.inline_help.post.title
This setup allows to keep all translation keys for an attribute to share a common prefix:
some:
attributes:
title:
label: "Label"
inline_help: "..."
inline_help_disabled: "..."
For each inline help translation key, a separate key with an
"_disabled"
suffix can be supplied, which provides a help string
that shall be displayed when the input is disabled. More specific
attribute translation key prefixes take precedence over suffixed
keys:
some.attributes.title.inline_help_html
some.attributes.title.inline_help
some.attributes.title.inline_help_disabled_html
some.attributes.title.inline_help_disabled
fallback.attributes.title.inline_help_html
fallback.attributes.title.inline_help
fallback.attributes.title.inline_help_disabled_html
fallback.attributes.title.inline_help_disabled
pageflow.ui.inline_help.post.title_html
pageflow.ui.inline_help.post.title
pageflow.ui.inline_help.post.title_disabled_html
pageflow.ui.inline_help.post.title_disabled
(string)
Common constructor options for all views that include this mixin.
Name | Description |
---|---|
options.propertyName string
|
Name of the attribute on the model to display and edit. |
options.label string?
|
Label text for the input. |
options.attributeTranslationKeyPrefixes Array<string>?
|
An array of prefixes to lookup translations for labels and inline help texts based on attribute names. |
options.additionalInlineHelpText string?
|
A text that will be appended to the translation based inline text. |
options.disabledBinding (string | Array<string>)?
|
Name of an attribute to control whether the input is disabled. If
the
disabled
and
disabledBinding
options are not set,
input will be disabled whenever this attribute has a truthy value.
When multiple attribute names are passed, the function passed to
the
disabled
option will receive an array of values in the same
order.
|
options.disabled (function | boolean)?
|
Render input as disabled. A Function taking the value of the
disabledBinding
attribute as parameter. Input will be disabled
only if function returns
true
.
|
options.disabledBindingValue any?
|
Input will be disabled whenever the value of the
disabledBinding
attribute equals the value of this option.
|
options.visibleBinding (string | Array<string>)?
|
Name of an attribute to control whether the input is visible. If
the
visible
and
visibleBindingValue
options are not set,
input will be visible whenever this attribute has a truthy value.
When multiple attribute names are passed, the function passed to
the
visible
option will receive an array of values in the same
order.
|
options.visible (function | boolean)?
|
A Function taking the value of the
visibleBinding
attribute as
parameter. Input will be visible only if function returns
true
.
|
options.visibleBindingValue any?
|
Input will be visible whenever the value of the
visibleBinding
attribute equals the value of this option.
|
Returns an array of translation keys based on the
attributeTranslationKeyPrefixes
option and the given keyName.
Combined with i18nUtils.findTranslation, this can be used inside input views to obtain additional translations with the same logic as for labels and inline help texts.
findTranslation(this.attributeTranslationKeys('default_value'));
(string)
Suffix to append to prefixes.
(any)
Array<string>
:
Text based input view that can display a placeholder.
(Object?)
Name | Description |
---|---|
options.placeholder (string | function)?
|
Display a placeholder string if the input is blank. Either a string or a function taking the model as a first parameter and returning a string. |
options.placeholderBinding string?
|
Name of an attribute. Recompute the placeholder function whenever this attribute changes. |
options.hidePlaceholderIfDisabled boolean?
|
Do not display the placeholder if the input is disabled. |
options.placeholderModel Backbone.Model?
|
Obtain placeholder by looking up the configured
propertyName
inside a given model.
|
Input view for boolean values. See inputView for further options
(Object?)
Name | Description |
---|---|
options.displayUncheckedIfDisabled boolean
(default false )
|
Ignore the attribute value if the input is disabled and display an unchecked check box. |
options.displayCheckedIfDisabled boolean
(default false )
|
Ignore the attribute value if the input is disabled and display an checked check box. |
options.storeInverted string?
|
Display checked by default and store true in given attribute when
unchecked. The property name passed to
input
is only used for
translations.
|
Input view for a color value in hex representation. See inputView for further options
(Object?)
Name | Description |
---|---|
options.defaultValue (string | function)?
|
Color value to display by default. The corresponding value is not stored in the model. Selecting the default value when a different value was set before, unsets the attribute in the model. |
options.defaultValueBinding string?
|
Name of an attribute the default value depends on. If a function is used as defaultValue option, it will be passed the value of the defaultValueBinding attribute each time it changes. If no defaultValue option is set, the value of the defaultValueBinding attribute will be used as default value. |
options.swatches Array<string>?
|
Preset color values to be displayed inside the picker drop down. The default value, if present, is always used as the first swatch automatically. |
Render an input that is only a label. Can be used to render additional inline help.
See inputView for further options
Input view that verifies that a certain URL is reachable via a proxy. To conform with same origin restrictions, this input view lets the user enter some url and saves a rewritten url where the domain is replaced with some path segment.
That way, when /example
is setup to proxy requests to
http://example.com
, the user can enter an url of the form
http://example.com/some/path
but the string /example/some/path
is persisited to the database.
See inputView for further options
(Object)
Name | Description |
---|---|
options.displayPropertyName string
|
Attribute name to store the url entered by the user. |
options.proxies Array<Object>
|
List of supported proxies. |
options.proxies string
|
[].url Supported prefix of an url that can be entered by the user. |
options.proxies string
|
[].base_path Path to replace the url prefix with. |
options.required boolean
(default false )
|
Display an error if the url is blank. |
options.permitHttps boolean
(default false )
|
Allow urls with https protocol. |
this.input('url, ProxyUrlInputView, { proxies: [ { url: 'http://example.com', base_path: '/example' } ] });
A drop down with support for grouped items. See inputView for further options
(Object?)
Name | Description |
---|---|
options.values Array<string>?
|
List of possible values to persist in the attribute. |
options.texts Array<string>?
|
List of display texts for drop down items. |
options.translationKeys Array<string>?
|
Translation keys to obtain item texts from. |
options.translationKeyPrefix Array<string>?
|
Obtain texts for items from translations by appending the item
value to this prefix separated by a dot. By default the
[
attributeTranslationKeyPrefixes
option]
inputView
is used by appending the suffix
.values
to each candidate.
|
options.groups Array<string>?
|
Array of same length as
values
array, containing the display
name of a group header each item shall be grouped under.
|
options.collection Array<Backbone.Model>?
|
Create items for each model in the collection. Use the
*Property
options to extract values and texts for each items
from the models.
|
options.valueProperty string?
|
Attribute to use as item value. |
options.textProperty string?
|
Attribute to use as item display text. |
options.groupProperty string?
|
Attribute to use as item group name. |
options.translationKeyProperty string?
|
Attribute to use as translation key to obtain display text. |
options.groupTranslationKeyProperty string?
|
Attribute to use as translation key to obtain group name. |
options.ensureValueDefined boolean?
|
Set the attribute to the first value on view creation. |
options.includeBlank boolean?
|
Include an item that sets the value of the attribute to a blank string. |
options.blankText string?
|
Display text for the blank item. |
options.blankTranslationKey string?
|
Translation key to obtain display text for blank item. |
options.placeholderValue string?
|
Include an item that sets the value of the attribute to a blank
string and indicate that the attribute is set to a default
value. Include the display name of the given value, in the
text. This option can be used if a fallback to the
placeholderValue
occurs whenever the attribute is blank.
|
options.placeholderModel Backbone.Model?
|
Behaves like
placeholderValue
, but obtains the value by looking
up the
propertyName
attribute inside the given model. This
option can be used if a fallback to the corresponding attribute
value of the
placeholderModel
occurs whenever the attribute is
blank.
|
options.optionDisabled function?
|
Receives value and has to return boolean indicating whether option is disabled. |
Render a separator in a ConfigurationEditorView tab.
this.view(SeparatorView);
A slider for numeric inputs. See inputView for options
(Object?)
Name | Description |
---|---|
options.defaultValue number?
|
Defaults value to display if property is not set. |
options.minValue number
(default 0 )
|
Value when dragging slider to the very left. |
options.maxValue number
(default 100 )
|
Value when dragging slider to the very right. |
options.unit string
(default "%" )
|
Unit to display after value. |
options.displayText function?
|
Function that receives value and returns custom text to display as value. |
options.saveOnSlide boolean?
|
Already update the model while dragging the handle - not only after handle has been released. |
Input view for multi line text with simple formatting options. See inputWithPlaceholderText for placeholder related options. See inputView for further options.
(Object?)
Name | Description |
---|---|
options.size string
(default "normal" )
|
Pass
"short"
to reduce the text area height.
|
options.disableLinks boolean
(default false )
|
Do not allow links inside the text. |
options.disableRichtext boolean
(default false )
|
Do not provide text formatting options. |
options.fragmentLinkInputView Backbone.View?
|
A view to select an id to use in links which only consist
of a url fragment. Will receive a model with a
linkId
attribute.
|
Input view for a single line of text.
See inputWithPlaceholderText for placeholder related further options. See inputView for further options.
(Object?)
Name | Description |
---|---|
options.required boolean
(default false )
|
Display an error if the input is blank. |
options.maxLength number
(default 255 )
|
Maximum length of characters for this input. To support legacy data which consists of more characters than the specified maxLength, the option will only take effect for data which is shorter than the specified maxLength. |
Input view for URLs. See inputView for further options
Override to be notified when the input has been loaded.
Override to change the list of supported host names.
Override to transform the property value before it is stored.
(any)
any
:
Promise | String
Override to validate the untransformed url. Validation error message can be passed as rejected promise. Progress notifications are displayed. Only valid urls are stored in the configuration.
(any)
any
:
Promise
Backbone views exported by pageflow/ui
to display tables.
A table cell providing a button which destroys the model that the current row refers to.
The following attribute translation is used:
.cell_title
- Used as title attribute.(Object?)
Name | Description |
---|---|
options.toggleDeleteButton function?
|
A function with boolean return value to be called on this.getModel(). Delete button will be visible only if the function returns a truthy value. |
options.invertToggleDeleteButton boolean?
|
Invert the return value of
toggleDeleteButton
?
|
A table cell mapping column attribute values to a list of translations.
The following attribute translations are used:
.cell_text.<attribute_value>
- Used as cell content..cell_text.blank
- Used as cell content if attribute is blank..cell_title.<attribute_value>
- Used as title attribute..cell_title.blank
- Used as title attribute if attribute is blank.A table cell mapping column attribute values to icons.
The following attribute translations are used:
.cell_title.<attribute_value>
- Used as title attribute..cell_title.blank
- Used as title attribute if attribute is blank.A table cell representing whether the column attribute is present on the row model.
The following attribute translations are used:
.cell_title.present
- Used as title attribute if the attribute
is present. The current attribute value is provided as
interpolation %{value}
..cell_title.blank
- Used as title attribute if the
attribute is blank.Base class for table cell views.
Inside sub classes the name of the column options are available as
this.options.column
. Override the update
method to populate the
element.
Look up attribute specific translations based on
attributeTranslationKeyPrefixes
of the the parent TableView
.
(any)
this.attribute.attributeTranslation("cell_title");
// Looks for keys of the form:
// <table_view_translation_key_prefix>.<column_attribute>.cell_title
Returns the column attribute's value in the row model.
Set up content binding to update this view upon change of specified attribute on this.getModel().
Override in concrete cell view.
General purpose Backbone views exported by pageflow/ui
.
Render a inputs on multiple tabs.
(Object?)
Name | Description |
---|---|
options.model string?
|
Backbone model to use for input views. |
options.placeholderModel string?
|
Backbone model to read placeholder values from. |
options.tab string?
|
Name of the tab to enable by default. |
options.attributeTranslationKeyPrefixes Array<string>?
|
List of prefixes to use in input views for attribute based transltions. |
options.tabTranslationKeyPrefixes Array<string>?
|
List of prefixes to append tab name to. First exisiting translation is used as label. |
options.tabTranslationKeyPrefix string?
|
Prefixes to append tab name to. |
Base class for views used as valueView
for file type meta data
attributes.
Switch between different views using tabs.
(Object?)
Name | Description |
---|---|
options.defaultTab string?
|
Name of the tab to enable by default. |
options.translationKeyPrefixes Array<string>?
|
List of prefixes to append tab name to. First exisiting translation is used as label. |
options.fallbackTranslationKeyPrefix string?
|
Translation key prefix to use if non of the
translationKeyPrefixes
result in an
existing translation for a tab name.
|
options.i18n string?
|
Legacy alias for
fallbackTranslationKeyPrefix
.
|
Utility functions exported by pageflow/ui
.
Helpers functions for handling translations.
Takes the same parameters as attributeTranslationKeys, but returns the first existing translation.
(any)
(any)
(any)
string
:
Helpers functions for working with CSS modules.
Create object that can be passed to Marionette events property from CSS module object.
Object
:
// MyView.module.css
.addButton {}
// MyView.js
import Marionette from 'marionette';
import {cssModulesUtils} from 'pageflow/ui';
import styles from './MyView.module.css';
export const MyView = Marionette.ItemView({
template: () => `
<button class=${styles.addButton}></button>
`,
events: cssModulesUtils.events(styles, {
'click addButton': () => console.log('clicked add button');
})
});
Create object that can be passed to Marionette ui property from CSS module object.
(...string)
Keys from the styles object that shall be used in the ui object.
Object
:
// MyView.module.css
.container {}
// MyView.js
import Marionette from 'marionette';
import {cssModulesUtils} from 'pageflow/ui';
import styles from './MyView.module.css';
export const MyView = Marionette.ItemView({
template: () => `
<div class=${styles.container}></div>
`,
ui: cssModulesUtils.ui(styles, 'container'),
onRender() {
this.ui.container // => JQuery wrapper for container element
}
});
Utility functions exported by pageflow/testHelpers
.
Build editor Backbone models for tests.
Build an entry model.
(Function)
Entry type specific entry model
(Object?)
Model attributes
(Object?
= {}
)
Name | Description |
---|---|
options.entryTypeSeed Object?
|
Seed data passed to
Entry#setupFromEntryTypeSeed
.
|
options.fileTypes FileTypes?
|
Use factories.fileTypes to construct this object. |
options.filesAttributes Object?
|
An object mapping (underscored) file collection names to arrays of file attributes. |
Entry
:
An entry Backbone model.
import {factories} from 'pageflow/testHelpers';
import {PagedEntry} from 'editor/models/PagedEntry';
const entry = factories.entry(PagedEntry, {slug: 'some-entry'}, {
entryTypeSeed: {some: 'data'},
fileTypes: factories.fileTypes(f => f.withImageFileType()),
filesAttributes: {
image_files: [{id: 100, perma_id: 1, basename: 'image'}]
}
});
Construct a file type registry that can be passed to factories.entry.
The passed function receives a builder object with the following methods that register a corresponding file type:
withImageFileType([options])
: Registers a file type with collection name image_files
.withVideoFileType([options])
: Registers a file type with collection name video_files
.withTextTrackFileType([options])
: Registers a file type with collection name text_track_files
.(Function)
Build function.
FileTypes
:
A file Type registry
Shorthand for calling factories.fileTypes with a builder function that calls
withImageFileType
.
(Object)
File type options passed to withImageFileType,
FileTypes
:
A file Type registry.
Setup global state for testing Backbone editor components.
For some editor components like (some views or models) it's easier
to depend on the global mutable state (available via the $state
module alias) instead of injecting dependencies. This helper can be
used to test these components in isolation.
(Object)
Properties to set on the global state. Functions as values will
be evaluated and the return value will be assigned instead.
Define translations to use in tests.
(Object)
A mapping of either the form
(translation key => translated text)
. Translation keys can contains dots.
import {useFakeTranslations} from 'pageflow/testHelpers';
import I18n from 'i18n-js';
describe('...', () => {
useFakeTranslations({
'some.key': 'some translation'
});
it('...', () => {
I18n.t('some.key') // => 'some translation'
});
});
import {useFakeTranslations} from 'pageflow/testHelpers';
import I18n from 'i18n-js';
describe('...', () => {
useFakeTranslations({
'en.some.key': 'some text',
'de.some.key': 'etwas Text'
}, {multiLocale: true});
it('...', () => {
I18n.locale = 'de';
I18n.t('some.key') // => 'etwas Text'
});
});