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("_","-")
|
||||
%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))
|
||||
|
|
|
|||
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:
|
||||
- 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/*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
app.views.Comment = app.views.Content.extend({
|
||||
|
||||
legacyTemplate : true,
|
||||
template_name: "#comment-template",
|
||||
|
||||
tagName : "li",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
app.views.CommentStream = app.views.Base.extend({
|
||||
|
||||
legacyTemplate : true,
|
||||
template_name: "#comment-stream-template",
|
||||
|
||||
className : "comment_stream",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
app.views.Content = app.views.StreamObject.extend({
|
||||
legacyTemplate : true,
|
||||
presenter : function(){
|
||||
var model = this.model
|
||||
return _.extend(this.defaultPresenter(), {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
app.views.Feedback = app.views.StreamObject.extend({
|
||||
legacyTemplate : true,
|
||||
template_name: "#feedback-template",
|
||||
|
||||
className : "info",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
app.views.Header = app.views.Base.extend({
|
||||
legacyTemplate : true,
|
||||
|
||||
template_name : "#header-template",
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
app.views.LikesInfo = app.views.StreamObject.extend({
|
||||
|
||||
legacyTemplate : true,
|
||||
template_name : "#likes-info-template",
|
||||
|
||||
className : "likes_container",
|
||||
|
||||
events : {
|
||||
"click .expand_likes" : "showAvatars"
|
||||
"click .expand_likes" : "showAvatars"
|
||||
},
|
||||
|
||||
tooltipSelector : ".avatar",
|
||||
|
|
@ -15,12 +16,12 @@ app.views.LikesInfo = app.views.StreamObject.extend({
|
|||
},
|
||||
|
||||
showAvatars : function(evt){
|
||||
if(evt) { evt.preventDefault() }
|
||||
var self = this;
|
||||
this.model.likes.fetch()
|
||||
.done(function(resp){
|
||||
if(evt) { evt.preventDefault() }
|
||||
var self = this;
|
||||
this.model.likes.fetch()
|
||||
.done(function(resp){
|
||||
// set like attribute and like collection
|
||||
self.model.set({likes : self.model.likes.reset(resp)})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
app.views.StreamFaces = app.views.Base.extend({
|
||||
|
||||
template_name : "#stream-faces-template",
|
||||
templateName : "stream-faces",
|
||||
|
||||
className : "stream-faces",
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
app.views.Stream = Backbone.View.extend({
|
||||
legacyTemplate : true,
|
||||
events: {
|
||||
"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("#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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue