Skip to content

Commit

Permalink
Add _path local
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Jan 13, 2017
1 parent f6d5965 commit 3c69f29
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/underscore-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ These are the keys you can set in your front-matter or `_defaults.yaml`.
These keys are set automatically by onessg and exposed to you templates as locals. Of course, you can access the keys you set in your templates as well.

- `_body` This is the main contents of the file (the part outside the front-matter).
- `_path` This is the path of the HTML or Markdown file, relative to `src/`. Note that extensions are preserved, i.e. `index.md` is a possible value.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function loadFile(name) {
.then(function (file) {
var data = file.data;
data._body = file.content;
data._path = name;
return data;
});
}
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/_path/expected/path.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
path.html
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</body>
</html>
10 changes: 10 additions & 0 deletions test/fixtures/_path/layouts/path.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<%- _path %>
<%- _body -%>
</body>
</html>
4 changes: 4 additions & 0 deletions test/fixtures/_path/src/path.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
_layout: "path"
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
6 changes: 5 additions & 1 deletion test/onessg.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ assert.fixture = function (fixture, done, devMode) {
dist: distPath,
layouts: layoutPath,
devMode: devMode,
}, function () {
}, function (err) {
if (err) return done(err);
// Assert that dist/ & expected/ are equal:
try {
assert.dirsEqual(path.join('test/fixtures/', fixture, 'dist'), path.join('test/fixtures/', fixture, 'expected'));
Expand Down Expand Up @@ -137,6 +138,9 @@ suite('layouts & front-matter', function () {
test('works', function (done) {
assert.fixture('layouts', done);
});
test('_path is set automatically', function (done) {
assert.fixture('_path', done);
});
});
suite('_defaults file', function () {
test('works', function (done) {
Expand Down

0 comments on commit 3c69f29

Please sign in to comment.