Revert "Revert "now using handlebars for client side templates" for now"
This reverts commit 5f9c469b12.
This commit is contained in:
parent
5bd929b697
commit
5d15c53f6b
19 changed files with 1597 additions and 20 deletions
|
|
@ -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))
|
||||||
|
|
|
||||||
1
app/views/templates/static_text.handlebars
Normal file
1
app/views/templates/static_text.handlebars
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<span class=text>{{ text }}</span>
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<span class=text><%= text %></span>
|
|
||||||
5
app/views/templates/stream_faces.handlebars
Normal file
5
app/views/templates/stream_faces.handlebars
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{{#people}}
|
||||||
|
<a href="/people/{{id}}">
|
||||||
|
<img class="avatar" src="{{avatar.small}}" title="{{name}}"/>
|
||||||
|
</a>
|
||||||
|
{{/people}}
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<% _.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:
|
||||||
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({
|
||||||
},
|
},
|
||||||
|
|
||||||
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();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
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",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
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",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
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(), {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
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",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
app.views.Header = app.views.Base.extend({
|
app.views.Header = app.views.Base.extend({
|
||||||
|
legacyTemplate : true,
|
||||||
|
|
||||||
template_name : "#header-template",
|
template_name : "#header-template",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
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({
|
||||||
},
|
},
|
||||||
|
|
||||||
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)})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
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({
|
||||||
|
|
||||||
//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});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
app.views.Stream = Backbone.View.extend({
|
app.views.Stream = Backbone.View.extend({
|
||||||
|
legacyTemplate : true,
|
||||||
events: {
|
events: {
|
||||||
"click #paginate": "render"
|
"click #paginate": "render"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
1550
public/javascripts/vendor/handlebars-1.0.0.beta.6.js
vendored
Normal file
1550
public/javascripts/vendor/handlebars-1.0.0.beta.6.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,7 @@
|
||||||
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(){
|
||||||
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:
|
||||||
- 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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue