From 4c3d4b672e6ce6feb79075fbccb867d153332a95 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 15 Sep 2011 23:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=A1=B5=E9=9D=A2=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E7=BB=84=E4=BB=B6=E5=8C=96;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/cells/user/followed_topics.html.erb | 23 ++++++++++++++ app/cells/user/followers.html.erb | 14 +++++++++ app/cells/user/following.html.erb | 15 +++++++++ app/cells/user_cell.rb | 41 ++++++++++++++++++++++++ app/helpers/users_helper.rb | 3 -- app/views/users/_sidebar.html.erb | 42 ++----------------------- 6 files changed, 96 insertions(+), 42 deletions(-) create mode 100644 app/cells/user/followed_topics.html.erb create mode 100644 app/cells/user/followers.html.erb create mode 100644 app/cells/user/following.html.erb create mode 100644 app/cells/user_cell.rb diff --git a/app/cells/user/followed_topics.html.erb b/app/cells/user/followed_topics.html.erb new file mode 100644 index 0000000..be5d14c --- /dev/null +++ b/app/cells/user/followed_topics.html.erb @@ -0,0 +1,23 @@ +<% if !@followed_topics.blank? %> +
+

关注 <%= @user.followed_topic_ids.size %>个话题

+ +
+<% end %> diff --git a/app/cells/user/followers.html.erb b/app/cells/user/followers.html.erb new file mode 100644 index 0000000..b71bee7 --- /dev/null +++ b/app/cells/user/followers.html.erb @@ -0,0 +1,14 @@ +<% if !@followers.blank? %> +
+

最近关注<%= user_sex_title(@user) %>的人

+
+
+ <% for follower in @followers %> + + <%= user_avatar_tag(follower, :small) %> + + <% end %> +
+
+
+<% end %> diff --git a/app/cells/user/following.html.erb b/app/cells/user/following.html.erb new file mode 100644 index 0000000..b076f21 --- /dev/null +++ b/app/cells/user/following.html.erb @@ -0,0 +1,15 @@ +<% if !@following.blank? %> +
+

<%= user_sex_title(@user) %>最近关注的人

+
+
+ <% for follower in @following %> + + <%= user_avatar_tag(follower, :small) %> + + <% end %> +
+
+
+<% end %> + diff --git a/app/cells/user_cell.rb b/app/cells/user_cell.rb new file mode 100644 index 0000000..ff6bcc6 --- /dev/null +++ b/app/cells/user_cell.rb @@ -0,0 +1,41 @@ +class UserCell < Cell::Rails + helper :users + cache :followers, :followers_key, :expires_in => 3.days + cache :following, :following_key, :expires_in => 3.days + + def followed_topics(opts = {}) + @user = opts[:user] || nil + @current_user = opts[:current_user] || nil + if @user + @followed_topics = @user.followed_topics.desc("$natural").limit(7) + end + render + end + + def followers(opts = {}) + @user = opts[:user] || nil + if @user + @followers = @user.followers.desc("$natural").limit(42) + end + render + end + + def following(opts = {}) + @user = opts[:user] || nil + if @user + @following = @user.following.desc("$natural").limit(42) + end + render + end + + private + def followers_key(opts = {}) + return "followers/nil" if opts[:user].blank? + "followers/#{opts[:user].id}/#{opts[:user].follower_ids.to_s.md5}" + end + + def following_key(opts = {}) + return "following/nil" if opts[:user].blank? + "following/#{opts[:user].id}/#{opts[:user].following_ids.to_s.md5}" + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index a4ca1de..25ce1b3 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -32,9 +32,6 @@ def user_tagline_tag(user,options = {}) def user_sex_title(user) return "" if user.blank? - if current_user - return "我" if user.id == current_user.id - end user.girl.blank? == true ? "他" : "她" end diff --git a/app/views/users/_sidebar.html.erb b/app/views/users/_sidebar.html.erb index ce4ea6c..a853497 100644 --- a/app/views/users/_sidebar.html.erb +++ b/app/views/users/_sidebar.html.erb @@ -38,45 +38,9 @@
注册于 <%= l user.created_at.to_date, :format => :long %>
-<% if @user.followed_topic_ids.size > 0 %> -
-

关注 <%= @user.followed_topic_ids.size %>个话题

- -
-<% end %> - -<% if @user.follower_ids.size > 0 %> -
-

最近关注<%= user_sex_title(@user) %>的人

-
-
- <% for follower in @user.followers.desc("$natural").limit(42) %> - - <%= user_avatar_tag(follower, :small) %> - - <% end %> -
-
-
-<% end %> +<%= render_cell :user, :followed_topics, :user => @user, :current_user => current_user %> +<%= render_cell :user, :followers, :user => @user %> +<%= render_cell :user, :following, :user => @user %> -<% if @user.following_ids.size > 0 %> -
-

<%= user_sex_title(@user) %>最近关注的人

-
-
- <% for follower in @user.following.desc("$natural").limit(42) %> - - <%= user_avatar_tag(follower, :small) %> - - <% end %> -
-
-
-<% end %> <% end %>