Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds grunt.config.process to pageContext so that lodash templates are…

… processed. previously, lodash templates were only processed for the context of the "current page" but were left un-processed for the "other pages".
  • Loading branch information...
commit 32324d3d0172edadab900d5b3218dd4be2abe7e4 1 parent 727323f
@jonschlinkert jonschlinkert authored
View
46 EXAMPLES.md
@@ -1,46 +0,0 @@
-# Examples
-
-> Gruntfile configuration examples for the "assemble" task
-
-
-## Prettify HTML
-
-> Use js-prettify with Assemble's `postprocess` option to format generated HTML
-
-To get started, in the command line run `npm i js-prettify --save-dev` to add js-prettify to your project.
-
-### Prettify all generated HTML
-
-Use the `postprocess` option to prettify output HTML for all targets in the task:
-
-```js
-assemble: {
- options: {
- postprocess: require('pretty')
- },
- site: {
- files: {
- 'site/': ['templates/site/*.hbs']
- }
- }
-}
-```
-
-### Prettify a single target
-
-If you only want to format the generated HTML for a specific target, just put use the `postprocess` function in the options for that target:
-
-```js
-assemble: {
- options: {
- // task-level options
- },
- site: {
- options: {postprocess: require('pretty')},
- files: {
- 'site/': ['templates/site/*.hbs']
- }
- }
-}
-```
-
View
2  README.md
@@ -341,7 +341,7 @@ Released under the MIT license
***
-_This file was generated by [grunt-readme](https://github.com/assemble/grunt-readme) on Wednesday, December 4, 2013._
+_This file was generated by [grunt-readme](https://github.com/assemble/grunt-readme) on Thursday, December 5, 2013._
[grunt]: http://gruntjs.com/
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
View
1  tasks/assemble.js
@@ -299,6 +299,7 @@ module.exports = function(grunt) {
var pageInfo = yfm.extract(page, {fromFile: false});
pageContext = useFileInfo ? (fileInfo.data || fileInfo.metadata || {}) : pageInfo.context;
+ pageContext = grunt.config.process(pageContext);
@doowb Owner
doowb added a note

This is working properly? I had tried doing this before but had issues when properties were being used in the YFM that defined in the YFM. My understanding of grunt.config.process() was that it only used the properties that were already in grunt.config.data, but maybe something changed.

@jonschlinkert Owner

Yeah, it is using properties that are in grunt.config.data. <%= site.title %> is in the grunt config via https://github.com/assemble/assemble/blob/master/Gruntfile.js#L25

@doowb Owner
doowb added a note

Yeah, but my point is if there is YFM like this...

---
subtitle: "- all the awesomeness"
title: <%= subtitle %>
---

I think it'll fail because subtitle isn't in grunt.config.data. Or if there is data from external data files being used in the pageContext some place.

@jonschlinkert Owner

Oh, so rather than <%= subtitle %> rendering to - all the awesomeness, it will fail? We can revert if that's the case.

@doowb Owner
doowb added a note

That's what it used to do. I thought we had some test fixtures with YFM like that. Either we don't or the grunt.config.process is working differently than I expected.

@jonschlinkert Owner

Actually we need to figure this out for the refactor. Just thinking out loud, but maybe something like if(grunt.config.get("foo"){ // do stuff } and if the property doesn't exist on the grunt config object, but it does on the page context, then we add the property to the grunt config data? we also need to think about which should have precedence if there is a collision...?

@jonschlinkert Owner

I didn't see your replies until after I posted... let's just start adding a bunch of lodash templates to the yfm. I thought there used to be a lot of them, maybe those tests we're elsewhere?

and I was having a brain lapse on the last post, the convention in Assemble is already "local always beats global"...

@doowb Owner
doowb added a note

Actually, that file isn't being used, but this one is... https://github.com/assemble/assemble/blob/master/test/fixtures/pages/yfm/document.hbs#L4 and I had noticed that in your change, the date changed from 2007-08-05 to 2013-10-08, so date must be defined on grunt.config.data someplace else.

To your comment about checking if it exists and adding it, that's kind of what we do later in the build process, but instead of adding it to grunt.config.data permanently, it's just for when it's processing. This is so page data doesn't pollute other page data. https://github.com/assemble/assemble/blob/master/tasks/assemble.js#L623-L626

Now that I just looked at that function again, it's not restoring the grunt.config.data state anymore.

@jonschlinkert Owner

Now that I just looked at that function again, it's not restoring the grunt.config.data state anymore.

shouldn't it be deep cloning grunt.config.data instead?

@doowb Owner
doowb added a note

I think so. You had done a bunch of testing with the context a while ago and everything has seemed to be working okay. Maybe we just aren't hitting a case where this would cause an issue. Anyway... I think context is something we'll be focusing on a lot in the refactor to make sure everything works as expected.

@jonschlinkert Owner

Maybe we just aren't hitting a case where this would cause an issue

exactly what I was thinking

I think context is something we'll be focusing on a lot in the refactor to make sure everything works as expected.

also exactly what I was thinking lol. the test driven development will help a lot, but we should probably also describe the expected result somewhere - preferably docs, so that we're killing two birds with one stone. Coincidentally, I started a new document last night called "Understanding-Context.md". It's completely fragmented, but here is what I have so far: https://gist.github.com/jonschlinkert/7805831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
// Page object
var pageObj = {
View
4 test/actual/collections/asc/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/collections/asc/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
4 test/actual/collections/complex/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/collections/complex/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
4 test/actual/collections/custom/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/collections/custom/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
4 test/actual/collections/desc/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/collections/desc/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
4 test/actual/paths/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/paths/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
4 test/actual/plugin_preprocess/collections-pages.html
@@ -411,9 +411,7 @@
<a href="#">Collections Categories</a>
<a href="#">Title from YFM of "example.hbs"</a>
<a href="#">Gist Helper</a>
- <a href="#">
- <%=s ite.title %>
- </a>
+ <a href="#">Assemble</a>
<a href="#">md helper</a>
<a href="#"></a>
<a href="#">This title is from the YFM of the current page</a>
View
2  test/actual/plugin_preprocess/context.html
@@ -573,7 +573,7 @@
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
<li> <a href="#" data-context="page.title"></a> </li>
- <li> <a href="#" data-context="data.title">&lt;%= site.title %&gt;</a> </li>
+ <li> <a href="#" data-context="data.title">Assemble</a> </li>
<li> <a href="#" data-context="title"></a> </li>
<li> <a href="#" data-context="../title">Context</a> </li>
<li> <a href="#" data-context="this.title"></a> </li>
View
6 test/actual/yfm/document.html
@@ -139,7 +139,7 @@ <h4 style="background: #eee; display: block">Customer Information</h4>
<dt>Receipt:</dt>
<dd>Oz-Ware Purchase Invoice</dd>
<dt>Date:</dt>
- <dd>2007-08-05</dd>
+ <dd>2013-10-08</dd>
<dt>First Name:</dt>
<dd>Dorothy</dd>
<dt>Last Name:</dt>
@@ -587,7 +587,7 @@ <h4 style="background: #eee; display: block">Delivery Instructions</h4>
"data": {
"receipt": "Oz-Ware Purchase Invoice",
"date": "2007-08-06T00:00:00.000Z",
- "prettyDate": "2007-08-05",
+ "prettyDate": "2013-10-08",
"customer": {
"given": "Dorothy",
"family": "Gale"
@@ -671,7 +671,7 @@ <h4 style="background: #eee; display: block">Delivery Instructions</h4>
"page": "<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title>Layout filename: '{{layout}}'</title>\n <link rel=\"stylesheet\" href=\"http://getbootstrap.com/dist/css/bootstrap.min.css\">\n <link rel=\"stylesheet\" href=\"{{assets}}/validation.css\">\n </head>\n <body style=\"padding-top: 60px;\">\n <div class=\"container\">\n\n <!-- validate assets path -->\n <section id=\"validate\"></section>\n <div class=\"docs-section\">\n <div class=\"docs-header\" id=\"content\">\n <h4><strong class=\"text-muted\">{{page.src}}</strong> &#x2192; <strong class=\"text-success\">{{page.dest}}</strong></h4>\n </div>\n <hr>\n </div>\n\n {{pager pagination}}\n <hr>\n\n <div class=\"row\">\n <!-- Column: sidebar -->\n <div class=\"col-md-3\">\n <div class=\"bs-sidebar hidden-print\" role=\"complementary\">\n <!-- pagination -->\n {{nav pagination}}\n </div>\n </div>\n <!-- Column: content -->\n <div class=\"col-md-9\" role=\"main\">\n <div class=\"docs-section\">\n <div class=\"docs-header\" id=\"content\">\n <h4><strong>Page layout:</strong> {{default originalLayout '(no layout defined)'}}</h4>\n <h4><strong>Page src:</strong> {{page.src}}</h4>\n <h4><strong>Page dest:</strong> {{page.dest}}</h4>\n <h4><strong>Dest filename:</strong> {{page.filename}}</h4>\n <h4><strong>Dest basename:</strong> {{page.basename}}</h4>\n <h4><strong>Page title:</strong> {{default title '(no title defined)'}}</h4>\n </div>\n\n <hr>\n <div class=\"row\">\n <div class=\"col-md-6\">\n <!-- Categories Collection -->\n {{#if categories}}\n {{> collections-categories }}\n {{/if}}\n </div>\n <div class=\"col-md-6\">\n {{#if tags}}\n {{> collections-tags }}\n {{/if}}\n </div>\n </div>\n\n <hr>\n\n \n<div class=\"page-header\">\n <h4>{{{title}}}</h4>\n</div>\n\n\n<!-- Customer Information\n============================================ -->\n<div class=\"customer-information\">\n <h4 style=\"background: #eee; display: block\">Customer Information</h4>\n <dl class=\"dl-horizontal\">\n <dt>Receipt:</dt>\n <dd>{{receipt}}</dd>\n\n <dt>Date:</dt>\n <dd>{{prettyDate}}</dd>\n\n <dt>First Name:</dt>\n <dd>{{customer.given}}</dd>\n\n <dt>Last Name:</dt>\n <dd>{{customer.family}}</dd>\n </dl>\n</div>\n\n<hr>\n\n<!-- Order Information\n============================================ -->\n<div class=\"customer-information\">\n <h4 style=\"background: #eee; display: block\">Order Information</h4>\n <dl class=\"dl-horizontal\">\n <dt>Items:</dt>\n {{#each items}}\n <dd>\n <strong class=\"muted\" style=\"border-bottom: 1px solid #ddd; display: block\">Item #{{@index}}</strong>\n <dl class=\"dl-horizontal\">\n <dt>Part No: </dt>\n <dd> {{part_no}} </dd>\n <dt>Description: </dt>\n <dd> {{descrip}} </dd>\n <dt>Price: </dt>\n <dd> ${{price}} </dd>\n <dt>Qty: </dt>\n <dd> {{quantity}} </dd>\n </dl>\n </dd>\n {{/each}}\n </dl>\n</div>\n<hr>\n\n<!-- Bill To\n============================================ -->\n<div class=\"bill-to\">\n <h4 style=\"background: #eee; display: block\">Address Information</h4>\n <strong>Bill To:</strong>\n <dl class=\"dl-horizontal\">\n <dt>Billing Street: </dt>\n <dd> {{bill-to.street}} </dd>\n <dt>Billing City: </dt>\n <dd> {{bill-to.city}} </dd>\n <dt>Billing State: </dt>\n <dd> {{bill-to.state}} </dd>\n </dl>\n <strong>Ship To:</strong>\n <dl class=\"dl-horizontal\">\n <dt>Shipping Street: </dt>\n <dd> {{ship-to.street}} </dd>\n <dt>Shipping City: </dt>\n <dd> {{ship-to.city}} </dd>\n <dt>Shipping State: </dt>\n <dd> {{ship-to.state}} </dd>\n </dd>\n </dl>\n</div>\n\n<!-- Special Instructions\n============================================ -->\n<div class=\"special-instructions\" style=\"margin-bottom: 120px;\">\n <h4 style=\"background: #eee; display: block\">Delivery Instructions</h4>\n <p>{{{specialDelivery}}}</p>\n</div>\n\n <div class=\"docs-header\" id=\"content\">\n <h1>Content</h1>\n </div>\n <ul>\n {{#each pages}}\n <li> <a href=\"{{relativeLink}}\">{{filename}}</a></li>\n {{/each}}\n </ul>\n\n <hr>\n <div style=\"display: none\">\n\n <h1>Page</h1>\n <!--\n \"this\"\n ===============================\n this.src: {{this.src}}\n this.dest: {{this.dest}}\n this.layout: {{this.layout}}\n this.dirname: {{this.dirname}}\n this.filename: {{this.filename}}\n this.pagename: {{this.pagename}}\n this.basename: {{this.basename}}\n this.ext: {{this.ext}}\n\n \"page\"\n ===============================\n page.src: {{page.src}}\n page.dest: {{page.dest}}\n page.layout: {{page.layout}}\n page.dirname: {{page.dirname}}\n page.filename: {{page.filename}}\n page.pagename: {{page.pagename}}\n page.basename: {{page.basename}}\n page.ext: {{page.ext}}\n\n \"root\"\n ===============================\n src: {{src}}\n dest: {{dest}}\n layout: {{layout}}\n dirname: {{dirname}}\n filename: {{filename}}\n pagename: {{pagename}}\n basename: {{basename}}\n ext: {{ext}}\n -->\n <h1>Each pages</h1>\n <ul>\n {{#each pages}}<li><a href=\"{{relativeLink}}\">{{filename}}</a> </li>\n <!--\n \"this\"\n ===============================\n this.src: {{this.src}}\n this.dest: {{this.dest}}\n this.dirname: {{this.dirname}}\n this.filename: {{this.filename}}\n this.pagename: {{this.pagename}}\n this.basename: {{this.basename}}\n this.ext: {{this.ext}}\n\n \"page\"\n ===============================\n page.src: {{../page.src}}\n page.dest: {{../page.dest}}\n page.dirname: {{../page.dirname}}\n page.filename: {{../page.filename}}\n page.pagename: {{../page.pagename}}\n page.basename: {{../page.basename}}\n page.ext: {{../page.ext}}\n\n \"root\"\n ===============================\n src: {{src}}\n dest: {{dest}}\n dirname: {{dirname}}\n filename: {{filename}}\n pagename: {{pagename}}\n basename: {{basename}}\n ext: {{ext}}\n -->\n {{/each}}\n </ul>\n\n <h1>Debug Info </h1>\n {{{inspect page 'json'}}}\n </div>\n </div>\n </div>\n </div>\n </div>\n <script src=\"{{assets}}/validation.js\"></script>\n </body>\n</html>\n",
"pageName": "document.html",
"pagename": "document.html",
- "prettyDate": "2007-08-05",
+ "prettyDate": "2013-10-08",
"prev": 4,
"receipt": "Oz-Ware Purchase Invoice",
"relativeLink": "document.html",

2 comments on commit 32324d3

@taurose

This change is giving me some trouble.
I simply have a data file called foo.yaml and want to include it via yaml fm like so

bar: '<%= foo %>'

Without the change, it worked as expected, but now bar is turned into an empty string.

@jonschlinkert

Agreed, this will be reverted today.

Please sign in to comment.
Something went wrong with that request. Please try again.