Skip to content

Commit

Permalink
Updating fragment caching and compartmentalizing partials.
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Branca committed Feb 16, 2010
1 parent 38803db commit cf0fdcb
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 235 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
!*.gitignore
public/uploads
public/cache/*
!public/cache/.gitignore
tmp
.DS_Store
public/system
Expand Down
12 changes: 1 addition & 11 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ class HomeController < ApplicationController
caches_page :index, :google_ads

before_filter :set_current_tab
before_filter :load_top_stories, :only => [:index, :app_tab]
before_filter :load_featured_items, :only => [:index, :app_tab]
before_filter :load_top_discussed_stories, :only => [:index, :app_tab]
before_filter :load_top_users, :only => [:index, :app_tab]
before_filter :load_newest_users, :only => [:index, :app_tab]

def index
expires_in 1.minutes, :private => false, :public => true
#expires_in 1.minutes, :private => false, :public => true
@no_paginate = true
@contents = Content.paginate :page => params[:page], :per_page => 10, :order => "created_at desc"
respond_to do |format|
format.html
format.fbml
end
end

def app_tab
Expand Down
11 changes: 5 additions & 6 deletions app/views/home/index.fbml.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#col_left
- if @featured_items.present?
= render :partial => 'shared/featured_items', :locals => { :featured_items => @featured_items }
= render :partial => 'shared/featured_items'
= render :partial => 'shared/stories'

#col_right
= render :partial => 'shared/sidebar/top_stories', :locals => { :top_stories => @top_stories }
= render :partial => 'shared/sidebar/top_discussed_stories', :locals => { :most_discussed_stories => @most_discussed_stories }
= render :partial => 'shared/sidebar/top_users', :locals => { :top_users => @top_users }
= render :partial => 'shared/sidebar/newest_users', :locals => { :newest_users => @newest_users }
= render :partial => 'shared/sidebar/top_stories'
= render :partial => 'shared/sidebar/top_discussed_stories'
= render :partial => 'shared/sidebar/top_users'
= render :partial => 'shared/sidebar/newest_users'
= render :partial => 'shared/sidebar/active_users'
11 changes: 5 additions & 6 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#col_left
- if @featured_items.present?
= render :partial => 'shared/featured_items', :locals => { :featured_items => @featured_items }
= render :partial => 'shared/featured_items'
= render :partial => 'shared/stories'

#col_right
= render :partial => 'shared/sidebar/top_stories', :locals => { :top_stories => @top_stories }
= render :partial => 'shared/sidebar/top_discussed_stories', :locals => { :most_discussed_stories => @most_discussed_stories }
= render :partial => 'shared/sidebar/top_users', :locals => { :top_users => @top_users }
= render :partial => 'shared/sidebar/newest_users', :locals => { :newest_users => @newest_users }
= render :partial => 'shared/sidebar/top_stories'
= render :partial => 'shared/sidebar/top_discussed_stories'
= render :partial => 'shared/sidebar/top_users'
= render :partial => 'shared/sidebar/newest_users'
= render :partial => 'shared/sidebar/active_users'
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xmlns:fb" => "http://www.facebook.com/2008/fbml"}
%head
= stylesheet_link_tag 'default.css', 'formtastic.css', 'ui-lightness/jquery-ui-1.7.2.custom.css', 'jquery.jcarousel', 'jcarousel.skin', 'application', :cache => true
= stylesheet_link_tag 'default.css', 'formtastic.css', 'ui-lightness/jquery-ui-1.7.2.custom.css', 'jquery.jcarousel', 'jcarousel.skin', 'application'
= javascript_include_tag 'jquery.min', 'jquery.ui.min', 'jquery.jcarousel.pack', 'jquery.application'
= auto_discovery_link_tag(:atom, stories_path(:format => :atom))
%style
Expand Down
59 changes: 31 additions & 28 deletions app/views/shared/_featured_items.fbml.haml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#featurePanel.clearfix
.panelBar.clearfix
%h2 Featured Content
#featuredStories
- section1 = featured_items.children.first
- section2 = featured_items.children.second
- case featured_items.featured_type
- when 'template_1'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
- when 'template_2'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
- secondary1 = section1.children.second.featurable
- secondary2 = section1.children.third.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
.related_story
.bullet_list
%ul
%li= link_to secondary1.featured_title, secondary1.featured_url
%li= link_to secondary2.featured_title, secondary2.featured_url
- cache :featured_items do
- featured_items ||= FeaturedItem.find_root_by_item_name('featured_template')
- if featured_items.present?
#featurePanel.clearfix
.panelBar.clearfix
%h2 Featured Content
#featuredStories
- section1 = featured_items.children.first
- section2 = featured_items.children.second
- case featured_items.featured_type
- when 'template_1'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
- when 'template_2'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
- secondary1 = section1.children.second.featurable
- secondary2 = section1.children.third.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
.related_story
.bullet_list
%ul
%li= link_to secondary1.featured_title, secondary1.featured_url
%li= link_to secondary2.featured_title, secondary2.featured_url
59 changes: 31 additions & 28 deletions app/views/shared/_featured_items.html.haml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#featurePanel.clearfix
.panelBar.clearfix
%h2 Featured Content
#featuredStories
- section1 = featured_items.children.first
- section2 = featured_items.children.second
- case featured_items.featured_type
- when 'template_1'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
- when 'template_2'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
- secondary1 = section1.children.second.featurable
- secondary2 = section1.children.third.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
.related_story
.bullet_list
%ul
%li= link_to secondary1.featured_title, secondary1.featured_url
%li= link_to secondary2.featured_title, secondary2.featured_url
- cache :featured_items do
- featured_items ||= FeaturedItem.find_root_by_item_name('featured_template')
- if featured_items.present?
#featurePanel.clearfix
.panelBar.clearfix
%h2 Featured Content
#featuredStories
- section1 = featured_items.children.first
- section2 = featured_items.children.second
- case featured_items.featured_type
- when 'template_1'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
- when 'template_2'
.featured_story.clearfix
- primary1 = section1.children.first.featurable
- secondary1 = section1.children.second.featurable
- secondary2 = section1.children.third.featurable
#story_1_image.thumb= link_to image_tag(primary1.featured_image_url), primary1.featured_url
.storyBlockWrap
%h1#story_1_title= link_to primary1.featured_title, primary1.featured_url
%p#story_1_caption= primary1.featured_blurb
.related_story
.bullet_list
%ul
%li= link_to secondary1.featured_title, secondary1.featured_url
%li= link_to secondary2.featured_title, secondary2.featured_url
57 changes: 30 additions & 27 deletions app/views/shared/_stories.fbml.haml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
.subtitle
%span= t('.stories_subtitle')
.storyList
.list_stories.clearfix
%ul
- @contents.each do |content|
%li
.thumb
- if content.content_image.present?
%img{:alt => "story image", :src => content.content_image.url}
.storyBlockWrap
%p.storyHead= link_to content.title, story_path(content)
%p.storyCaption= linked_story_caption content
.profilePic= local_linked_profile_pic content.user
.storyBlockMeta
%p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
%p
%span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
%span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
%span.btn_right= t('.stories_share')
- unless @no_paginate
.clearfix
= will_paginate @contents
%br
- cache :stories_list do
- contents ||= Content.paginate :page => params[:page], :per_page => 10, :order => "created_at desc"
- no_paginate ||= false
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
.subtitle
%span= t('.stories_subtitle')
.storyList
.list_stories.clearfix
%ul
- contents.each do |content|
%li
.thumb
- if content.content_image.present?
%img{:alt => "story image", :src => content.content_image.url}
.storyBlockWrap
%p.storyHead= link_to content.title, story_path(content)
%p.storyCaption= linked_story_caption content
.profilePic= local_linked_profile_pic content.user
.storyBlockMeta
%p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
%p
%span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
%span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
%span.btn_right= t('.stories_share')
- unless no_paginate
.clearfix
= will_paginate contents
%br
57 changes: 30 additions & 27 deletions app/views/shared/_stories.html.haml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
.subtitle
%span= t('.stories_subtitle')
.storyList
.list_stories.clearfix
%ul
- @contents.each do |content|
%li
.thumb
- if content.content_image.present?
%img{:alt => "story image", :src => content.content_image.url}
.storyBlockWrap
%p.storyHead= link_to content.title, story_path(content)
%p.storyCaption= linked_story_caption content
.profilePic= local_linked_profile_pic content.user
.storyBlockMeta
%p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
%p
%span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
%span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
%span.btn_right= t('.stories_share')
- unless @no_paginate
.clearfix
= will_paginate @contents
%br
- cache :stories_list do
- contents ||= Content.paginate :page => params[:page], :per_page => 10, :order => "created_at desc"
- no_paginate ||= false
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
.subtitle
%span= t('.stories_subtitle')
.storyList
.list_stories.clearfix
%ul
- contents.each do |content|
%li
.thumb
- if content.content_image.present?
%img{:alt => "story image", :src => content.content_image.url}
.storyBlockWrap
%p.storyHead= link_to content.title, story_path(content)
%p.storyCaption= linked_story_caption content
.profilePic= local_linked_profile_pic content.user
.storyBlockMeta
%p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
%p
%span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
%span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
%span.btn_right= t('.stories_share')
- unless no_paginate
.clearfix
= will_paginate contents
%br
11 changes: 7 additions & 4 deletions app/views/shared/sidebar/_active_users.fbml.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
%br
.list_stories.clearfix
%ul
- active_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} active #{time_ago_in_words user.last_active} ago
- unless active_users.empty?
- active_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} active #{time_ago_in_words user.last_active} ago
- else
%p No currently active users.
26 changes: 15 additions & 11 deletions app/views/shared/sidebar/_active_users.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
-# @expects: local 'active_users'
- active_users ||= User.last_active
- cache :active_users do
- active_users ||= User.last_active

.panel_2
.panelBar.clearfix
%h2= t('.title')
%br
.list_stories.clearfix
%ul
- active_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} active #{time_ago_in_words user.last_active} ago
.panel_2
.panelBar.clearfix
%h2= t('.title')
%br
.list_stories.clearfix
- unless active_users.empty?
%ul
- active_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} active #{time_ago_in_words user.last_active} ago
- else
%p No currently active users.
24 changes: 13 additions & 11 deletions app/views/shared/sidebar/_newest_users.fbml.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
-# @expects: local 'newest_users'
- unless newest_users.empty?
.panel_2
.panelBar.clearfix
%h2= t('.newest_users_title')
%br
.list_stories.clearfix
%ul
- newest_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} registered #{time_ago_in_words user.created_at} ago
- cache :newest_users do
- newest_users ||= User.newest
- unless newest_users.empty?
.panel_2
.panelBar.clearfix
%h2= t('.newest_users_title')
%br
.list_stories.clearfix
%ul
- newest_users.each do |user|
%li
.profilePic= local_linked_profile_pic user
== #{link_to user.name, user_path(user)} registered #{time_ago_in_words user.created_at} ago
Loading

0 comments on commit cf0fdcb

Please sign in to comment.