Skip to content

Commit

Permalink
add isPageMeta and isLayoutMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonpecora committed Jul 5, 2018
1 parent fa80274 commit c9867a2
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ npm install --save clayutils
* **isDefaultComponent** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isDefaultComponent)
* **isDefaultLayout** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isDefaultLayout)
* **isLayout** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isLayout)
* **isLayoutMeta** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isLayoutMeta)
* **isList** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isList)
* **isPage** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isPage)
* **isPageMeta** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isPageMeta)
* **isPublished** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isPublished)
* **isUri** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isUri)
* **isUser** [(code|tests|docs)](https://github.com/clay/clayutils/tree/master/lib/isUser)
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ module.exports.getListInstance = require('./lib/getListInstance');
module.exports.getPrefix = require('./lib/getPrefix');
module.exports.isComponent = require('./lib/isComponent');
module.exports.isLayout = require('./lib/isLayout');
module.exports.isLayoutMeta = require('./lib/isLayoutMeta');
module.exports.isDefaultComponent = require('./lib/isDefaultComponent');
module.exports.isDefaultLayout = require('./lib/isDefaultLayout');
module.exports.isPage = require('./lib/isPage');
module.exports.isPageMeta = require('./lib/isPageMeta');
module.exports.isPublished = require('./lib/isPublished');
module.exports.isList = require('./lib/isList');
module.exports.isUri = require('./lib/isUri');
Expand Down
17 changes: 17 additions & 0 deletions lib/isLayoutMeta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### isLayoutMeta

Check if '/_layouts/:name/instances/:id/meta' is in the uri

#### Params

* `uri` _string_

**Returns** _boolean_

#### Example

```js
isPage('domain.com/_layouts/foo/instances/bar/meta')
//=> true

```
16 changes: 16 additions & 0 deletions lib/isLayoutMeta/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const isUriStringCheck = require('../strCheck'),
isLayout = require('../isLayout'),
getLayoutInstance = require('../getLayoutInstance');

/**
* First test if argument is a String. If true, test if '/_layouts/:name/instances/:id/meta' is in the string.
* Otherwise, throw an error.
* @param {string} uri
* @return {Boolean}
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return isLayout(uri) && !!getLayoutInstance(uri) && !!uri.match(/\/meta$/i);
};
33 changes: 33 additions & 0 deletions lib/isLayoutMeta/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const name = __filename.split('/').pop().split('.').shift(),
fn = require('./' + name),
expect = require('chai').expect;

describe('isLayoutMeta', () => {
it('returns false if default', () => {
expect(fn('domain.com/_layouts/foo/meta')).to.equal(false);
});

it('returns false if no meta', () => {
expect(fn('domain.com/_layouts/foo/instances/bar')).to.equal(false);
});

it('returns true if meta', () => {
expect(fn('domain.com/sitepath/_layouts/foo/instances/bar/meta')).to.equal(true);
});

it('throws an error if the URI passed in is not a string', () => {
const nonStringArgument = function () {
return fn([0, 1, 2, 3]);
};

expect(nonStringArgument).to.throw(Error);
});

it('returns false if non-layout reference', () => {
expect(fn('domain.com/_users/foo')).to.equal(false);
expect(fn('domain.com/_components/foo')).to.equal(false);
expect(fn('domain.com/_pages/foo/meta')).to.equal(false);
});
});
17 changes: 17 additions & 0 deletions lib/isPageMeta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### isPageMeta

Check if '/_pages/:id/meta' is in the uri

#### Params

* `uri` _string_

**Returns** _boolean_

#### Example

```js
isPage('domain.com/_pages/foobar/meta')
//=> true

```
15 changes: 15 additions & 0 deletions lib/isPageMeta/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const isUriStringCheck = require('../strCheck'),
isPage = require('../isPage');

/**
* First test if argument is a String. If true, test if '/_pages/:id/meta' is in the string.
* Otherwise, throw an error.
* @param {string} uri
* @return {Boolean}
*/
module.exports = function (uri) {
isUriStringCheck.strCheck(uri);
return isPage(uri) && !!uri.match(/\/meta$/i);
};
29 changes: 29 additions & 0 deletions lib/isPageMeta/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const name = __filename.split('/').pop().split('.').shift(),
fn = require('./' + name),
expect = require('chai').expect;

describe('isPageMeta', () => {
it('returns false if no meta', () => {
expect(fn('domain.com/_pages/foo')).to.equal(false);
});

it('returns true if meta', () => {
expect(fn('domain.com/sitepath/_pages/foobarbaz/meta')).to.equal(true);
});

it('throws an error if the URI passed in is not a string', () => {
const nonStringArgument = function () {
return fn([0, 1, 2, 3]);
};

expect(nonStringArgument).to.throw(Error);
});

it('returns false if non-page reference', () => {
expect(fn('domain.com/_users/foo')).to.equal(false);
expect(fn('domain.com/_components/foo')).to.equal(false);
expect(fn('domain.com/_layouts/foo/instances/bar/meta')).to.equal(false);
});
});

0 comments on commit c9867a2

Please sign in to comment.