Added plates support #89

Open
wants to merge 9 commits into
from

Conversation

Projects
None yet
4 participants

No description provided.

study and others added some commits Jan 24, 2013

@ForbesLindesay ForbesLindesay commented on an outdated diff Jan 25, 2013

lib/consolidate.js
+
+/**
+* Plates Support.
+*/
+
+exports.plates = fromStringRenderer('plates');
+
+/**
+* Plates string support.
+*/
+
+exports.plates.render = function(str, options, fn) {
+ var engine = requires.plates || (requires.plates = require('plates'))
+ , map = options.map || undefined;
+ try {
+ var tmpl = cache(options) || cache(options, engine.bind(str, options, map));
@ForbesLindesay

ForbesLindesay Jan 25, 2013

Contributor

This caches too much, you can't use caching with it, if you pass the options when you do caching then dynamic sites won't work. consolidate will automatically cache the string so you just need:

var tmpl = engine.bind(str, options, map);

@tj tj and 1 other commented on an outdated diff Jan 29, 2013

@@ -67,6 +68,20 @@ cons[name]('views/page.html', { user: 'tobi' }, function(err, html){
console.log(html);
});
```
+### Example using [Plates](https://github.com/flatiron/plates)
+
+Plates accepts an optional third argument, a mapping object. To pass a map object through consolidate add it to options.map.
+
+```js
+var cons = require('consolidate')
+ , _map = require('plates').Map();
+
+_map.class('list').append('views/partial.html', {item: ['one', 'two']});
+cons.plates('views/user.html', {user: 'Tobi', map: _map}, function(err, html) {
+ if (err) throw err;
+ console.log(html);
+});
@tj

tj Jan 29, 2013

Owner

i dont think we should even bother with specific examples, if it cant fit the consolidate model it shouldn't be in the lib

@ForbesLindesay

ForbesLindesay Jan 29, 2013

Contributor

I agree, for cases like this people can read the source to work out how to pass the map option to plates.

@BridgeAR BridgeAR commented on the diff Jan 21, 2016

test/shared/index.js
@@ -18,7 +18,7 @@ exports.test = function(name) {
var locals = { user: user };
cons[name](path, locals, function(err, html){
if (err) return done(err);
- html.should.equal('<p>Tobi</p>');
+ html.should.match(/Tobi/);
@BridgeAR

BridgeAR Jan 21, 2016

Collaborator

Does the <p>...</p> really has to be removed? I guess using match with the p should still be possible? And if the id is going to be kept, you might aswell add that as optional part in the regex to match that too.

Collaborator

BridgeAR commented Jan 21, 2016

Please rebase and squash your commits. Otherwise, besides my comment, it's LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment