From a5f297d7f7b1443d4f4b5a8132a1a880e08b52cc Mon Sep 17 00:00:00 2001 From: Raphael Sofaer <raphael@joindiaspora.com> Date: Thu, 28 Apr 2011 10:38:33 -0700 Subject: [PATCH] Don't include every helper everywhere, re-organize helpers --- app/controllers/application_controller.rb | 2 + app/controllers/aspects_controller.rb | 1 + app/controllers/contacts_controller.rb | 1 + app/controllers/people_controller.rb | 1 + app/controllers/photos_controller.rb | 1 + app/controllers/requests_controller.rb | 2 - app/controllers/sockets_controller.rb | 1 + app/controllers/status_messages_controller.rb | 3 +- app/controllers/tags_controller.rb | 3 +- app/controllers/users_controller.rb | 1 + app/helpers/application_helper.rb | 20 ++++---- app/helpers/aspect_memberships_helper.rb | 36 +++++++++++++++ app/helpers/aspects_helper.rb | 46 ++----------------- .../{stream_helper.rb => comments_helper.rb} | 2 +- app/helpers/conversations_helper.rb | 5 -- app/helpers/layout_helper.rb | 8 ++++ app/helpers/notifications_helper.rb | 3 -- app/helpers/people_helper.rb | 4 ++ app/helpers/requests_helper.rb | 16 ------- app/helpers/tags_helper.rb | 9 ++++ app/views/people/show.html.haml | 2 +- ...helper_spec.rb => comments_helper_spec.rb} | 2 +- 22 files changed, 89 insertions(+), 80 deletions(-) create mode 100644 app/helpers/aspect_memberships_helper.rb rename app/helpers/{stream_helper.rb => comments_helper.rb} (97%) delete mode 100644 app/helpers/conversations_helper.rb delete mode 100644 app/helpers/requests_helper.rb create mode 100644 app/helpers/tags_helper.rb rename spec/helpers/{stream_helper_spec.rb => comments_helper_spec.rb} (95%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 595d963a84..9f1432300b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,8 @@ # the COPYRIGHT file. class ApplicationController < ActionController::Base + clear_helpers + helper :layout, :error_messages has_mobile_fu protect_from_forgery :except => :receive diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 6da08ba72b..15c01772e2 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class AspectsController < ApplicationController + helper :comments, :aspect_memberships before_filter :authenticate_user! before_filter :save_sort_order, :only => :index before_filter :ensure_page, :only => :index diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index a567fc8387..7bf5241434 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class ContactsController < ApplicationController + helper :aspect_memberships before_filter :authenticate_user! def new diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 97f0b7b8a8..33a5fe9718 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class PeopleController < ApplicationController + helper :comments before_filter :authenticate_user!, :except => [:show] before_filter :ensure_page, :only => :show diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 94f40d7288..ba33f6a993 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class PhotosController < ApplicationController + helper :comments before_filter :authenticate_user! respond_to :html, :json diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 114b487416..943795f063 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -6,8 +6,6 @@ require File.join(Rails.root, 'lib/webfinger') class RequestsController < ApplicationController before_filter :authenticate_user! - include RequestsHelper - respond_to :html def destroy diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 7ed70b1cb9..913ead7396 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class SocketsController < ApplicationController + helper :comments include ApplicationHelper include SocketsHelper include Rails.application.routes.url_helpers diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 1eae974487..2b0e89ace7 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class StatusMessagesController < ApplicationController + helper :comments before_filter :authenticate_user! respond_to :html @@ -25,7 +26,7 @@ class StatusMessagesController < ApplicationController end end - def bookmarklet + def bookmarklet @aspects = current_user.aspects @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq @aspect_ids = @aspects.map{|x| x.id} diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 444c5627b6..1a52eddb41 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class TagsController < ApplicationController + helper :comments skip_before_filter :count_requests skip_before_filter :set_invites skip_before_filter :which_action_and_user @@ -54,7 +55,7 @@ class TagsController < ApplicationController @posts = @posts.tagged_with(params[:name]) max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now - @posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time)) + @posts = @posts.where(StatusMessage.arel_table[:created_at].lteq(max_time)) @posts = @posts.includes(:comments, :photos).order('posts.created_at DESC').limit(15) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 431259e518..343bc64fbd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,6 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. class UsersController < ApplicationController + helper :language require File.join(Rails.root, 'lib/diaspora/ostatus_builder') require File.join(Rails.root, 'lib/diaspora/exporter') require File.join(Rails.root, 'lib/collect_user_photos') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f3c65d9a48..a1b1a8b6ba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,13 +5,6 @@ module ApplicationHelper @@youtube_title_cache = Hash.new("no-title") - def next_page_path - if @controller.instance_of?(TagsController) - tag_path(@tag, :max_time => @posts.last.send(session[:sort_order].to_sym).to_i) - else - aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids]) - end - end def timeago(time, options = {}) options[:class] ||= "timeago" content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time @@ -86,8 +79,19 @@ module ApplicationHelper </li>".html_safe end + def link_for_aspect(aspect, opts={}) + opts[:params] ||= {} + params ||= {} + opts[:params] = opts[:params].merge("a_ids[]" => aspect.id, :created_at => params[:created_at]) + opts[:class] ||= "" + opts[:class] << " hard_aspect_link" + opts['data-guid'] = aspect.id + + link_to aspect.name, aspects_path( opts[:params] ), opts + end + def current_aspect?(aspect) - !@aspect.nil? && !@aspect.is_a?(Symbol) && @aspect.id == aspect.id + !@aspect.nil? && !@aspect.instance_of?(Symbol) && @aspect.id == aspect.id end def aspect_or_all_path aspect diff --git a/app/helpers/aspect_memberships_helper.rb b/app/helpers/aspect_memberships_helper.rb new file mode 100644 index 0000000000..8949f6e6e6 --- /dev/null +++ b/app/helpers/aspect_memberships_helper.rb @@ -0,0 +1,36 @@ +module AspectMembershipsHelper + def add_to_aspect_button(aspect_id, person_id, kontroller) + link_to image_tag('icons/monotone_plus_add_round.png'), + {:controller => kontroller, + :action => 'create', + :aspect_id => aspect_id, + :person_id => person_id}, + :remote => true, + :method => 'post', + :class => 'add button' + end + + def remove_from_aspect_button(aspect_id, person_id) + link_to image_tag('icons/monotone_check_yes.png'), + {:controller => "aspect_memberships", + :action => 'destroy', + :id => 42, + :aspect_id => aspect_id, + :person_id => person_id}, + :remote => true, + :method => 'delete', + :class => 'added button' + end + + def aspect_membership_button(aspect, contact, person) + if contact.nil? || !aspect.contacts.include?(contact) + add_to_aspect_button(aspect.id, person.id, contact_or_membership(contact)) + else + remove_from_aspect_button(aspect.id, person.id) + end + end + + def contact_or_membership(contact) + (contact.persisted?) ? 'aspect_memberships' : 'contacts' + end +end diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index bcab3a14d0..9c1a4e6783 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -3,15 +3,8 @@ # the COPYRIGHT file. module AspectsHelper - def link_for_aspect(aspect, opts={}) - opts[:params] ||= {} - params ||= {} - opts[:params] = opts[:params].merge("a_ids[]" => aspect.id, :created_at => params[:created_at]) - opts[:class] ||= "" - opts[:class] << " hard_aspect_link" - opts['data-guid'] = aspect.id - - link_to aspect.name, aspects_path( opts[:params] ), opts + def next_page_path + aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids], :class => 'paginate') end def remove_link(aspect) @@ -22,38 +15,9 @@ module AspectsHelper end end - def add_to_aspect_button(aspect_id, person_id, kontroller) - link_to image_tag('icons/monotone_plus_add_round.png'), - {:controller => kontroller, - :action => 'create', - :aspect_id => aspect_id, - :person_id => person_id}, - :remote => true, - :method => 'post', - :class => 'add button' - end - - def remove_from_aspect_button(aspect_id, person_id) - link_to image_tag('icons/monotone_check_yes.png'), - {:controller => "aspect_memberships", - :action => 'destroy', - :id => 42, - :aspect_id => aspect_id, - :person_id => person_id}, - :remote => true, - :method => 'delete', - :class => 'added button' - end - - def contact_or_membership(contact) - (contact.persisted?) ? 'aspect_memberships' : 'contacts' - end - - def aspect_membership_button(aspect, contact, person) - if contact.nil? || !aspect.contacts.include?(contact) - add_to_aspect_button(aspect.id, person.id, contact_or_membership(contact)) - else - remove_from_aspect_button(aspect.id, person.id) + def new_request_link(request_count) + if request_count > 0 + link_to t('requests.helper.new_requests', :count => @request_count), manage_aspects_path end end end diff --git a/app/helpers/stream_helper.rb b/app/helpers/comments_helper.rb similarity index 97% rename from app/helpers/stream_helper.rb rename to app/helpers/comments_helper.rb index 3fdb1c6804..0df7ee28f1 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/comments_helper.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -module StreamHelper +module CommentsHelper GSUB_THIS = "FIUSDHVIUSHDVIUBAIUHAPOIUXJM" def comment_toggle(count, commenting_disabled=false) if count <= 3 diff --git a/app/helpers/conversations_helper.rb b/app/helpers/conversations_helper.rb deleted file mode 100644 index e9370a658d..0000000000 --- a/app/helpers/conversations_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module ConversationsHelper - def new_message_text(count) - t('conversations.helper.new_messages', :count => count) - end -end diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 166e6b2548..e8707e4122 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -23,4 +23,12 @@ module LayoutHelper def javascript(*args) content_for(:head) { javascript_include_tag(*args) } end + + def new_notification_text(count) + t('notifications.helper.new_notifications', :count => count) + end + + def new_message_text(count) + t('conversations.helper.new_messages', :count => count) + end end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index a49f1578cf..e722797bf6 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -33,9 +33,6 @@ module NotificationsHelper t("notifications.#{target_type}", :post_author => post_author) end - def new_notification_text(count) - t('notifications.helper.new_notifications', :count => count) - end def new_notification_link(count) if count > 0 diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index b149abca86..a8b16b44ac 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -27,4 +27,8 @@ module PeopleHelper I18n.l bday, :format => I18n.t('date.formats.birthday_with_year') end end + + def next_page_path + person_path(@person, :max_time => @posts.last.created_at.to_i, :class => 'paginate') + end end diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb deleted file mode 100644 index d54a29de2c..0000000000 --- a/app/helpers/requests_helper.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module RequestsHelper - - def new_request?(request_count) - 'new_requests' if request_count > 0 - end - - def new_request_link(request_count) - if request_count > 0 - link_to t('requests.helper.new_requests', :count => @request_count), manage_aspects_path - end - end -end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 0000000000..9511f624e6 --- /dev/null +++ b/app/helpers/tags_helper.rb @@ -0,0 +1,9 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module TagsHelper + def next_page_path + tag_path(@tag, :max_time => @posts.last.created_at.to_i, :class => 'paginate') + end +end diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index f8870beba4..20e7f6b9ed 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -82,7 +82,7 @@ #main_stream.stream = render 'shared/stream', :posts => @posts, :commenting_disabled => @commenting_disabled #pagination - =link_to(t('more'), person_path(@person, :page => next_page), :class => 'paginate') + =link_to(t('more'), next_page_path) - else #stream diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/comments_helper_spec.rb similarity index 95% rename from spec/helpers/stream_helper_spec.rb rename to spec/helpers/comments_helper_spec.rb index 1b2d96b49a..7880ab4df8 100644 --- a/spec/helpers/stream_helper_spec.rb +++ b/spec/helpers/comments_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe StreamHelper do +describe CommentsHelper do before do @user = alice @aspect = @user.aspects.first -- GitLab