diff options
author | re4k <re4k@re4k.info> | 2013-03-28 02:11:40 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-03-28 02:11:40 +0900 |
commit | 295db76b7643868456eafb98cf760a5e383b41ed (patch) | |
tree | 054845af698810440ce1b96324618fb05ee67cb2 /app | |
parent | b4972590475eb595bc88f6ee47125fe8ca6e1fb2 (diff) | |
download | aclog-295db76b7643868456eafb98cf760a5e383b41ed.tar.gz |
Refactor
Diffstat (limited to 'app')
22 files changed, 284 insertions, 27 deletions
diff --git a/app/assets/images/protected_profile_image.png b/app/assets/images/protected_profile_image.png Binary files differnew file mode 100644 index 0000000..3d1e0f9 --- /dev/null +++ b/app/assets/images/protected_profile_image.png diff --git a/app/assets/stylesheets/_sidebar.css.sass b/app/assets/stylesheets/_sidebar.css.sass new file mode 100644 index 0000000..a61fd50 --- /dev/null +++ b/app/assets/stylesheets/_sidebar.css.sass @@ -0,0 +1,12 @@ +.sidebar + :margin-top 20px + .screen_name + :text-align center + :font-size larger + :margin 10px 0 + .avatar + :text-align center + .records + .data + :text-align right + diff --git a/app/assets/stylesheets/_users.css.sass b/app/assets/stylesheets/_users.css.sass new file mode 100644 index 0000000..610caf1 --- /dev/null +++ b/app/assets/stylesheets/_users.css.sass @@ -0,0 +1,28 @@ +.users + ul + :padding 0 + :margin 0 + li + :width 48px + :margin 12px + :padding 0 + :color #666666 + a + :color inherit + &:hover + :text-decoration inherit + .avatar + :display block + :margin-bottom 6px + img + :width 48px + :height 48px + .count, .type + :display block + .count + :font-weight bold + :font-size 14px + .type + :font-weight normal + :font-size 10px + :text-transform uppercase diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d899703..0e82b89 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -194,6 +194,7 @@ class UsersController < ApplicationController end raise Aclog::Exceptions::UserNotFound unless @user + raise Aclog::Exceptions::UserNotRegistered if @user.protected? && !@user.registered? end def get_user_b diff --git a/app/models/user.rb b/app/models/user.rb index 874f8d6..9598236 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,6 @@ class User < ActiveRecord::Base - def initialize(attrs = {}) - if attrs.is_a?(Fixnum) || attrs.is_a?(Bignum) - u = attrs - attrs = {:id => u} - end - attrs[:profile_image_url] ||= ActionController::Base.helpers.asset_path("missing_profile_image.png") - attrs[:name] ||= "Missing name: #{u}" - super(attrs) + def protected? + protected end has_many :tweets, :dependent => :delete_all diff --git a/app/views/errors/error.html.haml b/app/views/errors/error.html.haml new file mode 100644 index 0000000..8bc508f --- /dev/null +++ b/app/views/errors/error.html.haml @@ -0,0 +1,20 @@ +%h1= response.status +.lead + - case @exception + - when Aclog::Exceptions::TweetNotFound + ツイートが見つかりませんでした。 + - when Aclog::Exceptions::UserNotFound + ユーザーが見つかりませんでした。 + - when Aclog::Exceptions::UserNotRegistered + ユーザーは aclog に登録していません。 + - when Aclog::Exceptions::UserProtected + ユーザーは非公開です。 + - when Aclog::Exceptions::LoginRequired + このページの表示にはログインが必要です。 + - when ActionController::RoutingError + 不正な URL です。 + - else + - if response.status == 404 + Not Found (Unknown) + - else + Internal Error (Unknown) diff --git a/app/views/errors/error.json.jbuilder b/app/views/errors/error.json.jbuilder new file mode 100644 index 0000000..8dab39a --- /dev/null +++ b/app/views/errors/error.json.jbuilder @@ -0,0 +1,24 @@ +json.error do |json| + json.status response.status + case @exception + when Aclog::Exceptions::TweetNotFound + json.message "ツイートが見つかりませんでした。" + when Aclog::Exceptions::UserNotFound + json.message "ユーザーが見つかりませんでした。" + when Aclog::Exceptions::UserNotRegistered + json.message "ユーザーは aclog に登録していません。" + when Aclog::Exceptions::UserProtected + json.message "ユーザーは非公開です。" + when Aclog::Exceptions::LoginRequired + json.message "このページの表示にはログインが必要です。" + when ActionController::RoutingError + json.message "不正な URL です。" + else + if response.status == 404 + json.message "Not Found (Unknown)" + else + json.message "Internal Error (Unknown)" + end + end + json.exception @exception.class.to_s +end diff --git a/app/views/layouts/_base.html.haml b/app/views/layouts/_base.html.haml new file mode 100644 index 0000000..eab9eb2 --- /dev/null +++ b/app/views/layouts/_base.html.haml @@ -0,0 +1,21 @@ +!!! xml +%html{xmlns: "http://www.w3.org/1999/xhtml"} + %head + %title= @title + = stylesheet_link_tag "application" + %body + .navbar.navbar-static-top + .navbar-inner + .container + .brand + = link_to "aclog", :controller => "main", :action => "index" + %ul.nav.pull-right + %li + = link_to "about", :controller => "main", :action => "about" + - if session[:screen_name] + %li= link_to "logout", :controller => "sessions", :action => "destroy" + %li= link_to "@#{session[:screen_name]}", :controller => "users", :action => "best", :screen_name => session[:screen_name] + - else + %li= link_to "login", "/i/login" + .container + = yield diff --git a/app/views/layouts/index.html.haml b/app/views/layouts/index.html.haml new file mode 100644 index 0000000..4c0da9c --- /dev/null +++ b/app/views/layouts/index.html.haml @@ -0,0 +1,2 @@ += render :layout => "layouts/base" do + = yield diff --git a/app/views/main/about.html.haml b/app/views/main/about.html.haml new file mode 100644 index 0000000..660a511 --- /dev/null +++ b/app/views/main/about.html.haml @@ -0,0 +1,12 @@ +%h1 aclog について +%p + = link_to "@re4k", "https://twitter.com/re4k" + が Favstar BAN されたので仕方なく代わりを作りました。 +%p + そーすはこっち + = link_to "GitHub", "https://github.com/re4k/aclog" +%p + このページ作ったはいいけど書くことがない… + トップページ見てくださいな +%p + = link_to "トップページ", :root diff --git a/app/views/main/api.html.haml b/app/views/main/api.html.haml new file mode 100644 index 0000000..8d5adef --- /dev/null +++ b/app/views/main/api.html.haml @@ -0,0 +1,62 @@ +%h1 API +%p + ドキュメントは今度もっとわかりやすく書き直しますね +%h3 URL +%p + 全部 GET です +%dl + %dt ツイート表示 + %dd /i/show.json?id=(tweet_id) + %dt ツイート一覧 + %dd /users/{best|recent|timeline|discovered}.json + %dt 他ユーザーが関係してくるもの + %dd /users/{favorited_by|retweeted_by|given_favorites_to|given_retweets_to}.json + %dt ユーザー情報。include_user_stats は標準で有効になります。 + %dd /users/info.json +%h3 パラメータ +%dl + %dt screen_name or user_id + %dd + %p Twitter アカウントのもの + %p 必須 + %p ツイート表示以外では必須 + %dt screen_name_b or user_id_b + %dd + %p Twitter アカウントのもの + %p 有無で結果が変わります + %p favorited_by などのみ。なんとなくわかるとおもう + %dt include_user + %dd + %p true or false + %p default: false + %p 共通。ふぁぼ/RTしたユーザー情報を含めるか。重め + %dt include_user_stats + %dd + %p true or false + %p default: false + %p 共通。ふぁぼ/RTしたユーザーのふぁぼられなどの情報を含めるか。重いです + %dt count + %dd + %p 1-100 + %p default: 10 + %p リストのみ。件数 + %dt page + %dd + %p 1- + %p default: 1 + %p リストのみ。ページ + %dt all + %dd + %p true or false + %p default: false + %p timeline のみ。反応がなかったツイートも含めるかどうか + %dt tweets + %dd + %p favorite or retweet or all + %p default: all + %p discovered のみ + %dt order + %dd + %p favorite or retweet or all + %p default: all + %p best, recent のみ diff --git a/app/views/shared/_sidebar_i.html.haml b/app/views/shared/_sidebar_i.html.haml new file mode 100644 index 0000000..098b35c --- /dev/null +++ b/app/views/shared/_sidebar_i.html.haml @@ -0,0 +1,12 @@ +%ul.nav.nav-tabs.nav-stacked + %li + = link_to "about", :controller => "main", :action => "about" + %li + = link_to "api", :controller => "main", :action => "api" +%ul.nav.nav-tabs.nav-stacked + %li + = link_to "best", :controller => "i", :action => "best" + %li + = link_to "recent", :controller => "i", :action => "recent" + %li + = link_to "timeline", :controller => "i", :action => "timeline" diff --git a/app/views/shared/_sidebar_main.html.haml b/app/views/shared/_sidebar_main.html.haml new file mode 100644 index 0000000..dcc2630 --- /dev/null +++ b/app/views/shared/_sidebar_main.html.haml @@ -0,0 +1 @@ += render "shared/sidebar_i" diff --git a/app/views/shared/_sidebar_users.html.haml b/app/views/shared/_sidebar_users.html.haml new file mode 100644 index 0000000..bfd4b4d --- /dev/null +++ b/app/views/shared/_sidebar_users.html.haml @@ -0,0 +1,38 @@ +.sidebar + .avatar= link_to (image_tag @user.profile_image_url_original, :alt => @user.screen_name, :width => 64, :height => 64, :class => "icon img-rounded"), :controller => "users", :action => "best", :screen_name => @user.screen_name + .screen_name= link_to "@#{@user.screen_name}", :controller => "users", :action => "best", :screen_name => @user.screen_name + - if @user.registered? + %table.table.table-condensed.records + %tr + %td favorited + %td.data= @user.stats[:favorited_count] + %tr + %td retweeted + %td.data= @user.stats[:retweeted_count] + %tr + %td avg. fav + %td.data= ((@user.stats[:favorited_count] + 0.0) / @user.stats[:tweets_count]).round(2) + - else + .alert.alert-info + = "@#{@user.screen_name} has never signed in to aclog" + .user_nav + %ul.nav.nav-tabs.nav-stacked + - if @user.registered? + %li + = link_to "info", :controller => "users", :action => "info", :screen_name => @user.screen_name + %li + = link_to "best", :controller => "users", :action => "best", :screen_name => @user.screen_name + %li + = link_to "recent", :controller => "users", :action => "recent", :screen_name => @user.screen_name + %li + = link_to "timeline", :controller => "users", :action => "timeline", :screen_name => @user.screen_name + %li + = link_to "discovered", :controller => "users", :action => "discovered", :screen_name => @user.screen_name + %li + = link_to "favorited by", :controller => "users", :action => "favorited_by", :screen_name => @user.screen_name + %li + = link_to "retweted by", :controller => "users", :action => "retweeted_by", :screen_name => @user.screen_name + %li + = link_to "given favorites", :controller => "users", :action => "given_favorites_to", :screen_name => @user.screen_name + %li + = link_to "given retweets", :controller => "users", :action => "given_retweets_to", :screen_name => @user.screen_name diff --git a/app/views/shared/_tweet.html.haml b/app/views/shared/_tweet.html.haml index d98fdbb..3f76f1a 100644 --- a/app/views/shared/_tweet.html.haml +++ b/app/views/shared/_tweet.html.haml @@ -26,11 +26,10 @@ %span.type= type %dd %ul.inline - - actions.take(params[:controller] == "users" && params[:action] == "show" ? actions.count : 20).each do |a| | - - m = a.user || User.new + - actions.take(params[:action] == "show" ? actions.count : 20).each do |a| + - m = a.user %li - - if m.screen_name + - if m = link_to image_tag(m.profile_image_url, :alt => m.screen_name, :title => m.name), :controller => "users", :action => "best", :screen_name => m.screen_name - else - = image_tag(m.profile_image_url, :alt => m.name, :title => m.name) - + = image_tag asset_path("missing_profile_image.png"), :alt => "Missing User: #{a.user_id}", :title => "Missing User: #{a.user_id}" diff --git a/app/views/shared/_tweet.json.jbuilder b/app/views/shared/_tweet.json.jbuilder index 467249a..c048dee 100644 --- a/app/views/shared/_tweet.json.jbuilder +++ b/app/views/shared/_tweet.json.jbuilder @@ -1,29 +1,26 @@ json.(item, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count) json.user do |json| - unless @include_user - json.id item.user_id - else + json.id item.user_id + if @include_user json.partial! "shared/user", :user => item.user end end json.favorites item.favorites.order("id") do |json, favorite| json.user do |json| - unless @include_user - json.id favorite.user_id - else - json.partial! "shared/user", :user => favorite.user || User.new + json.id favorite.user_id + if @include_user + json.partial! "shared/user", :user => favorite.user end end end json.retweets item.retweets.order("id") do |json, retweet| json.id retweet.id json.user do |json| - unless @include_user - json.id retweet.user_id - else - json.partial! "shared/user", :user => retweet.user || User.new + json.id retweet.user_id + if @include_user + json.partial! "shared/user", :user => retweet.user end end end diff --git a/app/views/shared/_user.json.jbuilder b/app/views/shared/_user.json.jbuilder index 1bac0ad..fe64d8d 100644 --- a/app/views/shared/_user.json.jbuilder +++ b/app/views/shared/_user.json.jbuilder @@ -1,4 +1,7 @@ -json.(user, :id, :screen_name, :name, :profile_image_url) -if @include_user_stats && user.registered? - json.stats user.stats +if user + json.(user, :id, :screen_name, :name, :profile_image_url, :protected) + if @include_user_stats && user.registered? + json.stats user.stats + end end + diff --git a/app/views/shared/tweets.html.haml b/app/views/shared/tweets.html.haml new file mode 100644 index 0000000..f6a3f12 --- /dev/null +++ b/app/views/shared/tweets.html.haml @@ -0,0 +1,4 @@ +.items + = render :partial => "shared/tweet", :collection => @items, :as => :item +- if @items + = paginate @items diff --git a/app/views/shared/tweets.json.jbuilder b/app/views/shared/tweets.json.jbuilder new file mode 100644 index 0000000..d2637d3 --- /dev/null +++ b/app/views/shared/tweets.json.jbuilder @@ -0,0 +1,4 @@ +json.array! @items do |json, item| + json.partial! "shared/tweet", :item => item +end + diff --git a/app/views/shared/users.html.haml b/app/views/shared/users.html.haml new file mode 100644 index 0000000..6393630 --- /dev/null +++ b/app/views/shared/users.html.haml @@ -0,0 +1,13 @@ +.users + %ul.inline + - @usermap.take(50).each do |user_id, count| + - user = User.cached(user_id) + %li + - if user + %a{:href => url_for(params.merge(:screen_name_b => user.screen_name))} + .avatar= image_tag user.profile_image_url, :alt => user.screen_name, :title => user.name + - else + .avatar= image_tag asset_path("missing_profile_image.png"), :alt => "Missing User: #{user_id}", :title => "Missing User: #{user_id}" + .count= count + .type= @event_type + diff --git a/app/views/shared/users.json.jbuilder b/app/views/shared/users.json.jbuilder new file mode 100644 index 0000000..d58c584 --- /dev/null +++ b/app/views/shared/users.json.jbuilder @@ -0,0 +1,9 @@ +json.array! @usermap do |json, u| + json.count u[1] + json.user do |json| + json.id u[0] + if @include_user + json.partial! "shared/user", :user => User.cached(u[0]) + end + end +end diff --git a/app/views/users/info.json.jbuilder b/app/views/users/info.json.jbuilder new file mode 100644 index 0000000..cae64a6 --- /dev/null +++ b/app/views/users/info.json.jbuilder @@ -0,0 +1 @@ +json.partial! "shared/user", :user => @user |