Skip to content

Commit

Permalink
tweaks to disable tabs feature
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorturk committed Feb 10, 2010
1 parent 07ef34f commit 14441ae
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 74 deletions.
58 changes: 26 additions & 32 deletions app/helpers/application_helper.rb
@@ -1,33 +1,32 @@
module ApplicationHelper
module ApplicationHelper

def random_string
char = ("a".."z").to_a + ("1".."9").to_a
Array.new(6, '').collect{char[rand(char.size)]}.join
end

protected

def header_image_path
if current_controller == 'headers' && %w(edit show).include?(current_action)
@header = Header.find(params[:id])
else
@header = Header.random
end

@header and @header.attachment.url or "/images/eldorado.jpg"
end

def header_css
if @settings.clickable_header
return ""
else
return "<style type=\"text/css\">.header { background: url('#{header_image_path}'); }</style>"
end
end

def theme_css
return "<style type=\"text/css\">@import url('/stylesheets/application.css');</style>" if @settings.theme.blank?
return "<style type=\"text/css\">@import url('#{@settings.theme}');</style>"
return "<style type=\"text/css\">@import url('/stylesheets/application.css');</style>" if @settings.theme.blank?
return "<style type=\"text/css\">@import url('#{@settings.theme}');</style>"
end

def page_title
Expand All @@ -36,15 +35,15 @@ def page_title
page = @settings.tagline if current_controller == 'home'
"#{@settings.title}: #{item || page}"
end

def favicon_tag
return "<link rel=\"shortcut icon\" href=\"#{@settings.favicon}\" />\n" unless @settings.favicon.blank?
end

def avatar_for(user)
image_tag user.avatar unless user.avatar.nil?
end

def rank_for(user)
return I18n.t(:rank_administrator) if user.admin
return I18n.t(:rank_banned) if user.banned?
Expand All @@ -56,7 +55,7 @@ def rank_for(user)
return I18n.t(:rank_member) if @rank.nil? # if no ranks are low enough
return h(@rank.title)
end

def tab(name)
if name == current_controller
'current_tab'
Expand All @@ -66,7 +65,12 @@ def tab(name)
'current_tab'
end
end


def enabled?(name)
return true if CONFIG['disabled_tabs'].nil?
!CONFIG['disabled_tabs'].include?(name)
end

def is_new?(item)
return false unless logged_in?
if item.is_a?(Topic)
Expand All @@ -76,19 +80,19 @@ def is_new?(item)
session[:online_at] < item.updated_at
end
end

def icon_for(item)
if item && is_new?(item)
'<div class="icon inew"><!-- --></div>'
else
'<div class="icon"><!-- --></div>'
end
end

def bb(text)
auto_link(simple_format(bbcodeize(sanitize(h(text))))) {|t| truncate(t, :length => 50)}
end

def current_page(collection)
I18n.t(:page)+' ' + number_with_delimiter(collection.current_page).to_s + ' ' + I18n.t(:of) + ' ' + number_with_delimiter(collection.total_pages).to_s unless collection.total_pages == 0
end
Expand All @@ -98,18 +102,17 @@ def prev_page(collection)
link_to('&laquo; '+I18n.t(:previous_page), { :page => collection.previous_page }.merge(params.reject{|k,v| k=='page'}))
end
end

def next_page(collection)
unless collection.current_page == collection.total_pages or collection.total_pages == 0
link_to(I18n.t(:next_page)+' &raquo;', { :page => collection.next_page }.merge(params.reject{|k,v| k=='page'}))
end
end

def t_no_of(item, count = 0)
I18n.t item, :count => count, :print_count => number_with_delimiter(count)
end


