Skip to content

Commit

Permalink
created view helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 9, 2014
1 parent b5bdc2a commit afb04bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var Account = require('../models/account');
var moment = require('moment');
var accountHelper = require('../helpers/accounts_helper');

exports.init = function(req, res){
res.render('accounts/init');
Expand All @@ -21,7 +22,7 @@ exports.index = function(req, res){

exports.show = function(req, res){
Account.findById(req.params.id, function(account){
res.render('accounts/show', {account:account, moment:moment});
res.render('accounts/show', {account:account, moment:moment, helper:accountHelper});
});
};

Expand Down
18 changes: 18 additions & 0 deletions app/helpers/accounts_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

exports.wd = function(type){
if(type === 'withdraw'){
return '#ff4136';
}else{
return '#2ecc40';
}
};

exports.tf = function(from){
if(from !== ''){
return '#7fdbff';
}else{
return '#ff851b';
}
};

4 changes: 2 additions & 2 deletions app/views/accounts/show.jade
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ block content
th Fee
tbody
each tr in account.transactions
tr
tr(style='background-color:#{helper.wd(tr.type)};')
td= tr.id
td= moment(tr.date).format('ll')
td= tr.type
Expand All @@ -52,7 +52,7 @@ block content
th Fee
tbody
each tr in account.transfers
tr
tr(style='background-color:#{helper.tf(tr.from)};')
td= tr.id
td= moment(tr.date).format('ll')
td= tr.from
Expand Down

0 comments on commit afb04bc

Please sign in to comment.