Skip to content
Extraits de code Groupes Projets
Valider 5d15c53f rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

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

This reverts commit 5f9c469b.
parent 5bd929b6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 1597 ajouts et 20 suppressions
...@@ -3,3 +3,9 @@ ...@@ -3,3 +3,9 @@
- template_name = File.basename(template, ".jst").gsub("_","-") - template_name = File.basename(template, ".jst").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'} %script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(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))
<span class=text>{{ text }}</span>
<span class=text><%= text %></span>
{{#people}}
<a href="/people/{{id}}">
<img class="avatar" src="{{avatar.small}}" title="{{name}}"/>
</a>
{{/people}}
<% _.each(people, function(person) { %>
<a href="/people/<%= person.id %>">
<img class="avatar" src="<%= person.avatar.small %>" title="<%= person.name %>"/>
</a>
<% }) %>
...@@ -9,6 +9,7 @@ javascripts: ...@@ -9,6 +9,7 @@ javascripts:
main: main:
- public/javascripts/vendor/underscore.js - public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js - public/javascripts/vendor/backbone.js
- public/javascripts/vendor/handlebars-1.0.0.beta.6.js
- public/javascripts/vendor/markdown/* - public/javascripts/vendor/markdown/*
- public/javascripts/app/app.js - public/javascripts/app/app.js
- public/javascripts/app/helpers/* - public/javascripts/app/helpers/*
......
...@@ -22,9 +22,18 @@ app.views.Base = Backbone.View.extend({ ...@@ -22,9 +22,18 @@ app.views.Base = Backbone.View.extend({
}, },
renderTemplate : function(){ renderTemplate : function(){
var templateHTML = $(this.template_name).html(); //don't forget to regenerate your jasmine fixtures ;-) var templateHTML //don't forget to regenerate your jasmine fixtures ;-)
this.template = _.template(templateHTML);
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter 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.el).html(this.template(presenter));
this.postRenderTemplate(); this.postRenderTemplate();
}, },
......
app.views.Comment = app.views.Content.extend({ app.views.Comment = app.views.Content.extend({
legacyTemplate : true,
template_name: "#comment-template", template_name: "#comment-template",
tagName : "li", tagName : "li",
......
app.views.CommentStream = app.views.Base.extend({ app.views.CommentStream = app.views.Base.extend({
legacyTemplate : true,
template_name: "#comment-stream-template", template_name: "#comment-stream-template",
className : "comment_stream", className : "comment_stream",
......
app.views.Content = app.views.StreamObject.extend({ app.views.Content = app.views.StreamObject.extend({
legacyTemplate : true,
presenter : function(){ presenter : function(){
var model = this.model var model = this.model
return _.extend(this.defaultPresenter(), { return _.extend(this.defaultPresenter(), {
......
app.views.Feedback = app.views.StreamObject.extend({ app.views.Feedback = app.views.StreamObject.extend({
legacyTemplate : true,
template_name: "#feedback-template", template_name: "#feedback-template",
className : "info", className : "info",
......
app.views.Header = app.views.Base.extend({ app.views.Header = app.views.Base.extend({
legacyTemplate : true,
template_name : "#header-template", template_name : "#header-template",
......
app.views.LikesInfo = app.views.StreamObject.extend({ app.views.LikesInfo = app.views.StreamObject.extend({
legacyTemplate : true,
template_name : "#likes-info-template", template_name : "#likes-info-template",
className : "likes_container", className : "likes_container",
events : { events : {
"click .expand_likes" : "showAvatars" "click .expand_likes" : "showAvatars"
}, },
tooltipSelector : ".avatar", tooltipSelector : ".avatar",
...@@ -15,12 +16,12 @@ app.views.LikesInfo = app.views.StreamObject.extend({ ...@@ -15,12 +16,12 @@ app.views.LikesInfo = app.views.StreamObject.extend({
}, },
showAvatars : function(evt){ showAvatars : function(evt){
if(evt) { evt.preventDefault() } if(evt) { evt.preventDefault() }
var self = this; var self = this;
this.model.likes.fetch() this.model.likes.fetch()
.done(function(resp){ .done(function(resp){
// set like attribute and like collection // set like attribute and like collection
self.model.set({likes : self.model.likes.reset(resp)}) self.model.set({likes : self.model.likes.reset(resp)})
}) })
} }
}); });
app.views.Post = app.views.StreamObject.extend({ app.views.Post = app.views.StreamObject.extend({
legacyTemplate : true,
template_name: "#stream-element-template", template_name: "#stream-element-template",
...@@ -28,11 +29,14 @@ app.views.Post = app.views.StreamObject.extend({ ...@@ -28,11 +29,14 @@ app.views.Post = app.views.StreamObject.extend({
//subviews //subviews
this.commentStreamView = new app.views.CommentStream({ model : this.model}); this.commentStreamView = new app.views.CommentStream({ model : this.model});
this.likesInfoView = new app.views.LikesInfo({ model : this.model});
return this; return this;
}, },
likesInfoView : function(){
return new app.views.LikesInfo({ model : this.model});
},
feedbackView : function(){ feedbackView : function(){
if(!window.app.user().current_user ) { return null } if(!window.app.user().current_user ) { return null }
return new app.views.Feedback({model : this.model}); return new app.views.Feedback({model : this.model});
......
app.views.StreamFaces = app.views.Base.extend({ app.views.StreamFaces = app.views.Base.extend({
templateName : "stream-faces",
template_name : "#stream-faces-template",
className : "stream-faces", className : "stream-faces",
......
app.views.Stream = Backbone.View.extend({ app.views.Stream = Backbone.View.extend({
legacyTemplate : true,
events: { events: {
"click #paginate": "render" "click #paginate": "render"
}, },
......
Ce diff est replié.
describe("app.views.Base", function(){ describe("app.views.Base", function(){
describe("#render", function(){ describe("#render", function(){
beforeEach(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.model = new Backbone.Model({text : "model attributes are in the default presenter"})
this.view = new staticTemplateClass({model: this.model}) this.view = new staticTemplateClass({model: this.model})
...@@ -21,7 +21,7 @@ describe("app.views.Base", function(){ ...@@ -21,7 +21,7 @@ describe("app.views.Base", function(){
context("subViewRendering", function(){ context("subViewRendering", function(){
beforeEach(function(){ beforeEach(function(){
var viewClass = app.views.Base.extend({ var viewClass = app.views.Base.extend({
template_name : "#static-text-template", templateName : "static-text",
subviews : { subviews : {
".subview1": "subview1", ".subview1": "subview1",
".subview2": "createSubview2" ".subview2": "createSubview2"
......
...@@ -26,6 +26,7 @@ src_files: ...@@ -26,6 +26,7 @@ src_files:
- public/javascripts/jquery.infieldlabel-custom.js - public/javascripts/jquery.infieldlabel-custom.js
- public/javascripts/vendor/underscore.js - public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js - public/javascripts/vendor/backbone.js
- public/javascripts/vendor/handlebars-1.0.0.beta.6.js
- public/javascripts/fileuploader-custom.js - public/javascripts/fileuploader-custom.js
- public/javascripts/jquery.autocomplete-custom.js - public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/diaspora.js - public/javascripts/diaspora.js
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter