Skip to content

Commit

Permalink
adds grunt.config.process to pageContext so that lodash templates are…
Browse files Browse the repository at this point in the history
… 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
jonschlinkert committed Dec 5, 2013
1 parent 727323f commit 32324d3
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 74 deletions.
46 changes: 0 additions & 46 deletions EXAMPLES.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tasks/assemble.js
Expand Up @@ -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);

This comment has been minimized.

Copy link
@doowb

doowb Dec 5, 2013

Member

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.

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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

This comment has been minimized.

Copy link
@doowb

doowb Dec 5, 2013

Member

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.

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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

This comment has been minimized.

Copy link
@doowb

doowb Dec 5, 2013

Member

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.

This comment has been minimized.

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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...?

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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"...

This comment has been minimized.

Copy link
@doowb

doowb Dec 5, 2013

Member

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.

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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?

This comment has been minimized.

Copy link
@doowb

doowb Dec 5, 2013

Member

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.

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Dec 5, 2013

Author Member

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


// Page object
var pageObj = {
Expand Down
4 changes: 1 addition & 3 deletions test/actual/collections/asc/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/collections/asc/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
4 changes: 1 addition & 3 deletions test/actual/collections/complex/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/collections/complex/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
4 changes: 1 addition & 3 deletions test/actual/collections/custom/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/collections/custom/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
4 changes: 1 addition & 3 deletions test/actual/collections/desc/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/collections/desc/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
4 changes: 1 addition & 3 deletions test/actual/paths/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/paths/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
4 changes: 1 addition & 3 deletions test/actual/plugin_preprocess/collections-pages.html
Expand Up @@ -411,9 +411,7 @@ <h4>Pages Collection</h4>
<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>
Expand Down
2 changes: 1 addition & 1 deletion test/actual/plugin_preprocess/context.html
Expand Up @@ -573,7 +573,7 @@ <h4>Pages related to each tag</h4>
<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>
Expand Down
6 changes: 3 additions & 3 deletions test/actual/yfm/document.html
Expand Up @@ -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>
Expand Down Expand Up @@ -587,7 +587,7 @@ <h1>Debug Info</h1>
"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"
Expand Down Expand Up @@ -671,7 +671,7 @@ <h1>Debug Info</h1>
"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",
Expand Down

2 comments on commit 32324d3

@agundermann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this will be reverted today.

Please sign in to comment.