Revert "Revert "now using handlebars for client side templates" for now"

This reverts commit 5f9c469b12.
This commit is contained in:
danielgrippi 2012-01-22 18:40:50 -08:00
parent 5bd929b697
commit 5d15c53f6b
19 changed files with 1597 additions and 20 deletions

View file

@ -3,3 +3,9 @@
- template_name = File.basename(template, ".jst").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(template))
- #don't tell my mom I did this, okay?
- Dir[templates_dir.to_s + "/*.handlebars"].each do |template|
- template_name = File.basename(template, ".handlebars").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(template))

View file

@ -0,0 +1 @@
<span class=text>{{ text }}</span>

View file

@ -1 +0,0 @@
<span class=text><%= text %></span>

View file

@ -0,0 +1,5 @@
{{#people}}
<a href="/people/{{id}}">
<img class="avatar" src="{{avatar.small}}" title="{{name}}"/>
</a>
{{/people}}

View file

@ -1,5 +0,0 @@
<% _.each(people, function(person) { %>
<a href="/people/<%= person.id %>">
<img class="avatar" src="<%= person.avatar.small %>" title="<%= person.name %>"/>
</a>
<% }) %>

View file

@ -9,6 +9,7 @@ javascripts:
main:
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js
- public/javascripts/vendor/handlebars-1.0.0.beta.6.js
- public/javascripts/vendor/markdown/*
- public/javascripts/app/app.js
- public/javascripts/app/helpers/*

View file

@ -22,9 +22,18 @@ app.views.Base = Backbone.View.extend({
},
renderTemplate : function(){
var templateHTML = $(this.template_name).html(); //don't forget to regenerate your jasmine fixtures ;-)
this.template = _.template(templateHTML);
var templateHTML //don't forget to regenerate your jasmine fixtures ;-)
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter
if(this.legacyTemplate) {
templateHTML = $(this.template_name).html();
this.template = _.template(templateHTML);
} else {
window.templateCache = window.templateCache || {}
templateHTML = $("#" + this.templateName + "-template").html(); //don't forget to regenerate your jasmine fixtures ;-)
this.template = templateCache[this.templateName] = templateCache[this.templateName] || Handlebars.compile(templateHTML);
}
$(this.el).html(this.template(presenter));
this.postRenderTemplate();
},

View file

@ -1,5 +1,6 @@
app.views.Comment = app.views.Content.extend({
legacyTemplate : true,
template_name: "#comment-template",
tagName : "li",

View file

@ -1,5 +1,6 @@
app.views.CommentStream = app.views.Base.extend({
legacyTemplate : true,
template_name: "#comment-stream-template",
className : "comment_stream",

View file

@ -1,4 +1,5 @@
app.views.Content = app.views.StreamObject.extend({
legacyTemplate : true,
presenter : function(){
var model = this.model
return _.extend(this.defaultPresenter(), {

View file

@ -1,4 +1,5 @@
app.views.Feedback = app.views.StreamObject.extend({
legacyTemplate : true,
template_name: "#feedback-template",
className : "info",

View file

@ -1,4 +1,5 @@
app.views.Header = app.views.Base.extend({
legacyTemplate : true,
template_name : "#header-template",

View file

@ -1,5 +1,6 @@
app.views.LikesInfo = app.views.StreamObject.extend({
legacyTemplate : true,
template_name : "#likes-info-template",
className : "likes_container",

View file

@ -1,4 +1,5 @@
app.views.Post = app.views.StreamObject.extend({
legacyTemplate : true,
template_name: "#stream-element-template",
@ -28,11 +29,14 @@ app.views.Post = app.views.StreamObject.extend({
//subviews
this.commentStreamView = new app.views.CommentStream({ model : this.model});
this.likesInfoView = new app.views.LikesInfo({ model : this.model});
return this;
},
likesInfoView : function(){
return new app.views.LikesInfo({ model : this.model});
},
feedbackView : function(){
if(!window.app.user().current_user ) { return null }
return new app.views.Feedback({model : this.model});

View file

@ -1,6 +1,5 @@
app.views.StreamFaces = app.views.Base.extend({
template_name : "#stream-faces-template",
templateName : "stream-faces",
className : "stream-faces",

View file

@ -1,4 +1,5 @@
app.views.Stream = Backbone.View.extend({
legacyTemplate : true,
events: {
"click #paginate": "render"
},

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
describe("app.views.Base", function(){
describe("#render", function(){
beforeEach(function(){
var staticTemplateClass = app.views.Base.extend({ template_name : "#static-text-template" })
var staticTemplateClass = app.views.Base.extend({ templateName : "static-text" })
this.model = new Backbone.Model({text : "model attributes are in the default presenter"})
this.view = new staticTemplateClass({model: this.model})
@ -21,7 +21,7 @@ describe("app.views.Base", function(){
context("subViewRendering", function(){
beforeEach(function(){
var viewClass = app.views.Base.extend({
template_name : "#static-text-template",
templateName : "static-text",
subviews : {
".subview1": "subview1",
".subview2": "createSubview2"

View file

@ -26,6 +26,7 @@ src_files:
- public/javascripts/jquery.infieldlabel-custom.js
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js
- public/javascripts/vendor/handlebars-1.0.0.beta.6.js
- public/javascripts/fileuploader-custom.js
- public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/diaspora.js