we're now rolling 100% handlebars for our templates, with jammit handling them as static assets.

This commit is contained in:
danielgrippi 2012-02-05 16:34:40 -08:00
parent 36e5ca431f
commit 5d051fcc52
16 changed files with 78 additions and 86 deletions

View file

@ -1,5 +0,0 @@
- templates_dir = Rails.root.join("app", "views", "templates")
- Dir[templates_dir.to_s + "/*.jst"].each do |template|
- template_name = File.basename(template, ".jst").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(template))

View file

@ -127,8 +127,6 @@
%header
= render 'layouts/header'
= render 'layouts/templates'
.container{:style=> "#{yield(:break_the_mold)}"}
- if @aspsect == :getting_started || @page == :logged_out
= yield

View file

@ -1,53 +0,0 @@
<div class="reshare">
<% if(root) { %>
<a href="/people/<%= root.author.guid %>">
<img src="<%= root.author.avatar.small %>" class="avatar" data-person-id="<%= root.author.id %>"/>
</a>
<div class="content">
<div class="post_initial_info">
<span class="from">
<a href="/people/<%= root.author.guid %>">
<%= root.author.name %>
</a>
</span>
<span class="details">
-
<a href="/posts/<%= root.id %>">
<time class="timeago" datetime="<%= root.created_at %>"/>
</a>
</span>
<% if(root.reshares_count) { %>
-
<%= Diaspora.I18n.t("stream.reshares", {count : root.reshares_count}) %>
<% } %>
</div>
<!-- duplicate from statusmessage partial -->
<% if(root.photos && root.photos.length > 0) { %>
<div class="photo_attachments">
<img src="<%= root.photos[0].sizes.large %>" class="stream-photo big_stream_photo">
<% for(photo in root.photos) {
if(photo == 0){ continue; }
if(photo == 8){ break; } %>
<img src="<%= root.photos[photo].sizes.small %>" class="stream-photo thumb_small">
<% } %>
<% } %>
<div class="collapsible">
<%= text %>
<%= o_embed_html %>
</div">
<!-- end duplication -->
</div>
<% } else { %>
<p>
<%= Diaspora.I18n.t('stream.original_post_deleted') %>
</p>
<% } %>
</div>

View file

@ -37,13 +37,5 @@ var app = {
};
$(function() {
Handlebars.registerHelper('t', function(scope, values) {
return Diaspora.I18n.t(scope, values.hash)
})
Handlebars.registerHelper('imageUrl', function(path){
return app.baseImageUrl() + path;
})
app.initialize();
});

View file

@ -0,0 +1,7 @@
Handlebars.registerHelper('t', function(scope, values) {
return Diaspora.I18n.t(scope, values.hash)
})
Handlebars.registerHelper('imageUrl', function(path){
return app.baseImageUrl() + path;
})

View file

@ -0,0 +1,4 @@
/* we need to wrap this in a document ready to ensure JST is accessible */
$(function(){
Handlebars.registerPartial('status-message', Handlebars.compile(JST['status-message']))
})

View file

@ -0,0 +1,43 @@
<div class="reshare">
{{#if root}}
{{#with root}}
<a href="/people/{{author.guid}}">
<img src="{{author.avatar.small}}" class="avatar" />
</a>
<div class="content">
<div class="post_initial_info">
<span class="from">
<a href="/people/{{author.guid}}">
{{author.name}}
</a>
</span>
<span class="details">
-
<a href="/posts/{{id}}">
<time class="timeago" datetime="{{created_at}}"/>
</a>
</span>
{{#if reshares_count}}
-
{{t "stream.reshares" count=reshares_count}}
{{/if}}
</div>
{{> status-message}}
</div>
{{/with}}
{{else}}
<p>
{{t "stream.original_post_deleted"}}
</p>
{{/if}}
</div>

View file

@ -1,9 +1,9 @@
{{#if photos.length}}
{{#if largePhoto}}
<div class="photo_attachments">
<a href="#" class="stream-photo-link">
{{#with largePhoto}}
<img src="{{sizes.large}}" class="stream-photo big_stream_photo" data-small-photo="{{sizes.small}}" data-full-photo="{{sizes.large}}" rel="lightbox">
<img src="{{sizes.large}}" class="stream-photo big_stream_photo" data-small-photo="{{sizes.small}}" data-full-photo="{{largePhoto.sizes.large}}" rel="lightbox">
{{/with}}
</a>

View file

@ -25,15 +25,10 @@ app.views.Base = Backbone.View.extend({
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 = JST[this.templateName];
this.template = templateCache[this.templateName] = templateCache[this.templateName] || Handlebars.compile(templateHTML);
}
window.templateCache = window.templateCache || {}
templateHTML = JST[this.templateName];
this.template = templateCache[this.templateName] = templateCache[this.templateName] || Handlebars.compile(templateHTML);
$(this.el).html(this.template(presenter));
this.postRenderTemplate();
},

View file

@ -1,11 +1,13 @@
app.views.Content = app.views.StreamObject.extend({
presenter : function(){
var model = this.model
presenter : function(model){
var model = model || this.model
return _.extend(this.defaultPresenter(), {
text : app.helpers.textFormatter(model),
o_embed_html : embedHTML(model),
largePhoto : this.largePhoto(),
smallPhotos : this.smallPhotos()
smallPhotos : this.smallPhotos(),
root : this.rootPresenter(model)
})
function embedHTML(model){
@ -29,6 +31,12 @@ app.views.Content = app.views.StreamObject.extend({
var photos = this.model.get("photos")
if(!photos || photos.length < 2) { return }
return photos.slice(1,8)
},
// should be a private function in this.presenter()
rootPresenter : function(model) {
if(!model || !model.get("root")) { return }
return this.presenter(new app.models.Post(model.get("root")))
}
})
@ -37,12 +45,10 @@ app.views.StatusMessage = app.views.Content.extend({
});
app.views.Reshare = app.views.Content.extend({
legacyTemplate : true,
template_name : "#reshare-template"
templateName : "reshare"
});
app.views.ActivityStreams__Photo = app.views.Content.extend({
legacyTemplate : false,
templateName : "activity-streams-photo"
});

View file

@ -1,4 +1,5 @@
app.views.Header = app.views.Base.extend({
templateName : "header",
tagName : "header",

View file

@ -1,4 +1,5 @@
app.views.Post = app.views.StreamObject.extend({
templateName: "stream-element",
className : "stream_element loaded",

View file

@ -3,6 +3,7 @@
//this with PANACHE!
app.views.Publisher = Backbone.View.extend({
el : "#publisher",
events : {

View file

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

View file

@ -1,4 +1,5 @@
app.views.StreamObject = app.views.Base.extend({
initialize: function(options) {
this.setupRenderEvents();
},

View file

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