def time_ago_or_time_stamp(from_time, to_time = Time.now.utc, include_seconds = true, detail = false)
return '&ndash;' if from_time.nil?
from_time = from_time.to_time if from_time.respond_to?(:to_time)
Expand All @@ -128,17 +131,8 @@ def time_ago_or_time_stamp(from_time, to_time = Time.now.utc, include_seconds =
return time_stamp(from_time) if (detail && distance_in_minutes > 2880)
return time
end

def time_stamp(time, short = false)
I18n.l(time, :format => ( short ? :ed_timestamp_short : :ed_timestamp ) )
end

def disabled_feature?(f)
# Admins can see all features
return false if (current_user != 0 and current_user.admin)

disabled_features = (CONFIG["disabled_features"] or "").split(",").map { |x| x.strip }
disabled_features.include?(f)
def time_stamp(time, short = false)
I18n.l(time, :format => ( short ? :ed_timestamp_short : :ed_timestamp ) )
end

end
end
24 changes: 8 additions & 16 deletions app/views/home/index.html.erb
@@ -1,22 +1,14 @@
<div class="home-left">
<% unless @chatters.empty? || @message.nil? %>
<div class="info-left">
<span class="title"><%= link_to I18n.t(:chat), chat_path %></span>
<span class="detail">
<%= render :partial => 'messages/chatters' %>
&nbsp;|&nbsp; <%= link_to "Last active #{time_ago_or_time_stamp(@message.created_at)}", chat_path, :class => 'text' if @message %>
</span>
</div>
<% end %>
<%= render :file => 'topics/index' %>
<%= render :partial => 'messages/mini' if enabled?('forum') %>
<%= render :file => 'topics/index' if enabled?('forum') %>
</div>

<div class="home-right">
<%= render :partial => 'events/mini.html.erb' if not disabled_feature?("events")%>
<%= render :file => 'uploads/index' %>
<%= render :file => 'headers/list' %>
<%= render :file => 'users/index' if not disabled_feature?("users") %>
<%= render :file => 'avatars/list' %>
<%= render :partial => 'events/mini' if enabled?('events') %>
<%= render :file => 'uploads/index' if enabled?('files') %>
<%= render :file => 'headers/list' if enabled?('headers') %>
<%= render :file => 'users/index' if enabled?('users') %>
<%= render :file => 'avatars/list' if enabled?('avatars') %>
</div>

<div class="clear"> </div>
<div class="clear"> </div>
9 changes: 9 additions & 0 deletions app/views/messages/_mini.html.erb
@@ -0,0 +1,9 @@
<% unless @chatters.empty? || @message.nil? %>
<div class="info-left">
<span class="title"><%= link_to I18n.t(:chat), chat_path %></span>
<span class="detail">
<%= render :partial => 'messages/chatters' %>
&nbsp;|&nbsp; <%= link_to "Last active #{time_ago_or_time_stamp(@message.created_at)}", chat_path, :class => 'text' if @message %>
</span>
</div>
<% end %>
19 changes: 9 additions & 10 deletions app/views/shared/tabs.html.erb
@@ -1,11 +1,10 @@
<ul class="tabs">
<% # The home tab should always be visible %>
<li id="tab-home" class="tab <%= tab('home') %>"><%= link_to I18n.t(:home), root_path %></li>
<% if not disabled_feature? "blog" %><li id="tab-blog" class="tab <%= tab('articles') %>"><%= link_to I18n.t(:blog), blog_path %></li><% end %>
<% if not disabled_feature? "chat" %><li id="tab-chat" class="tab <%= tab('messages') %>"><%= link_to I18n.t(:chat), chat_path %></li><% end %>
<% if not disabled_feature? "events" %><li id="tab-events" class="tab <%= tab('events') %>"><%= link_to I18n.t(:events), events_path %></li><% end %>
<% if not disabled_feature? "uploads" %><li id="tab-files" class="tab <%= tab('uploads') %>"><%= link_to I18n.t(:files), files_path %></li><% end %>
<% if not disabled_feature? "forum" %><li id="tab-forum" class="tab <%= tab('forums') %>"><%= link_to I18n.t(:forum), forum_root_path %></li><% end %>
<% if not disabled_feature? "headers" %><li id="tab-headers" class="tab <%= tab('headers') %>"><%= link_to I18n.t(:headers), headers_path %></li><% end %>
<% if not disabled_feature? "users" %><li id="tab-users" class="tab <%= tab('users') %>"><%= link_to I18n.t(:users), users_path %></li><% end %>
</ul>
<% if enabled? "home" %><li id="tab-home" class="tab <%= tab('home') %>"><%= link_to I18n.t(:home), root_path %></li><% end %>
<% if enabled? "blog" %><li id="tab-blog" class="tab <%= tab('articles') %>"><%= link_to I18n.t(:blog), blog_path %></li><% end %>
<% if enabled? "chat" %><li id="tab-chat" class="tab <%= tab('messages') %>"><%= link_to I18n.t(:chat), chat_path %></li><% end %>
<% if enabled? "events" %><li id="tab-events" class="tab <%= tab('events') %>"><%= link_to I18n.t(:events), events_path %></li><% end %>
<% if enabled? "files" %><li id="tab-files" class="tab <%= tab('uploads') %>"><%= link_to I18n.t(:files), files_path %></li><% end %>
<% if enabled? "forum" %><li id="tab-forum" class="tab <%= tab('forums') %>"><%= link_to I18n.t(:forum), forum_root_path %></li><% end %>
<% if enabled? "headers" %><li id="tab-headers" class="tab <%= tab('headers') %>"><%= link_to I18n.t(:headers), headers_path %></li><% end %>
<% if enabled? "users" %><li id="tab-users" class="tab <%= tab('users') %>"><%= link_to I18n.t(:users), users_path %></li><% end %>
</ul>
10 changes: 5 additions & 5 deletions app/views/users/index.html.erb
@@ -1,21 +1,21 @@
<% if current_controller == 'users' %>
<div class="info-left">
<span class="title"><%=t :users %></span>
<span class="detail">&nbsp;|&nbsp;<%=t_no_of :no_of_users, (@users_count || 0) %></span>
</div>
<span class="detail">&nbsp;| &nbsp;<%=t_no_of :no_of_users, (@users_count || 0) %></span>
</div>
<div class="info-right">
<span class="title">&nbsp;</span>
<span class="detail">
<%= link_to I18n.t(:avatars), avatars_path %> &nbsp;
<%= link_to I18n.t(:avatars), avatars_path %> &nbsp;
<%= link_to I18n.t(:ranks), ranks_path %>
</span>
</div>
<div class="clear"> </div>

<% if logged_in? %>
<%#= render :file => 'users/show', :locals => {:user => current_user } %>
<% end %>
<% end %>
<% unless @users.blank? %>
Expand Down
8 changes: 4 additions & 4 deletions config/config.example.yml
Expand Up @@ -22,9 +22,9 @@ production:
# More info from Heroku: http://docs.heroku.com/constraints#read-only-filesystem
# Visit the Amazon S3 site to sign up for an access_id and secret_key: https://s3.amazonaws.com/
# The bucket name can be any unique string, and once set here it can be created by running "rake s3:create"
s3_access_id:
s3_secret_key:
s3_bucket_name:
s3_access_id:
s3_secret_key:
s3_bucket_name:

# AMAZON CLOUDFRONT (optional)
# You can sign up for CloudFront (http://aws.amazon.com/cloudfront) and provide the CNAME here
Expand All @@ -48,4 +48,4 @@ production:
locale: # Choose a locale from config/locales, en is the default

# DISABLE TABS (optional)
disable_tabs: # list tabs that want to hide from users (e.g. "blog events headers")
disabled_tabs: # list tabs that want to hide from users (e.g. "blog events headers")
24 changes: 17 additions & 7 deletions test/functional/home_controller_test.rb
@@ -1,41 +1,51 @@
require 'test_helper'

class HomeControllerTest < ActionController::TestCase

def test_should_get_index
get :index
assert_response :success
end

def test_should_get_index_when_logged_in
login_as :trevor
get :index
assert_response :success
end

def test_should_get_index_when_not_logged_in
get :index
assert_response :success
end

def test_should_redirect_to_login_if_site_is_private_and_not_logged_in
private_site
get :index
assert_redirected_to login_path
end

def test_should_get_index_if_site_is_private_and_logged_in
login_as :trevor
private_site
get :index
assert_response :success
end

def test_should_get_help
get :help
assert_response :success
end


test "should allow disbaled tabs" do
get :index
assert_response :success
assert_select '#tab-blog'
silence_warnings {CONFIG['disabled_tabs'] = 'blog events'}
get :index
assert_response :success
assert_select '#tab-blog', false
end

# def test_should_not_update_session_online_at
# # if current_user HAS been active in the last 10 minutes
# end
Expand Down

0 comments on commit 14441ae

Please sign in to comment.