Don't include every helper everywhere, re-organize helpers
This commit is contained in:
parent
4ed621fc1f
commit
a5f297d7f7
22 changed files with 89 additions and 80 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class ContactsController < ApplicationController
|
||||
helper :aspect_memberships
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def new
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class PeopleController < ApplicationController
|
||||
helper :comments
|
||||
before_filter :authenticate_user!, :except => [:show]
|
||||
before_filter :ensure_page, :only => :show
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class PhotosController < ApplicationController
|
||||
helper :comments
|
||||
before_filter :authenticate_user!
|
||||
|
||||
respond_to :html, :json
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class SocketsController < ApplicationController
|
||||
helper :comments
|
||||
include ApplicationHelper
|
||||
include SocketsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
36
app/helpers/aspect_memberships_helper.rb
Normal file
36
app/helpers/aspect_memberships_helper.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
module ConversationsHelper
|
||||
def new_message_text(count)
|
||||
t('conversations.helper.new_messages', :count => count)
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
9
app/helpers/tags_helper.rb
Normal file
9
app/helpers/tags_helper.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe StreamHelper do
|
||||
describe CommentsHelper do
|
||||
before do
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
Loading…
Reference in a new issue