UNPKG

get-view

Version:

Utility for getting an assemble view from a collection object.

144 lines (94 loc) 5.91 kB
# get-view [![NPM version](https://img.shields.io/npm/v/get-view.svg?style=flat)](https://www.npmjs.com/package/get-view) [![NPM monthly downloads](https://img.shields.io/npm/dm/get-view.svg?style=flat)](https://npmjs.org/package/get-view) [![NPM total downloads](https://img.shields.io/npm/dt/get-view.svg?style=flat)](https://npmjs.org/package/get-view) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/get-view.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/get-view) > Utility for getting an assemble view from a collection object. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save get-view ``` ## Usage Should work with any collection of vinyl files. ```js const getView = require('get-view'); ``` **[templates](https://github.com/jonschlinkert/templates) example** Given the following setup code, all of the below examples would return a view from the `app.views.pages` collection: ```js const templates = require('templates'); app = templates(); app.create('page'); app.page('foo', {content: 'this is foo'}); app.page('bar.md', {content: 'this is bar'}); app.page('a/b/c/baz.md', {content: 'this is baz', base: 'a'}); app.page('test/fixtures/templates/a.tmpl'); ``` Get a view by customizing the lookup key with a function: ```js const view = getView(app.views.pages, function(view) { return view.stem === 'foo.md'; }); //=> <View "foo" <Buffer 74 68 69 73 20 69>> ``` Get a view by `view.path` ```js const view = getView(app.views.pages, 'a/b/c/baz.md'); //=> <View "b/c/baz.md" <Buffer 74 68 69 73>> ``` Get a view by `view.basename` ```js const view = getView(app.views.pages, 'baz.md'); //=> <View "b/c/baz.md" <Buffer 74 68 69 73>> ``` Get a view by `view.filename` ```js const view = getView(app.views.pages, 'baz'); //=> <View "b/c/baz.md" <Buffer 74 68 69 73>> ``` Get a view by `view.relative` ```js const view = getView(app.views.pages, 'b/c/baz.md'); //=> <View "b/c/baz.md" <Buffer 74 68 69 73>> ``` ## Release history ### v2.0 **Breaking changes** * The order of arguments has been reversed, so that the collection of views is passed first, and the lookup value is second. * No longer matches with globs. This can be done by passing a glob matcher as the second argument. ## About <details> <summary><strong>Contributing</strong></summary> Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). </details> <details> <summary><strong>Running Tests</strong></summary> Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ``` </details> <details> <summary><strong>Building docs</strong></summary> _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ``` </details> ### Related projects You might also be interested in these projects: * [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") * [gulp](https://www.npmjs.com/package/gulp): The streaming build system | [homepage](http://gulpjs.com "The streaming build system") * [match-file](https://www.npmjs.com/package/match-file): Returns true when the given `name` matches any of the path properties on a vinyl… [more](https://github.com/jonschlinkert/match-file) | [homepage](https://github.com/jonschlinkert/match-file "Returns true when the given `name` matches any of the path properties on a vinyl file.") * [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.") * [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") * [vinyl](https://www.npmjs.com/package/vinyl): Virtual file format. | [homepage](https://github.com/gulpjs/vinyl#readme "Virtual file format.") ### Author **Jon Schlinkert** * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) ### License Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 18, 2018._