This commit is contained in:
parent
c2c7d8309e
commit
c791158dd5
@ -130,6 +130,28 @@ describe('stringTemplate', () => {
|
||||
),
|
||||
).toBe('BACKENDSLUG-title-01-02-2020');
|
||||
});
|
||||
|
||||
it('return apply filter for default value', () => {
|
||||
expect(
|
||||
compileStringTemplate(
|
||||
"{{slug | upper}}-{{title | default('none')}}-{{subtitle | default('none')}}",
|
||||
date,
|
||||
'backendSlug',
|
||||
fromJS({ slug: 'entrySlug', title: 'title', subtitle: null, published: date, date }),
|
||||
),
|
||||
).toBe('BACKENDSLUG-title-none');
|
||||
});
|
||||
|
||||
it('return apply filter for ternary', () => {
|
||||
expect(
|
||||
compileStringTemplate(
|
||||
"{{slug | upper}}-{{starred | ternary('star️','nostar')}}-{{done | ternary('done', 'open️')}}",
|
||||
date,
|
||||
'backendSlug',
|
||||
fromJS({ slug: 'entrySlug', starred: true, done: false }),
|
||||
),
|
||||
).toBe('BACKENDSLUG-star️-open️');
|
||||
});
|
||||
});
|
||||
|
||||
describe('expandPath', () => {
|
||||
|
@ -13,6 +13,14 @@ const filters = [
|
||||
pattern: /^date\('(.+)'\)$/,
|
||||
transform: (str: string, match: RegExpMatchArray) => moment(str).format(match[1]),
|
||||
},
|
||||
{
|
||||
pattern: /^default\('(.+)'\)$/,
|
||||
transform: (str: string, match: RegExpMatchArray) => (str ? str : match[1]),
|
||||
},
|
||||
{
|
||||
pattern: /^ternary\('(.*)',\s*'(.*)'\)$/,
|
||||
transform: (str: string, match: RegExpMatchArray) => (str ? match[1] : match[2]),
|
||||
},
|
||||
];
|
||||
|
||||
const FIELD_PREFIX = 'fields.';
|
||||
|
@ -545,7 +545,7 @@ collections:
|
||||
```
|
||||
|
||||
The above config will transform the title field to uppercase and format the date field using `YYYY-MM-DD` format.
|
||||
Available transformations are `upper`, `lower` and `date('<format>')`
|
||||
Available transformations are `upper`, `lower`, `date('<format>'), default('defaultValue') and ternary('valueForTrue','valueForFalse')`
|
||||
|
||||
## Registering to CMS Events
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user