├── test
├── fixtures
│ ├── yaml
│ │ ├── single.yml
│ │ └── double.yml
│ ├── alpha.hbs
│ └── beta.hbs
└── test.js
├── AUTHORS
├── .travis.yml
├── CONTRIBUTING.md
├── docs
├── getting-started.md
├── README.tmpl.md
└── methods.md
├── .gitattributes
├── .editorconfig
├── .gitignore
├── CHANGELOG
├── .jshintrc
├── index.js
├── bower.json
├── LICENSE-MIT
├── package.json
├── Gruntfile.js
└── README.md
/test/fixtures/yaml/single.yml:
--------------------------------------------------------------------------------
1 | ---
2 | foo: bar
3 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | Brian Woodward (https://github.com/doowb/)
2 |
--------------------------------------------------------------------------------
/test/fixtures/yaml/double.yml:
--------------------------------------------------------------------------------
1 | ---
2 | foo: bar
3 | ---
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "0.8"
4 | before_script:
5 | - npm install -g grunt-cli
6 |
--------------------------------------------------------------------------------
/test/fixtures/alpha.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | foo: bar
3 | ---
4 |
5 | This is an alert
6 |
--------------------------------------------------------------------------------
/test/fixtures/beta.hbs:
--------------------------------------------------------------------------------
1 | ---
2 | foo: bar
3 | version: 2
4 | ---
5 |
6 | This is an alert
7 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Please see the [Contributing to Assemble](http://assemble.io/contributing) guide for information on contributing to this project.
2 |
--------------------------------------------------------------------------------
/docs/getting-started.md:
--------------------------------------------------------------------------------
1 | ```shell
2 | npm install {%= name %} --save
3 | ```
4 |
5 | and use it as follows:
6 |
7 | ```js
8 | var yfm = require('{%= name %}');
9 | ```
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behaviour, in case users don't have core.autocrlf set.
2 | * text=lf
3 | * text eol=lf
4 | *.* eol=lf
5 |
6 | *.jpg binary
7 | *.gif binary
8 | *.png binary
9 | *.jpeg binary
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | lib-cov
2 | *.seed
3 | *.log
4 | *.csv
5 | *.dat
6 | *.out
7 | *.pid
8 | *.gz
9 | *.rar
10 | npm-debug.log
11 | node_modules
12 | pids
13 | logs
14 |
15 |
16 | release
17 | tmp
18 | temp
19 |
20 | TODO.md
21 |
22 | *.sublime-*
--------------------------------------------------------------------------------
/CHANGELOG:
--------------------------------------------------------------------------------
1 | v0.1.2:
2 | date: "2013-09-22"
3 | changes:
4 | - Adds grunt-readme and grunt-pkg-sync
5 | v0.1.1:
6 | date: "2013-09-02"
7 | changes:
8 | - Updates tests and example files
9 | v0.1.0:
10 | date: "2013-08-11"
11 | changes:
12 | - Initial setup
13 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": true,
6 | "newcap": true,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": false,
10 | "boss": true,
11 | "eqnull": true,
12 | "globals": {
13 | "module": true,
14 | "exports": true,
15 | "require": true
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * assemble-front-matter
3 | * https://github.com/assemble/assemble-front-matter
4 | *
5 | * Copyright (c) 2013 Brian Woodward, contributors.
6 | * Licensed under the MIT license.
7 | */
8 |
9 | var path = require('path');
10 | var pkg = require(path.resolve(process.cwd(), 'package.json'));
11 |
12 | if (pkg.name !== 'assemble-yaml') {
13 | module.exports = exports = require('assemble-yaml');
14 | } else {
15 | module.exports = exports = require('./lib');
16 | }
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assemble-front-matter",
3 | "version": "0.1.2",
4 | "repo": "assemble/assemble-front-matter",
5 | "main": [
6 | "./index.js"
7 | ],
8 | "dependencies": {
9 | "assemble-yaml": "~0.1.0"
10 | },
11 | "devDependencies": {
12 | "grunt-mocha-test": "~0.6.2",
13 | "chai": "~1.7.2",
14 | "grunt": "~0.4.1",
15 | "grunt-contrib-jshint": "~0.6.2",
16 | "grunt-contrib-watch": "~0.5.1",
17 | "grunt-sync-pkg": "~0.1.0",
18 | "grunt-readme": "~0.1.3"
19 | }
20 | }
--------------------------------------------------------------------------------
/docs/README.tmpl.md:
--------------------------------------------------------------------------------
1 | ---
2 | username: doowb
3 | ---
4 | # {%= name %} [](http://badge.fury.io/js/{%= name %}) {% if (travis) { %} []({%= travis %}){% } %}
5 |
6 | > {%= description %}
7 |
8 | Visit [Assemble's documentation](http://assemble.io) for many more examples and pointers on getting started.
9 |
10 | ## Getting Started
11 | {%= _.doc('getting-started.md') %}
12 |
13 | ## Methods
14 | {%= _.doc('methods.md') %}
15 |
16 | {% if (changelog) { %}
17 | ## Release History
18 | {%= _.include("docs-changelog.md") %} {% } %}
19 |
20 | ## Author
21 |
22 | + [github.com/{%= username %}](https://github.com/{%= username %})
23 | + [twitter.com/{%= username %}](http://twitter.com/{%= username %})
24 |
25 | ## License
26 | {%= copyright %}
27 | {%= license %}
28 |
29 | ***
30 |
31 | _This file was generated on Mon Sep 02 2013 09:44:51._
32 |
--------------------------------------------------------------------------------
/docs/methods.md:
--------------------------------------------------------------------------------
1 | ### extract
2 | Extract YAML front matter and content from files.
3 |
4 | ```js
5 | var raw = yfm.extract("./file.hbs", opts);
6 | ```
7 | **Parameters**:
8 |
9 | * `String`: The file to read.
10 | * `Object`: The options object to pass to [js-yaml](https://github.com/nodeca/js-yaml)
11 |
12 | **Returns**:
13 |
14 | Object with three properties
15 |
16 | ```js
17 | {
18 | "context": {} // Object. YAML front matter returned as a JSON object.
19 | "content": "" // String. File content, stripped of YAML front matter
20 | "originalContent": "" // String. Both content and YAML front matter.
21 | }
22 | ```
23 |
24 | ### context
25 |
26 | Return YAML front matter as a JSON object.
27 |
28 | ```js
29 | var data = yfm.extract("./file.hbs").context;
30 | ```
31 |
32 | Alias:
33 |
34 | ```js
35 | var data = yfm.extractJSON("./file.hbs");
36 | ```
37 |
38 | ### content
39 |
40 | Return the content of a file, with YAML front matter removed.
41 |
42 | ```js
43 | var content = yfm.extract("./file.hbs").content;
44 | ```
45 |
46 | Alias:
47 |
48 | ```js
49 | var data = yfm.stripYFM("./file.hbs");
50 | ```
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Assemble
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assemble-front-matter",
3 | "version": "0.1.2",
4 | "description": "Utilities for extracting front matter from source files.",
5 | "author": {
6 | "name": "Brian Woodward",
7 | "url": "https://github.com/doowb"
8 | },
9 | "contributors": [
10 | {
11 | "name": "Brian Woodward",
12 | "url": "https://github.com/doowb"
13 | },
14 | {
15 | "name": "Jon Schlinkert",
16 | "url": "https://github.com/jonschlinkert"
17 | }
18 | ],
19 | "licenses": [
20 | {
21 | "type": "MIT",
22 | "url": "https://github.com/assemble/yfm/blob/master/LICENSE-MIT"
23 | }
24 | ],
25 | "repository": {
26 | "type": "git",
27 | "url": "https://github.com/assemble/assemble-front-matter.git"
28 | },
29 | "bugs": {
30 | "url": "https://github.com/assemble/assemble-front-matter/issues"
31 | },
32 | "main": "./index.js",
33 | "scripts": {
34 | "test": "grunt test"
35 | },
36 | "devDependencies": {
37 | "grunt-mocha-test": "~0.6.2",
38 | "chai": "~1.7.2",
39 | "grunt": "~0.4.1",
40 | "grunt-contrib-jshint": "~0.6.2",
41 | "grunt-contrib-watch": "~0.5.1",
42 | "grunt-sync-pkg": "~0.1.0",
43 | "grunt-readme": "~0.1.3"
44 | },
45 | "dependencies": {
46 | "assemble-yaml": "~0.1.0"
47 | },
48 | "keywords": [
49 | "assemble",
50 | "front matter",
51 | "jekyll",
52 | "metadata",
53 | "static site generator",
54 | "yaml front matter",
55 | "yaml",
56 | "yfm"
57 | ]
58 | }
59 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * assemble-front-matter
3 | * https://github.com/assemble/assemble-front-matter
4 | *
5 | * Copyright (c) 2013 Brian Woodward, contributors.
6 | * Licensed under the MIT license.
7 | */
8 |
9 |
10 | /*global module:false*/
11 | module.exports = function(grunt) {
12 |
13 | // Project configuration.
14 | grunt.initConfig({
15 | // Task configuration.
16 | jshint: {
17 | options: {jshintrc: '.jshintrc'},
18 | gruntfile: {
19 | src: 'Gruntfile.js'
20 | },
21 | lib_test: {
22 | src: ['lib/*.js', 'test/*.js']
23 | }
24 | },
25 |
26 | // Run mocha tests.
27 | mochaTest: {
28 | files: ['test/**/*.js']
29 | },
30 | mochaTestConfig: {
31 | options: {
32 | reporter: 'nyan'
33 | }
34 | },
35 |
36 | watch: {
37 | gruntfile: {
38 | files: '<%= jshint.gruntfile.src %>',
39 | tasks: ['jshint:gruntfile']
40 | },
41 | lib_test: {
42 | files: '<%= jshint.lib_test.src %>',
43 | tasks: ['jshint:lib_test', 'test']
44 | }
45 | }
46 | });
47 |
48 | // These plugins provide necessary tasks.
49 | grunt.loadNpmTasks('grunt-contrib-jshint');
50 | grunt.loadNpmTasks('grunt-contrib-watch');
51 | grunt.loadNpmTasks('grunt-mocha-test');
52 | grunt.loadNpmTasks('grunt-sync-pkg');
53 | grunt.loadNpmTasks('grunt-readme');
54 |
55 | grunt.registerTask('test', ['mochaTest']);
56 |
57 | // Default task.
58 | grunt.registerTask('default', ['jshint', 'test', 'readme', 'sync']);
59 | };
60 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # assemble-front-matter [](http://badge.fury.io/js/assemble-front-matter) [](https://travis-ci.org/assemble/assemble-front-matter)
2 |
3 | > Utilities for extracting front matter from source files.
4 |
5 | Visit [Assemble's documentation](http://assemble.io) for many more examples and pointers on getting started.
6 |
7 | ## Getting Started
8 | ```shell
9 | npm install assemble-front-matter --save
10 | ```
11 |
12 | and use it as follows:
13 |
14 | ```js
15 | var yfm = require('assemble-front-matter');
16 | ```
17 |
18 |
19 | ## Methods
20 | #### extract
21 | Extract YAML front matter and content from files.
22 |
23 | ```js
24 | var raw = yfm.extract("./file.hbs", opts);
25 | ```
26 | **Parameters**:
27 |
28 | * `String`: The file to read.
29 | * `Object`: The options object to pass to [js-yaml](https://github.com/nodeca/js-yaml)
30 |
31 | **Returns**:
32 |
33 | Object with three properties
34 |
35 | ```js
36 | {
37 | "context": {} // Object. YAML front matter returned as a JSON object.
38 | "content": "" // String. File content, stripped of YAML front matter
39 | "originalContent": "" // String. Both content and YAML front matter.
40 | }
41 | ```
42 |
43 | #### context
44 |
45 | Return YAML front matter as a JSON object.
46 |
47 | ```js
48 | var data = yfm.extract("./file.hbs").context;
49 | ```
50 |
51 | Alias:
52 |
53 | ```js
54 | var data = yfm.extractJSON("./file.hbs");
55 | ```
56 |
57 | #### content
58 |
59 | Return the content of a file, with YAML front matter removed.
60 |
61 | ```js
62 | var content = yfm.extract("./file.hbs").content;
63 | ```
64 |
65 | Alias:
66 |
67 | ```js
68 | var data = yfm.stripYFM("./file.hbs");
69 | ```
70 |
71 |
72 |
73 | ## Release History
74 |
75 | * 2013-09-22 v0.1.2 Adds grunt-readme and grunt-pkg-sync
76 | * 2013-09-02 v0.1.1 Updates tests and example files
77 | * 2013-08-11 v0.1.0 Initial setup
78 |
79 |
80 | ## Author
81 |
82 | + [github.com/doowb](https://github.com/doowb)
83 | + [twitter.com/doowb](http://twitter.com/doowb)
84 |
85 | ## License
86 | Copyright (c) 2013 Brian Woodward, contributors.
87 | Released under the MIT license
88 |
89 | ***
90 |
91 | _This file was generated on Mon Sep 02 2013 09:44:51._
92 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * assemble-front-matter
3 | * https://github.com/assemble/assemble-front-matter
4 | *
5 | * Copyright (c) 2013 Brian Woodward, contributors.
6 | * Licensed under the MIT license.
7 | */
8 |
9 |
10 | /*global require:true */
11 | var yfm = require('../');
12 | var expect = require('chai').expect;
13 |
14 |
15 | describe('Reading From Files', function() {
16 |
17 | 'use strict';
18 |
19 | var simpleExpected = {
20 | context: {
21 | "foo": "bar"
22 | }
23 | };
24 |
25 | var complexExpected = {
26 | context: {
27 | "foo": "bar",
28 | "version": 2
29 | },
30 | originalContent: "---\nfoo: bar\nversion: 2\n---\n\nThis is an alert\n",
31 | content: "This is an alert\n"
32 | };
33 |
34 |
35 | it("YAML file starts with --- no content", function(done) {
36 | var data = yfm.extractJSON('./test/fixtures/yaml/single.yml');
37 | expect(data).to.deep.equal(simpleExpected.context);
38 | done();
39 | });
40 |
41 | it("YAML file starts and ends with --- no content", function(done) {
42 | var data = yfm.extractJSON('./test/fixtures/yaml/double.yml');
43 | expect(data).to.deep.equal(simpleExpected.context);
44 | done();
45 | });
46 |
47 | it("YAML file starts and ends with --- has content", function(done) {
48 | var data = yfm.extract('./test/fixtures/alpha.hbs');
49 | expect(data.context).to.deep.equal(simpleExpected.context);
50 | done();
51 | });
52 |
53 | it("hbs file with complex YAML data and content", function(done) {
54 | var data = yfm.extract("./test/fixtures/beta.hbs");
55 | expect(data).to.deep.equal(complexExpected);
56 | done();
57 | });
58 |
59 | });
60 |
61 | describe('Reading From Strings', function() {
62 |
63 | var opts = { fromFile: false };
64 |
65 | var simple1 = "---\nfoo: bar\n";
66 | var simple2 = "---\nfoo: bar\n---";
67 | var simple3 = "---\nfoo: bar\n---\n\nThis is an alert\n";
68 |
69 | var simpleExpected = {
70 | context: {
71 | foo: 'bar'
72 | }
73 | };
74 |
75 | var complex = "---\nfoo: bar\nversion: 2\n---\n\nThis is an alert\n";
76 |
77 | var complexExpected = {
78 | context: {
79 | "foo": "bar",
80 | "version": 2
81 | },
82 | originalContent: "---\nfoo: bar\nversion: 2\n---\n\nThis is an alert\n",
83 | content: "This is an alert\n"
84 | };
85 |
86 | it("YAML string starts with --- no content", function(done) {
87 | var data = yfm.extract(simple1, opts);
88 | expect(data.context).to.deep.equal(simpleExpected.context);
89 | done();
90 | });
91 |
92 | it("YAML string starts and ends with --- no content", function(done) {
93 | var data = yfm.extract(simple2, opts);
94 | expect(data.context).to.deep.equal(simpleExpected.context);
95 | done();
96 | });
97 |
98 | it("YAML string starts and ends with --- has content", function(done) {
99 | var data = yfm.extract(simple3, opts);
100 | expect(data.context).to.deep.equal(simpleExpected.context);
101 | done();
102 | });
103 |
104 | it("hbs string with complex YAML data and content", function(done) {
105 | var data = yfm.extract(complex, opts);
106 | expect(data).to.deep.equal(complexExpected);
107 | done();
108 | });
109 |
110 | it("extracts file content, with YAML front matter stripped.", function(done) {
111 | var data = yfm.stripYFM(complex, opts);
112 | expect(data).to.deep.equal(complexExpected.content);
113 | done();
114 | });
115 |
116 | });
117 |
--------------------------------------------------------------------------------