Skip to content

Commit

Permalink
got full handlebars setup working
Browse files Browse the repository at this point in the history
  • Loading branch information
ProCynic committed Jun 24, 2013
1 parent 3603ef4 commit e176236
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
8 changes: 1 addition & 7 deletions controllers/products.js
Expand Up @@ -14,8 +14,6 @@ var getProduct = module.exports.getProduct = function(req, res, next) {
if (err) return res.json(500, err);
if (response.statusCode !== 200) res.send(response.statusCode, body); //TODO: better

logger.info('product from magic: ' + body);

var product = JSON.parse(body).data;

var data = {
Expand All @@ -28,18 +26,14 @@ var getProduct = module.exports.getProduct = function(req, res, next) {
twitter: product.businessTwitter
},
image: {
url: product.photoUrl + '/convert?fit=clip&w=320&h=320', //TODO: switch to using hb filepicker helper
url: product.photoUrl,
width: 320,
height: 320
},
price: product.price != null ? '$' + product.price / 100 : null
}
};

if (product.photoUrl == null) delete data.product.image;

logger.info('compiling template with data: ' + JSON.stringify(data));

res.send(view(data));
});
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -10,6 +10,7 @@
}
],
"scripts": {
"prestart": "find views -name *handlebars | xargs -I {} echo node_modules/.bin/handlebars {} -f {} | sed 's/\\(.*\\)\\/.*\\.handlebars/\\1\\/index.js/g' | sh",
"start": "node ./main.js"
},
"main": "./server.js",
Expand Down
2 changes: 2 additions & 0 deletions views/index.js
@@ -1,5 +1,7 @@
global.Handlebars = require('handlebars');

require('./handlebars-helpers').register(global.Handlebars);

require('./product');

module.exports = Handlebars.templates;
4 changes: 2 additions & 2 deletions views/product/product.handlebars
@@ -1,15 +1,15 @@
<!doctype html>
<html>
<head>
{{#if product.image}}
{{#if product.image.url}}
<meta name="twitter:card" content="product">
<meta name="twitter:site" content="@goodybagATX">
{{#if product.business.twitter}}
<meta name="twitter:creator" content="{{product.business.twitter}}">
{{/if}}
<meta name="twitter:title" content="{{product.name}}">
<meta name="twitter:description" content="{{product.description}}">
<meta name="twitter:image" content="{{product.image.url}}">
<meta name="twitter:image" content="{{filepicker product.image.url product.image.width product.image.height}}">
<meta name="twitter:image:width" content="{{product.image.width}}">
<meta name="twitter:image:height" content="{{product.image.height}}">
<meta name="twitter:label1" content="Business">
Expand Down

0 comments on commit e176236

Please sign in to comment.