Skip to content

Commit

Permalink
Merge pull request #46 from vimia/BL-23-2
Browse files Browse the repository at this point in the history
BL-23 / BL-22 - EJS Filters + Moment.js DateFromNow filter!
  • Loading branch information
marceloboeira committed Sep 17, 2014
2 parents 64b7e15 + 8709f42 commit 0a16297
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
20 changes: 20 additions & 0 deletions api/services/FilterService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* View Filters
*
* @see https://github.com/vimia/blew/issues/23
*/
module.exports = {

/**
* Apply moment.js at server-side as a filter
*
* @param d - Dirty Date
* @return 'x days ago'
*/
dateFromNow: function(d) {
var moment = require('moment');
return moment(d).fromNow();
}
//TODO - Date Component creator..
}

8 changes: 8 additions & 0 deletions config/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

module.exports.bootstrap = function(cb) {
cb();

/**
* Injecting EJS Filters in the FilterService
*
* @see https://github.com/vimia/blew/issues/23
*/
sails.config.http.locals.filters = FilterService;
_.extend(sails.hooks.http.app.locals, sails.config.http.locals);
};
8 changes: 7 additions & 1 deletion config/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ module.exports.http = {
'500'
],
},
cache: 31557600000
cache: 31557600000,

// Keep to FilerService work
locals: {
filters: []
}
};

4 changes: 2 additions & 2 deletions views/index/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<td><a pjax href="<%= paste.getLink() %>"> <%= paste.name %> </a></td>
<td><%= paste.language %></td>
<td><a pjax href="<%= paste.owner.getLink() %>"><%= paste.owner.name %></a></td>
<td><date source="<%= paste.createdAt %>"></date></td>
<td><date source="<%= paste.updatedAt %>"></date></td>
<td><date source="<%= paste.createdAt %>"><%=: paste.createdAt | dateFromNow %></date></td>
<td><date source="<%= paste.updatedAt %>"><%=: paste.updatedAt | dateFromNow %></date></td>
</tr>
<% }); %>
<tbody>
Expand Down
8 changes: 5 additions & 3 deletions views/paste/view.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
<h1><i class="fa fa-file-code-o "></i> <%= paste.name %></h1>
<hr>
<i class="fa fa-code"></i> <%= paste.language %> |
<i class="fa fa-user"></i> <a pjax href="<%= paste.owner.getLink() %>"><%= paste.owner.name %> </a> |
<i class="fa fa-calendar"></i> <%= __("Created") %> <date source="<%= paste.createdAt %>"></date> |
<i class="fa fa-clock-o"></i> <%= __("Updated") %> <date source="<%= paste.updatedAt %>"></date>
<i class="fa fa-user"></i> <a pjax href="<%= paste.owner.getLink() %>"><%= paste.owner.name %> </a> |
<i class="fa fa-calendar"></i> <%= __("Created") %>
<date source="<%= paste.createdAt %>"><%=: paste.createdAt | dateFromNow %>"</date> |
<i class="fa fa-clock-o"></i> <%= __("Updated") %>
<date source="<%= paste.updatedAt %>"><%=: paste.updatedAt | dateFromNow %></date>
<hr>
</div>
</div>
Expand Down
15 changes: 6 additions & 9 deletions views/user/view.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="container">
<div class="row">
<div class="col-sm-10">

<a pjax class="h1 font-bold" href="<%= user.getLink() %>"><h1><%= user.name %></h1></a>
</div>
<div class="col-sm-2"><a href="/users" class="pull-right"><img title="profile image" class="img-circle img-responsive" src="<%= user.getGravatar({s:120}) %>"></a></div>
Expand All @@ -13,10 +12,10 @@

<li class="list-group-item text-right">
<span class="pull-left"><strong><%= __('Joined') %> </strong></span>
<date source="<%= user.createdAt %>"></date>
<date source="<%= user.createdAt %>"><%=: user.createdAt | dateFromNow %></date>
</li>
<li class="list-group-item text-right"><span class="pull-left">
<strong><%= __('Last Seen') %> </strong></span> <date source="<%= user.updatedAt %>"></date>
<strong><%= __('Last Seen') %> </strong></span> <date source="<%= user.updatedAt %>"><%=: user.updatedAt | dateFromNow %></date>
</li>
<li class="list-group-item text-right">
<span class="pull-left"><strong><%= __('Username') %></strong></span> <%= user.username %>
Expand Down Expand Up @@ -53,8 +52,9 @@
<tr>
<td><a pjax href="<%= paste.getLink() %>"> <%= paste.name %> </a></td>
<td><%= paste.language %></td>
<td><date source="<%= paste.createdAt %>"></date></td>
<td><date source="<%= paste.updatedAt %>"></date></td>
<td><date source="<%= paste.createdAt %>"><%=: paste.createdAt | dateFromNow %></date></td>
<td><date source="<%= paste.updatedAt %>"><%=: paste.updatedAt | dateFromNow %></date></td>
</tr>
<% }); %>
</tbody>
Expand Down Expand Up @@ -89,11 +89,8 @@
</tbody>
</table>
!>
</div>
</div>
</div>
</div>
</div>
</div>

0 comments on commit 0a16297

Please sign in to comment.