From 5d051fcc5226c855d726c64647d5f04fbc40cf08 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sun, 5 Feb 2012 16:34:40 -0800 Subject: [PATCH] we're now rolling 100% handlebars for our templates, with jammit handling them as static assets. --- app/views/layouts/_templates.haml | 5 -- app/views/layouts/application.html.haml | 2 - app/views/templates/reshare.jst | 53 ------------------- public/javascripts/app/app.js | 8 --- .../app/helpers/handlebars-helpers.js | 7 +++ .../app/helpers/handlebars-partials.js | 4 ++ .../app/templates/reshare.handlebars | 43 +++++++++++++++ .../app/templates/status-message.handlebars | 4 +- public/javascripts/app/views.js | 13 ++--- public/javascripts/app/views/content_view.js | 18 ++++--- public/javascripts/app/views/header_view.js | 1 + public/javascripts/app/views/post_view.js | 1 + .../javascripts/app/views/publisher_view.js | 1 + .../app/views/stream_faces_view.js | 1 + .../app/views/stream_object_view.js | 1 + public/javascripts/app/views/stream_view.js | 2 +- 16 files changed, 78 insertions(+), 86 deletions(-) delete mode 100644 app/views/layouts/_templates.haml delete mode 100644 app/views/templates/reshare.jst create mode 100644 public/javascripts/app/helpers/handlebars-helpers.js create mode 100644 public/javascripts/app/helpers/handlebars-partials.js create mode 100644 public/javascripts/app/templates/reshare.handlebars diff --git a/app/views/layouts/_templates.haml b/app/views/layouts/_templates.haml deleted file mode 100644 index 625d7bb8f..000000000 --- a/app/views/layouts/_templates.haml +++ /dev/null @@ -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)) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3c9c401c2..ab97407c2 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/templates/reshare.jst b/app/views/templates/reshare.jst deleted file mode 100644 index fbf63432c..000000000 --- a/app/views/templates/reshare.jst +++ /dev/null @@ -1,53 +0,0 @@ -
- - <% if(root) { %> - - - - - -
-
- - - <%= root.author.name %> - - - - - - - - - - <% if(root.reshares_count) { %> - - - <%= Diaspora.I18n.t("stream.reshares", {count : root.reshares_count}) %> - <% } %> -
- - - <% if(root.photos && root.photos.length > 0) { %> -
- - <% for(photo in root.photos) { - if(photo == 0){ continue; } - if(photo == 8){ break; } %> - - <% } %> - <% } %> - -
- <%= text %> - <%= o_embed_html %> - - - -
- - <% } else { %> -

- <%= Diaspora.I18n.t('stream.original_post_deleted') %> -

- <% } %> -
diff --git a/public/javascripts/app/app.js b/public/javascripts/app/app.js index bdcb43e7f..fdb4bf0c5 100644 --- a/public/javascripts/app/app.js +++ b/public/javascripts/app/app.js @@ -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(); }); diff --git a/public/javascripts/app/helpers/handlebars-helpers.js b/public/javascripts/app/helpers/handlebars-helpers.js new file mode 100644 index 000000000..0adc587c3 --- /dev/null +++ b/public/javascripts/app/helpers/handlebars-helpers.js @@ -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; +}) \ No newline at end of file diff --git a/public/javascripts/app/helpers/handlebars-partials.js b/public/javascripts/app/helpers/handlebars-partials.js new file mode 100644 index 000000000..228d438dd --- /dev/null +++ b/public/javascripts/app/helpers/handlebars-partials.js @@ -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'])) +}) \ No newline at end of file diff --git a/public/javascripts/app/templates/reshare.handlebars b/public/javascripts/app/templates/reshare.handlebars new file mode 100644 index 000000000..131c5dd48 --- /dev/null +++ b/public/javascripts/app/templates/reshare.handlebars @@ -0,0 +1,43 @@ +
+ + {{#if root}} + + {{#with root}} + + + + +
+
+ + + {{author.name}} + + + + + - + + + + + {{#if reshares_count}} + - + {{t "stream.reshares" count=reshares_count}} + {{/if}} +
+ + {{> status-message}} + +
+ {{/with}} + + {{else}} + +

+ {{t "stream.original_post_deleted"}} +

+ {{/if}} + +
diff --git a/public/javascripts/app/templates/status-message.handlebars b/public/javascripts/app/templates/status-message.handlebars index 5b846eb1a..c0e9bf4e1 100644 --- a/public/javascripts/app/templates/status-message.handlebars +++ b/public/javascripts/app/templates/status-message.handlebars @@ -1,9 +1,9 @@ -{{#if photos.length}} +{{#if largePhoto}}
{{#with largePhoto}} - + {{/with}} diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js index 8c24996f5..49332c6b5 100644 --- a/public/javascripts/app/views.js +++ b/public/javascripts/app/views.js @@ -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(); }, diff --git a/public/javascripts/app/views/content_view.js b/public/javascripts/app/views/content_view.js index 220f68ccf..802af4ad6 100644 --- a/public/javascripts/app/views/content_view.js +++ b/public/javascripts/app/views/content_view.js @@ -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" }); diff --git a/public/javascripts/app/views/header_view.js b/public/javascripts/app/views/header_view.js index 457c3c517..2b23cc2bc 100644 --- a/public/javascripts/app/views/header_view.js +++ b/public/javascripts/app/views/header_view.js @@ -1,4 +1,5 @@ app.views.Header = app.views.Base.extend({ + templateName : "header", tagName : "header", diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 6689e48ab..1db0c2178 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -1,4 +1,5 @@ app.views.Post = app.views.StreamObject.extend({ + templateName: "stream-element", className : "stream_element loaded", diff --git a/public/javascripts/app/views/publisher_view.js b/public/javascripts/app/views/publisher_view.js index 7f8e9d916..79eba2a07 100644 --- a/public/javascripts/app/views/publisher_view.js +++ b/public/javascripts/app/views/publisher_view.js @@ -3,6 +3,7 @@ //this with PANACHE! app.views.Publisher = Backbone.View.extend({ + el : "#publisher", events : { diff --git a/public/javascripts/app/views/stream_faces_view.js b/public/javascripts/app/views/stream_faces_view.js index eb2075462..9c975105c 100644 --- a/public/javascripts/app/views/stream_faces_view.js +++ b/public/javascripts/app/views/stream_faces_view.js @@ -1,4 +1,5 @@ app.views.StreamFaces = app.views.Base.extend({ + templateName : "stream-faces", className : "stream-faces", diff --git a/public/javascripts/app/views/stream_object_view.js b/public/javascripts/app/views/stream_object_view.js index 5c74e4ffd..85334ab69 100644 --- a/public/javascripts/app/views/stream_object_view.js +++ b/public/javascripts/app/views/stream_object_view.js @@ -1,4 +1,5 @@ app.views.StreamObject = app.views.Base.extend({ + initialize: function(options) { this.setupRenderEvents(); }, diff --git a/public/javascripts/app/views/stream_view.js b/public/javascripts/app/views/stream_view.js index 99d1dbcd2..20e9566ac 100644 --- a/public/javascripts/app/views/stream_view.js +++ b/public/javascripts/app/views/stream_view.js @@ -1,5 +1,5 @@ app.views.Stream = Backbone.View.extend({ - legacyTemplate : true, + events: { "click #paginate": "render" },