From 03e3c3a2022ea2e35e5b5d000a7f493415cf28e3 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Mon, 29 Nov 2010 15:31:17 -0800 Subject: [PATCH] Render comment partial with collection option --- app/controllers/comments_controller.rb | 4 ++-- app/helpers/sockets_helper.rb | 2 +- app/views/comments/_comment.html.haml | 3 ++- app/views/comments/_comments.html.haml | 14 +------------- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index cfb18b30c7..9e8f35c2a4 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -26,10 +26,10 @@ class CommentsController < ApplicationController :comment_id => @comment.id, :html => render_to_string( :partial => 'comments/comment', - :locals => { + :locals => { :hash => { :comment => @comment, :person => current_user, - } + }} ) } render(:json => json, :status => 201) diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 430264fee2..44481788cc 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -27,7 +27,7 @@ module SocketsHelper elsif object.is_a? Person v = render_to_string(:partial => type_partial(object), :locals => {:single_aspect_form => opts[:single_aspect_form], :person => object, :aspects => user.aspects, :current_user => user}) elsif object.is_a? Comment - v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.person}) + v = render_to_string(:partial => 'comments/comment', :locals => {:hash => {:comment => object, :person => object.person}}) else v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction end diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 7071e9ccc2..719b8c22d2 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -1,7 +1,8 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - +- comment = hash[:comment] +- person = hash[:person] %li.comment{:data=>{:guid=>comment.id}} %a{:href => "/people/#{person.id}"} %img{:src => image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id} diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index 41b716ea63..3d80c6cf39 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -3,19 +3,7 @@ -# the COPYRIGHT file. %ul.comments{:id => post_id, :class => ("hidden" if comment_hashes.size == 0)} - - for comment_hash in comment_hashes - -comment = comment_hash[:comment] - -person = comment_hash[:person] - - %li.comment{:data=>{:guid=>comment.id}} - %a{:href => "/people/#{person.id}"} - %img{:src => image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id} - .content - .from - %a{:href => "/people/#{person.id}"}=person.real_name - = markdownify(comment.text, :youtube_maps => comment[:youtube_titles]) - %div.time - = comment.created_at ? "#{time_ago_in_words(comment.created_at)}" : Time.now + = render :partial => 'comments/comment', :collection => comment_hashes, :as => :hash %li.comment.show = render 'comments/new_comment', :post_id => post_id -- GitLab