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.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
clear_helpers
|
||||||
|
helper :layout, :error_messages
|
||||||
has_mobile_fu
|
has_mobile_fu
|
||||||
protect_from_forgery :except => :receive
|
protect_from_forgery :except => :receive
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class AspectsController < ApplicationController
|
class AspectsController < ApplicationController
|
||||||
|
helper :comments, :aspect_memberships
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :save_sort_order, :only => :index
|
before_filter :save_sort_order, :only => :index
|
||||||
before_filter :ensure_page, :only => :index
|
before_filter :ensure_page, :only => :index
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class ContactsController < ApplicationController
|
class ContactsController < ApplicationController
|
||||||
|
helper :aspect_memberships
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class PeopleController < ApplicationController
|
class PeopleController < ApplicationController
|
||||||
|
helper :comments
|
||||||
before_filter :authenticate_user!, :except => [:show]
|
before_filter :authenticate_user!, :except => [:show]
|
||||||
before_filter :ensure_page, :only => :show
|
before_filter :ensure_page, :only => :show
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class PhotosController < ApplicationController
|
class PhotosController < ApplicationController
|
||||||
|
helper :comments
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
respond_to :html, :json
|
respond_to :html, :json
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ require File.join(Rails.root, 'lib/webfinger')
|
||||||
|
|
||||||
class RequestsController < ApplicationController
|
class RequestsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
include RequestsHelper
|
|
||||||
|
|
||||||
respond_to :html
|
respond_to :html
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class SocketsController < ApplicationController
|
class SocketsController < ApplicationController
|
||||||
|
helper :comments
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include SocketsHelper
|
include SocketsHelper
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class StatusMessagesController < ApplicationController
|
class StatusMessagesController < ApplicationController
|
||||||
|
helper :comments
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
respond_to :html
|
respond_to :html
|
||||||
|
|
@ -25,7 +26,7 @@ class StatusMessagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmarklet
|
def bookmarklet
|
||||||
@aspects = current_user.aspects
|
@aspects = current_user.aspects
|
||||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
|
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
|
||||||
@aspect_ids = @aspects.map{|x| x.id}
|
@aspect_ids = @aspects.map{|x| x.id}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class TagsController < ApplicationController
|
class TagsController < ApplicationController
|
||||||
|
helper :comments
|
||||||
skip_before_filter :count_requests
|
skip_before_filter :count_requests
|
||||||
skip_before_filter :set_invites
|
skip_before_filter :set_invites
|
||||||
skip_before_filter :which_action_and_user
|
skip_before_filter :which_action_and_user
|
||||||
|
|
@ -54,7 +55,7 @@ class TagsController < ApplicationController
|
||||||
@posts = @posts.tagged_with(params[:name])
|
@posts = @posts.tagged_with(params[:name])
|
||||||
|
|
||||||
max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
|
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)
|
@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
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
helper :language
|
||||||
require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
|
require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
|
||||||
require File.join(Rails.root, 'lib/diaspora/exporter')
|
require File.join(Rails.root, 'lib/diaspora/exporter')
|
||||||
require File.join(Rails.root, 'lib/collect_user_photos')
|
require File.join(Rails.root, 'lib/collect_user_photos')
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,6 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
@@youtube_title_cache = Hash.new("no-title")
|
@@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 = {})
|
def timeago(time, options = {})
|
||||||
options[:class] ||= "timeago"
|
options[:class] ||= "timeago"
|
||||||
content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time
|
content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time
|
||||||
|
|
@ -86,8 +79,19 @@ module ApplicationHelper
|
||||||
</li>".html_safe
|
</li>".html_safe
|
||||||
end
|
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)
|
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
|
end
|
||||||
|
|
||||||
def aspect_or_all_path aspect
|
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.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module AspectsHelper
|
module AspectsHelper
|
||||||
def link_for_aspect(aspect, opts={})
|
def next_page_path
|
||||||
opts[:params] ||= {}
|
aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids], :class => 'paginate')
|
||||||
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
|
end
|
||||||
|
|
||||||
def remove_link(aspect)
|
def remove_link(aspect)
|
||||||
|
|
@ -22,38 +15,9 @@ module AspectsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_aspect_button(aspect_id, person_id, kontroller)
|
def new_request_link(request_count)
|
||||||
link_to image_tag('icons/monotone_plus_add_round.png'),
|
if request_count > 0
|
||||||
{:controller => kontroller,
|
link_to t('requests.helper.new_requests', :count => @request_count), manage_aspects_path
|
||||||
: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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module StreamHelper
|
module CommentsHelper
|
||||||
GSUB_THIS = "FIUSDHVIUSHDVIUBAIUHAPOIUXJM"
|
GSUB_THIS = "FIUSDHVIUSHDVIUBAIUHAPOIUXJM"
|
||||||
def comment_toggle(count, commenting_disabled=false)
|
def comment_toggle(count, commenting_disabled=false)
|
||||||
if count <= 3
|
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)
|
def javascript(*args)
|
||||||
content_for(:head) { javascript_include_tag(*args) }
|
content_for(:head) { javascript_include_tag(*args) }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,6 @@ module NotificationsHelper
|
||||||
t("notifications.#{target_type}", :post_author => post_author)
|
t("notifications.#{target_type}", :post_author => post_author)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_notification_text(count)
|
|
||||||
t('notifications.helper.new_notifications', :count => count)
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_notification_link(count)
|
def new_notification_link(count)
|
||||||
if count > 0
|
if count > 0
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,8 @@ module PeopleHelper
|
||||||
I18n.l bday, :format => I18n.t('date.formats.birthday_with_year')
|
I18n.l bday, :format => I18n.t('date.formats.birthday_with_year')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def next_page_path
|
||||||
|
person_path(@person, :max_time => @posts.last.created_at.to_i, :class => 'paginate')
|
||||||
|
end
|
||||||
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
|
#main_stream.stream
|
||||||
= render 'shared/stream', :posts => @posts, :commenting_disabled => @commenting_disabled
|
= render 'shared/stream', :posts => @posts, :commenting_disabled => @commenting_disabled
|
||||||
#pagination
|
#pagination
|
||||||
=link_to(t('more'), person_path(@person, :page => next_page), :class => 'paginate')
|
=link_to(t('more'), next_page_path)
|
||||||
|
|
||||||
- else
|
- else
|
||||||
#stream
|
#stream
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe StreamHelper do
|
describe CommentsHelper do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect = @user.aspects.first
|
@aspect = @user.aspects.first
|
||||||
Loading…
Reference in a new issue