mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added 'visibility' property check to {{#has}} helper (#11596)
no issue - Allows for syntax like `{{#has visibility="paid"}}` to be used on Content API resources (posts, pages, etc.)| - The need for this change cropped out from being able to distinguish paid/member-only/public posts in member-enabled themes.
This commit is contained in:
parent
9c1aa07ea8
commit
aff289bfee
2 changed files with 36 additions and 1 deletions
|
@ -8,7 +8,7 @@ const proxy = require('./proxy');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const logging = proxy.logging;
|
const logging = proxy.logging;
|
||||||
const i18n = proxy.i18n;
|
const i18n = proxy.i18n;
|
||||||
const validAttrs = ['tag', 'author', 'slug', 'id', 'number', 'index', 'any', 'all'];
|
const validAttrs = ['tag', 'author', 'slug','visibility', 'id', 'number', 'index', 'any', 'all'];
|
||||||
|
|
||||||
function handleCount(ctxAttr, data) {
|
function handleCount(ctxAttr, data) {
|
||||||
if (!data || !_.isFinite(data.length)) {
|
if (!data || !_.isFinite(data.length)) {
|
||||||
|
@ -136,6 +136,9 @@ module.exports = function has(options) {
|
||||||
index: function () {
|
index: function () {
|
||||||
return attrs.index && evaluateIntegerMatch(attrs.index, options.data.index) || false;
|
return attrs.index && evaluateIntegerMatch(attrs.index, options.data.index) || false;
|
||||||
},
|
},
|
||||||
|
visibility: function () {
|
||||||
|
return attrs.visibility && evaluateStringMatch(attrs.visibility, self.visibility, true) || false;
|
||||||
|
},
|
||||||
slug: function () {
|
slug: function () {
|
||||||
return attrs.slug && evaluateStringMatch(attrs.slug, self.slug, true) || false;
|
return attrs.slug && evaluateStringMatch(attrs.slug, self.slug, true) || false;
|
||||||
},
|
},
|
||||||
|
|
|
@ -528,6 +528,38 @@ describe('{{#has}} helper', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('visibility match', function () {
|
||||||
|
it('matches on an exact visibility (pass)', function () {
|
||||||
|
thisCtx = {visibility: 'paid'};
|
||||||
|
|
||||||
|
// {{#has visibility="paid"}}
|
||||||
|
callHasHelper(thisCtx, {visibility: 'paid'});
|
||||||
|
|
||||||
|
fn.called.should.be.true();
|
||||||
|
inverse.called.should.be.false();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('matches on an exact visibility (fail)', function () {
|
||||||
|
thisCtx = {visibility: 'paid'};
|
||||||
|
|
||||||
|
// {{#has visibility="members"}}
|
||||||
|
callHasHelper(thisCtx, {visibility: 'members'});
|
||||||
|
|
||||||
|
fn.called.should.be.false();
|
||||||
|
inverse.called.should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails gracefully if there is no visibility (fail)', function () {
|
||||||
|
thisCtx = {};
|
||||||
|
|
||||||
|
// {{#has visibility="welcome-to-ghost"}}
|
||||||
|
callHasHelper(thisCtx, {visibility: 'paid'});
|
||||||
|
|
||||||
|
fn.called.should.be.false();
|
||||||
|
inverse.called.should.be.true();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('id match', function () {
|
describe('id match', function () {
|
||||||
it('matches on an exact id (pass)', function () {
|
it('matches on an exact id (pass)', function () {
|
||||||
thisCtx = {id: '5981fbed98141579627e9a5a'};
|
thisCtx = {id: '5981fbed98141579627e9a5a'};
|
||||||
|
|
Loading…
Add table
Reference in a new issue