diff options
author | re4k <re4k@re4k.info> | 2013-04-30 23:09:54 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-04-30 23:09:54 +0900 |
commit | 10c7c723c16d757b5a5692542911a08715966b6f (patch) | |
tree | 995d9b184bc5f9dc9d3d5819c723d62478e29784 | |
parent | 617c786764e4c10d85c87945a6c281061e65dcc8 (diff) | |
download | aclog-10c7c723c16d757b5a5692542911a08715966b6f.tar.gz |
refactor (not tested, no compatibility)
25 files changed, 361 insertions, 420 deletions
@@ -1,7 +1,7 @@ ruby '1.9.3' source 'https://rubygems.org' -gem 'rails', '4.0.0.beta1' +gem 'rails', '4.0.0.rc1' gem 'mysql2', "> 0.3.12b" gem 'dalli' @@ -19,9 +19,9 @@ gem 'twitter' gem 'omniauth-twitter' gem 'haml-rails' -gem 'sass-rails', '~> 4.0.0.beta1' +gem 'sass-rails', '~> 4.0.0.rc1' gem 'jbuilder' -gem 'coffee-rails', '~> 4.0.0.beta1' +gem 'coffee-rails', '~> 4.0.0.rc1' gem 'jquery-rails' gem 'uglifier', '>= 1.0.3' diff --git a/Gemfile.lock b/Gemfile.lock index e6d802d..03e640f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,36 +1,36 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.0.beta1) - actionpack (= 4.0.0.beta1) + actionmailer (4.0.0.rc1) + actionpack (= 4.0.0.rc1) mail (~> 2.5.3) - actionpack (4.0.0.beta1) - activesupport (= 4.0.0.beta1) + actionpack (4.0.0.rc1) + activesupport (= 4.0.0.rc1) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - activemodel (4.0.0.beta1) - activesupport (= 4.0.0.beta1) + activemodel (4.0.0.rc1) + activesupport (= 4.0.0.rc1) builder (~> 3.1.0) - activerecord (4.0.0.beta1) - activemodel (= 4.0.0.beta1) - activerecord-deprecated_finders (~> 0.0.3) - activesupport (= 4.0.0.beta1) - arel (~> 4.0.0.beta1) - activerecord-deprecated_finders (0.0.3) - activesupport (4.0.0.beta1) - i18n (~> 0.6.2) + activerecord (4.0.0.rc1) + activemodel (= 4.0.0.rc1) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.0.rc1) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.2) + activesupport (4.0.0.rc1) + i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) - tzinfo (~> 0.3.33) + tzinfo (~> 0.3.37) addressable (2.3.4) after_commit_action (0.1.3) activerecord (>= 3.0.0) arel (4.0.0) atomic (1.1.8) - bootstrap-sass (2.3.1.0) + bootstrap-sass (2.3.1.1) sass (~> 3.2) builder (3.1.4) coffee-rails (4.0.0) @@ -76,7 +76,6 @@ GEM jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.7.7) kgio (2.8.0) mail (2.5.3) i18n (>= 0.4.0) @@ -102,26 +101,23 @@ GEM rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (4.0.0.beta1) - actionmailer (= 4.0.0.beta1) - actionpack (= 4.0.0.beta1) - activerecord (= 4.0.0.beta1) - activesupport (= 4.0.0.beta1) + rails (4.0.0.rc1) + actionmailer (= 4.0.0.rc1) + actionpack (= 4.0.0.rc1) + activerecord (= 4.0.0.rc1) + activesupport (= 4.0.0.rc1) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.0.beta1) - sprockets-rails (~> 2.0.0.rc3) + railties (= 4.0.0.rc1) + sprockets-rails (~> 2.0.0.rc4) rails_config (0.3.3) activesupport (>= 3.0) - railties (4.0.0.beta1) - actionpack (= 4.0.0.beta1) - activesupport (= 4.0.0.beta1) + railties (4.0.0.rc1) + actionpack (= 4.0.0.rc1) + activesupport (= 4.0.0.rc1) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.17.0, < 2.0) + thor (>= 0.18.1, < 2.0) raindrops (0.11.0) rake (10.0.4) - rdoc (3.12.2) - json (~> 1.4) rspec (2.13.0) rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) @@ -130,7 +126,7 @@ GEM rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.13.1) - rspec-rails (2.13.0) + rspec-rails (2.13.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -186,7 +182,7 @@ PLATFORMS DEPENDENCIES bootstrap-sass - coffee-rails (~> 4.0.0.beta1) + coffee-rails (~> 4.0.0.rc1) counter_culture daemon-spawn dalli @@ -198,11 +194,11 @@ DEPENDENCIES msgpack mysql2 (> 0.3.12b) omniauth-twitter - rails (= 4.0.0.beta1) + rails (= 4.0.0.rc1) rails_config rspec rspec-rails - sass-rails (~> 4.0.0.beta1) + sass-rails (~> 4.0.0.rc1) thin twitter uglifier (>= 1.0.3) diff --git a/app/assets/javascripts/tweets.js b/app/assets/javascripts/tweets.js index c74bbb9..5968264 100644 --- a/app/assets/javascripts/tweets.js +++ b/app/assets/javascripts/tweets.js @@ -3,7 +3,7 @@ $(function() { $(".pagination").hide(); $.autopager({ autoLoad: true, - content: ".items", + content: ".tweets", start: function(current, next) { $(".loading").show(); }, diff --git a/app/assets/stylesheets/_tweets.css.sass b/app/assets/stylesheets/_tweets.css.sass index 91fcf76..61504b9 100644 --- a/app/assets/stylesheets/_tweets.css.sass +++ b/app/assets/stylesheets/_tweets.css.sass @@ -1,6 +1,6 @@ -.items +.tweets :width 572px - .item + .tweet :margin 15px 0 .tweet :overflow hidden diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 249b4ea..2c73623 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,27 +4,12 @@ class ApplicationController < ActionController::Base before_filter :set_format after_filter :xhtml - def render_tweets(options = {}, &blk) - if params[:count] - count = params[:count].to_i - else - count = 10 + def _get_user(id, screen_name) + if id + User.find_by(id: id.to_i) + elsif screen_name + User.find_by(screen_name: screen_name) end - p options - if options[:force_page] - params[:page] ||= "1" - end - - @items = blk.call.limit(count) - - if params[:page] - @items = @items.page(params[:page].to_i, count) - else - @items = @items.max_id(params[:max_id].to_i) if params[:max_id] - @items = @items.since_id(params[:since_id].to_i) if params[:since_id] - end - - render "shared/tweets" end private diff --git a/app/controllers/i_controller.rb b/app/controllers/i_controller.rb index bf6fee5..9a7f4d8 100644 --- a/app/controllers/i_controller.rb +++ b/app/controllers/i_controller.rb @@ -1,32 +1,11 @@ class IController < ApplicationController - def best - @title = "Best Tweets" - render_tweets(force_page: true) do - Tweet - .reacted - .original - .order_by_reactions - end - end - - def recent - @title = "Recent Best Tweets" - render_tweets(force_page: true) do - Tweet - .recent - .reacted - .original - .order_by_reactions - end - end - - def timeline - @title = "Public Timeline" - render_tweets do - Tweet - .reacted - .not_protected - .order_by_id + # GET /api/tweets/import + def import + # import 100 + if session[:account] + session[:account].import_favorites(params[:id].to_i) + else + raise Aclog::Exceptions::LoginRequired end end end diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb new file mode 100644 index 0000000..e372091 --- /dev/null +++ b/app/controllers/tweets_controller.rb @@ -0,0 +1,114 @@ +class TweetsController < ApplicationController + # GET /i/:id + # GET /api/tweets/show + def show + tweet_required + @user = @tweet.user + + @description = "#{@user.screen_name}'s Tweet" + text = ApplicationController.helpers.format_tweet_text(@tweet.text)[0...30] + @title = "\"#{text}\" from #{@user.screen_name}" + end + + # GET /:screen_name + # GET /i/best + # GET /api/tweets/best + def best + user_optional + @description = "Best" + @tweets = Tweet.of(@user).reacted.order_by_reactions.list(params, force_page: true) + end + + # GET /:screen_name/favorited + # GET /api/tweets/favorited + def favorited + user_optional + @description = "Most Favorited" + @tweets = Tweet.of(@user).reacted.order_by_favorites.list(params, force_page: true) + end + + # GET /:screen_name/retweeted + # GET /api/tweets/retweeted + def retweeted + user_optional + @description = "Most Retweeted" + @tweets = Tweet.of(@user).reacted.order_by_retweets.list(params, force_page: true) + end + + # GET /i/recent + # GET /api/tweets/recent + def recent + user_optional + @description = "Recent Best" + @tweets = Tweet.of(@user).recent.reacted.order_by_reactions.list(params, force_page: true) + end + + # GET /:screen_name/timeline + # GET /i/timeline + # GET /api/tweets/timeline + def timeline + user_optional + @description = "Recent" + @tweets = Tweet.of(@user).reacted.order_by_id.list(params) + end + + # GET /:screen_name/discoveries + # GET /api/tweets/discoveries + def discoveries + user_required + @description = "Discoveries" + @tweets = Tweet.discovered_by(@user).order_by_id.list(params) + end + + # GET /:screen_name/favorites + # GET /api/tweets/favorites + def favorites + user_required + @description = "Favorites" + @tweets = Tweet.favorited_by(@user).order_by_id.list(params) + end + + # GET /:screen_name/retweets + # GET /api/tweets/retweets + def retweets + user_required + @description = "Retweets" + @tweets = Tweet.retweeted_by(@user).order_by_id.list(params) + end + + # GET /:screen_name/discovered_by/:screen_name_b + # GET /api/tweets/discovered_by + def discovered_by + user_required + user_b_required + @description = "Discovored by #{@user_b.screen_name}" + @tweets = Tweet.of(@user).discovered_by(@user_b).order_by_id.list(params) + end + + private + def render(*args) + if args.empty? + if params[:action] == "show" + super "shared/tweet" + else + super "shared/tweets" + end + else + super(*args) + end + end + + def user_optional + @user = _get_user(params[:user_id], params[:screen_name]) + end + + def user_required + user_optional + raise Aclog::Exceptions::UserNotFound unless @user + end + + def user_b_required + @user_b = _get_user(params[:user_id_b], params[:screen_name_b]) + raise Aclog::Exceptions::UserNotFound unless @user_b + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 675badd..287fb96 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,199 +1,25 @@ class UsersController < ApplicationController - before_filter :require_user, except: [:show, :favoriters] - before_filter :require_tweet, only: [:show, :favoriters] - before_filter :include_user_b, only: [:favorited_by, :retweeted_by, :given_favorites_to, :given_retweets_to] - after_filter :check_protected - - def best - @title = "@#{@user.screen_name}'s Best Tweets" - - render_tweets(force_page: true) do - case params[:order] - when /^fav/ - @user.tweets.reacted.order_by_favorites - when /^re?t/ - @user.tweets.reacted.order_by_retweets - else - @user.tweets.reacted.order_by_reactions - end - end - end - - def recent - @title = "@#{@user.screen_name}'s Recent Best Tweets" - - render_tweets(force_page: true) do - case params[:order] - when /^fav/ - @user.tweets.recent.reacted.order_by_favorites - when /^re?t/ - @user.tweets.recent.reacted.order_by_retweets - else - @user.tweets.recent.reacted.order_by_reactions - end - end - end - - def timeline - @title = "@#{@user.screen_name}'s Newest Tweets" - - render_tweets do - if !!params[:all] - @user.tweets.order_by_id - else - @user.tweets.reacted.order_by_id - end - end - end - - def discovered - @title = "@#{@user.screen_name}'s Recent Discoveries" - - render_tweets do - case params[:tweets] - when /^fav/ - Tweet.favorited_by(@user).order_by_id - when /^re?t/ - Tweet.retweeted_by(@user).order_by_id - else - Tweet.discovered_by(@user).order_by_id - end - end - end - def info - raise Aclog::Exceptions::UserNotRegistered unless @user.registered? - - @title = "@#{@user.screen_name} (#{@user.name})'s Profile" - end - - def favorited_by - if @user_b - render_user_to_user - else - render_users_ranking - end + user_required + @description = "Profile" + @stats = @user.stats(true) end - def retweeted_by - if @user_b - render_user_to_user - else - render_users_ranking - end - end - - def given_favorites_to - if @user_b - render_user_to_user - else - render_users_ranking - end - end - - def given_retweets_to - if @user_b - render_user_to_user - else - render_users_ranking - end - end - - def show - @user = @item.user - - # import 100 - if params[:import] == "force" && session[:account] - session[:account].import_favorites(@item.id) - end - - text = ApplicationController.helpers.format_tweet_text(@item.text)[0...30] - @title = "\"#{text}\" from @#{@user.screen_name}" - @title_b = "@#{@user.screen_name}'s Tweet" - end - - # only json - def favoriters - render json: @item.favorites.load.map{|f| f.user_id} - end - - private - def render_users_ranking - by = -> model do - model.joins( - "INNER JOIN (#{@user.tweets.order_by_id.limit(100).to_sql}) target ON tweet_id = target.id") - end - - to = -> model do - Tweet.joins( - "INNER JOIN (" + - model.where(user_id: @user.id).order("id DESC").limit(500).to_sql + - ") action ON tweets.id = action.tweet_id") - end - - case params[:action].to_sym - when :favorited_by - @title = "Who Favorited @#{@user.screen_name}" - users_object = by.call(Favorite) - when :retweeted_by - @title = "Who Retweeted @#{@user.screen_name}" - users_object = by.call(Retweet) - when :given_favorites_to - @title = "@#{@user.screen_name}'s Favorites" - users_object = to.call(Favorite) - when :given_retweets_to - @title = "@#{@user.screen_name}'s Retweets" - users_object = to.call(Retweet) - end - - @usermap = users_object - .inject(Hash.new(0)){|hash, obj| hash[obj.user_id] += 1; hash} - .sort_by{|id, count| -count} - + def discovered_by + user_required + @usermap = @user.count_discovered_by render "shared/user_ranking" end - def render_user_to_user - render_tweets do - case params[:action].to_sym - when :favorited_by - @title = "@#{@user.screen_name}'s Tweets" - @user.tweets.favorited_by(@user_b).order_by_id - when :retweeted_by - @title = "@#{@user.screen_name}'s Tweets" - @user.tweets.retweeted_by(@user_b).order_by_id - when :given_favorites_to - @title = "@#{@user_b.screen_name}'s Tweets" - @user_b.tweets.favorited_by(@user).order_by_id - when :given_retweets_to - @title = "@#{@user_b.screen_name}'s Tweets" - @user_b.tweets.retweeted_by(@user).order_by_id - end - end - end - - def require_user - user = User.where(id: params[:user_id]).first || User.where(screen_name: params[:screen_name]).first - raise Aclog::Exceptions::UserNotFound unless user - @user = user - end - - def include_user_b - user_b = User.where(id: params[:user_id_b]).first || User.where(screen_name: params[:screen_name_b]).first - @user_b = user_b - end - - def require_tweet - item = Tweet.where(id: params[:id]).first - raise Aclog::Exceptions::TweetNotFound unless item - @item = item + def discovered_of + user_required + @usermap = @user.count_discovered_of + render "shared/user_ranking" end - def check_protected - if @user && @user.protected? - if session[:account] == nil || session[:account].user_id != @user.id - raise Aclog::Exceptions::UserProtected - end - end + private + def user_required + @user = _get_user(params[:id] || params[:user_id], params[:screen_name]) + raise Aclog::Exceptions::UserNotFound unless @user end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f54a537..f9d4705 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -44,6 +44,24 @@ module ApplicationHelper "https://twitter.com/#{screen_name}" end + def sidebar_type + if @sidebar + return @sidebar + elsif @user + return "users" + else + params[:controller] + end + end + + def caption + "#{@description}" + end + + def title + "#{@title || @description} - aclog" + end + # utf8, form def utf8_enforcer_tag; raw "" end end diff --git a/app/helpers/tweets_helper.rb b/app/helpers/tweets_helper.rb new file mode 100644 index 0000000..6b7d657 --- /dev/null +++ b/app/helpers/tweets_helper.rb @@ -0,0 +1,2 @@ +module TweetsHelper +end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 9a5ce96..046ba96 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -12,18 +12,20 @@ class Tweet < ActiveRecord::Base scope :reacted, -> {where("tweets.favorites_count > 0 OR tweets.retweets_count > 0") } scope :original, -> { includes(:stolen_tweet).where(stolen_tweets: {tweet_id: nil}) } scope :not_protected, -> { includes(:user).where(users: {protected: false}) } - scope :max_id, -> id { where("tweets.id <= ?", id) } - scope :since_id, -> id { where("tweets.id > ?", id) } + scope :max_id, -> id { where("tweets.id <= ?", id.to_i) if id } + scope :since_id, -> id { where("tweets.id > ?", id.to_i) if id } + scope :page, -> page, count { offset((page - 1) * count) } + scope :order_by_id, -> { order("tweets.id DESC") } scope :order_by_favorites, -> { order("tweets.favorites_count DESC") } scope :order_by_retweets, -> { order("tweets.retweets_count DESC") } scope :order_by_reactions, -> { order("COALESCE(tweets.favorites_count, 0) + COALESCE(tweets.retweets_count, 0) DESC") } + + scope :of, -> user { where(user: user) if user } scope :favorited_by, -> user { joins(:favorites).where(favorites: {user_id: user.id}) } scope :retweeted_by, -> user { joins(:retweets).where(retweets: {user_id: user.id}) } - scope :discovered_by, -> user { - joins("INNER JOIN (#{user.favorites.to_sql} UNION #{user.retweets.to_sql}) m ON m.tweet_id = tweets.id") - } + scope :discovered_by, -> user { joins("INNER JOIN (#{user.favorites.to_sql} UNION #{user.retweets.to_sql}) m ON m.tweet_id = tweets.id") } # will be moved def notify_favorite @@ -63,5 +65,22 @@ class Tweet < ActiveRecord::Base logger.error("Unknown error while inserting tweet: #{$!}/#{$@}") end end + + def self.list(params, options = {}) + params[:page] ||= "1" if options[:force_page] + + count = params[:count].to_i + count = 10 unless (1..100) === count + + ret = limit(count) + + + if params[:page] + ret.page(params[:page].to_i, count) + else + ret.max_id(params[:max_id]).since_id(params[:since_id]) + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 4b990cc..d230efb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -82,4 +82,23 @@ class User < ActiveRecord::Base end end end + + def count_discovered_by + count_by(Favorite).merge(count_by(Retweet)) {|_, fav, rt| fav + rt }.sort_by {|user_id, count| -count }.map {|user_id, count| [User.find(user_id), count] }.take(50) + end + + def count_discovered_of + count_to(Favorite).merge(count_to(Retweet)) {|_, fav, rt| fav + rt }.sort_by {|user_id, count| -count }.map {|user_id, count| [User.find(user_id), count] }.take(50) + end + + private + def count_by(klass) + actions = klass.joins("INNER JOIN (#{tweets.order_by_id.limit(100).to_sql}) m ON tweet_id = m.id") + actions.inject(Hash.new(0)) {|hash, obj| hash[obj.user_id] += 1; hash } + end + + def count_to(klass) + actions = Tweet.joins("INNER JOIN (#{klass.where(user: self).order("id DESC").limit(500).to_sql}) m ON tweets.id = m.tweet_id") + actions.inject(Hash.new(0)) {|hash, obj| hash[obj.user_id] += 1; hash } + end end diff --git a/app/views/layouts/_base.html.haml b/app/views/layouts/_base.html.haml index d0c876c..27cf75f 100644 --- a/app/views/layouts/_base.html.haml +++ b/app/views/layouts/_base.html.haml @@ -1,7 +1,7 @@ !!! xml %html{xmlns: "http://www.w3.org/1999/xhtml"} %head - %title= strip_tags(@title.to_s) + " - aclog" + %title= title = stylesheet_link_tag "application" = javascript_include_tag "twitter" = javascript_include_tag "application" @@ -10,17 +10,15 @@ .navbar-inner .container .brand - = link_to "aclog", controller: "main", action: "index" + = link_to "aclog", root_path %ul.nav.pull-right %li - = link_to "report", controller: "report", action: "index" + = link_to "report", report_path %li - = link_to "search", controller: "search", action: "search" - %li - = link_to "about", controller: "main", action: "about" + = link_to "about", about_path - if logged_in? - %li= link_to "logout", controller: "sessions", action: "destroy" - %li= link_to session[:account].user.screen_name, user_path(session[:account].user.screen_name) + %li= link_to "logout", logout_path + %li= link_to session[:account].user.screen_name, user_best_path(session[:account].user.screen_name) - else %li= link_to "login", "/i/login" .container diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index aeee99b..99357d1 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,7 +1,7 @@ = render layout: "layouts/base" do .row .span2 - .sidebar= render partial: "shared/sidebar/#{params[:controller]}" + .sidebar= render partial: "shared/sidebar/#{sidebar_type}" .span10 - %h1= strip_tags(@title_b || @title) + %h1= caption = yield diff --git a/app/views/shared/partial/_tweet.html.haml b/app/views/shared/partial/_tweet.html.haml index a1b3c7a..e8e26d9 100644 --- a/app/views/shared/partial/_tweet.html.haml +++ b/app/views/shared/partial/_tweet.html.haml @@ -1,36 +1,36 @@ -.item +.tweet .tweet .left .avatar - = link_to user_path(item.user.screen_name) do - = image_tag item.user.profile_image_url, alt: item.user.screen_name, title: item.user.name + = link_to user_best_path(tweet.user.screen_name) do + = image_tag tweet.user.profile_image_url, alt: tweet.user.screen_name, title: tweet.user.name %ul.inline.actions %li.twitter - = link_to image_tag("reply.png", alt: "reply"), "https://twitter.com/intent/tweet?in_reply_to=#{item.id}" - = link_to image_tag("retweet.png", alt: "retweet"), "https://twitter.com/intent/retweet?tweet_id=#{item.id}" - = link_to image_tag("favorite.png", alt: "favorite"), "https://twitter.com/intent/favorite?tweet_id=#{item.id}" + = link_to image_tag("reply.png", alt: "reply"), "https://twitter.com/intent/tweet?in_reply_to=#{tweet.id}" + = link_to image_tag("retweet.png", alt: "retweet"), "https://twitter.com/intent/retweet?tweet_id=#{tweet.id}" + = link_to image_tag("favorite.png", alt: "favorite"), "https://twitter.com/intent/favorite?tweet_id=#{tweet.id}" .tweet_content_fix .tweet_content .user - %span.nam= link_to item.user.name, user_path(item.user.screen_name) - %span.screen_name= link_to item.user.screen_name, user_path(item.user.screen_name) - .text{class: item.stolen_tweet ? "copied" : nil} - = raw format_tweet_text(item.text) + %span.nam= link_to tweet.user.name, user_best_path(tweet.user.screen_name) + %span.screen_name= link_to tweet.user.screen_name, user_best_path(tweet.user.screen_name) + .text{class: tweet.stolen_tweet ? "copied" : nil} + = raw format_tweet_text(tweet.text) .meta.clearfix %span.twitter_bird - = link_to image_tag("bird_gray_16.png", alt: "Twitter"), twitter_status_url(item), target: "_blank" + = link_to image_tag("bird_gray_16.png", alt: "Twitter"), twitter_status_url(tweet), target: "_blank" %span.created_at - = link_to format_time(item.tweeted_at), tweet_path(item.id) + = link_to format_time(tweet.tweeted_at), tweet_path(tweet.id) - if params[:action] == "show" %span.full = link_to "full", params.merge(limit: -1) - - if item.stolen_tweet + - if tweet.stolen_tweet %span.copied - = link_to "original", tweet_path(item.original.id) + = link_to "original", tweet_path(tweet.original.id) %span.source - = raw format_source_text(item.source) + = raw format_source_text(tweet.source) .stats - - [["favs", item.favoriters], ["retweets", item.retweeters]].each do |type, actions| + - [["favs", tweet.favoriters], ["retweets", tweet.retweeters]].each do |type, actions| - if actions.count > 0 %dl.dl-horizontal %dt @@ -40,5 +40,5 @@ %ul.inline - actions.limit(user_limit).each do |m| %li - = link_to user_path(m.screen_name) do + = link_to user_best_path(m.screen_name) do = image_tag m.profile_image_url, alt: m.screen_name, title: m.name diff --git a/app/views/shared/partial/_tweet.json.jbuilder b/app/views/shared/partial/_tweet.json.jbuilder index eb15878..db7eed2 100644 --- a/app/views/shared/partial/_tweet.json.jbuilder +++ b/app/views/shared/partial/_tweet.json.jbuilder @@ -1,9 +1,9 @@ -json.(item, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count) +json.(tweet, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count) json.user do - json.id item.user_id + json.id tweet.user_id if include_user? - json.partial! "shared/partial/user", user: item.user + json.partial! "shared/partial/user", user: tweet.user end end @@ -19,6 +19,6 @@ render_actions = -> name, data, render_id do end end -render_actions.call(:favorites, item.favorites, false) -render_actions.call(:retweets, item.retweets, true) +render_actions.call(:favorites, tweet.favorites, false) +render_actions.call(:retweets, tweet.retweets, true) diff --git a/app/views/shared/sidebar/_i.html.haml b/app/views/shared/sidebar/_i.html.haml index fe298ac..406fcaa 100644 --- a/app/views/shared/sidebar/_i.html.haml +++ b/app/views/shared/sidebar/_i.html.haml @@ -1,12 +1,12 @@ %ul.nav.nav-tabs.nav-stacked %li - = link_to "about", controller: "main", action: "about" + = link_to "about", about_path %li - = link_to "api", controller: "main", action: "api" + = link_to "api", about_api_path %ul.nav.nav-tabs.nav-stacked %li - = link_to "best", controller: "i", action: "best" + = link_to "best", best_path %li - = link_to "recent", controller: "i", action: "recent" + = link_to "recent", recent_path %li - = link_to "timeline", controller: "i", action: "timeline" + = link_to "timeline", timeline_path diff --git a/app/views/shared/sidebar/_search.html.haml b/app/views/shared/sidebar/_search.html.haml index fe298ac..774d930 100644 --- a/app/views/shared/sidebar/_search.html.haml +++ b/app/views/shared/sidebar/_search.html.haml @@ -1,12 +1 @@ -%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" += render "shared/sidebar/i" diff --git a/app/views/shared/sidebar/_tweets.html.haml b/app/views/shared/sidebar/_tweets.html.haml new file mode 100644 index 0000000..774d930 --- /dev/null +++ b/app/views/shared/sidebar/_tweets.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 index 216ae44..8ef51f4 100644 --- a/app/views/shared/sidebar/_users.html.haml +++ b/app/views/shared/sidebar/_users.html.haml @@ -1,6 +1,6 @@ .sidebar .avatar - = link_to user_path(@user.screen_name) do + = link_to user_best_path(@user.screen_name) do = image_tag @user.profile_image_url_original, alt: @user.screen_name, width: 64, height: 64, class: "icon img-rounded" .screen_name= link_to @user.screen_name, twitter_user_url(@user.screen_name) - if @user.registered? @@ -24,18 +24,14 @@ %ul.nav.nav-tabs.nav-stacked - if @user.registered? %li - = link_to "info", info_path(@user.screen_name) + = link_to "info", user_info_path(@user.screen_name) %li - = link_to "best", user_path(@user.screen_name) + = link_to "best", user_best_path(@user.screen_name) %li - = link_to "timeline", timeline_path(@user.screen_name) + = link_to "timeline", user_timeline_path(@user.screen_name) %li - = link_to "discovered", discovered_path(@user.screen_name) + = link_to "discoveries", user_discoveries_path(@user.screen_name) %li - = link_to "favorited by", favorited_by_path(@user.screen_name) + = link_to "discovered by", user_discovered_by_path(@user.screen_name) %li - = link_to "retweeted by", retweeted_by_path(@user.screen_name) - %li - = link_to "given favorites", given_favorites_to_path(@user.screen_name) - %li - = link_to "given retweets", given_retweets_to_path(@user.screen_name) + = link_to "discovered of", user_discovered_of_path(@user.screen_name) diff --git a/app/views/shared/tweets.html.haml b/app/views/shared/tweets.html.haml index 636a0ed..8bae139 100644 --- a/app/views/shared/tweets.html.haml +++ b/app/views/shared/tweets.html.haml @@ -1,11 +1,11 @@ - if params[:action] == "search" = render partial: "shared/partial/search" -.items - = render partial: "shared/partial/tweet", collection: @items, as: :item +.tweets + = render partial: "shared/partial/tweet", collection: @tweets, as: :tweet .loading = image_tag "loading.gif", alt: "loading...", title: nil .pagination - if params[:page] = link_to raw("Next ›"), params.merge(page: params[:page].to_i + 1), rel: :next - - elsif @items.last - = link_to raw("Next ›"), params.merge(max_id: @items.last.id - 1), rel: :next + - elsif @tweets.last + = link_to raw("Next ›"), params.merge(max_id: @tweets.last.id - 1), rel: :next diff --git a/app/views/shared/tweets.json.jbuilder b/app/views/shared/tweets.json.jbuilder index b623a1e..a1776b7 100644 --- a/app/views/shared/tweets.json.jbuilder +++ b/app/views/shared/tweets.json.jbuilder @@ -1,4 +1,4 @@ -json.array! @items do |json, item| - json.partial! "shared/partial/tweet", item: item +json.array! @tweets do |json, tweet| + json.partial! "shared/partial/tweet", tweet: tweet end diff --git a/app/views/shared/user_ranking.html.haml b/app/views/shared/user_ranking.html.haml index cc514ff..37ba110 100644 --- a/app/views/shared/user_ranking.html.haml +++ b/app/views/shared/user_ranking.html.haml @@ -1,17 +1,20 @@ .users %ul.inline - - @usermap.take(50).each do |user_id, count| - - user = User.find(user_id) + - @usermap.each do |user, count| %li - if user .avatar - = link_to user_path(user.screen_name) do + = link_to user_best_path(user.screen_name) do = image_tag user.profile_image_url, alt: user.screen_name, title: user.name .data - = link_to url_for(params.merge(screen_name_b: user.screen_name)) do - .count= count + .count + - if params[:action] == "discovered_by" + = link_to count, user_discovered_by_user_path(@user.screen_name, user.screen_name) + - elsif params[:action] == "discovered_of" + = link_to count, user_discovered_by_user_path(user.screen_name, @user.screen_name) + - else + - raise Exception - else .avatar= image_tag "missing_profile_image.png", alt: "Missing User: #{user_id}", title: "Missing User: #{user_id}" .data .count= count - diff --git a/app/views/users/info.html.haml b/app/views/users/info.html.haml index 2ca31d9..d55ed13 100644 --- a/app/views/users/info.html.haml +++ b/app/views/users/info.html.haml @@ -7,23 +7,23 @@ %dt Name %dd= raw @user.name %dt tweets - %dd= @user.stats[:stats_api][:tweets_count] + %dd= @stats[:stats_api][:tweets_count] %dt Following - %dd= @user.stats[:stats_api][:friends_count] + %dd= @stats[:stats_api][:friends_count] %dt Followers - %dd= @user.stats[:stats_api][:followers_count] + %dd= @stats[:stats_api][:followers_count] %dt Favorites - %dd= @user.stats[:stats_api][:favorites_count] + %dd= @stats[:stats_api][:favorites_count] %dt Listed - %dd= @user.stats[:stats_api][:listed_count] + %dd= @stats[:stats_api][:listed_count] %dt Bio - %dd= raw @user.stats[:stats_api][:bio] + %dd= raw @stats[:stats_api][:bio] - if @user.registered? %p records %dl.dl-horizontal %dt Favorited - %dd= @user.stats[:favorited_count] + %dd= @stats[:favorited_count] %dt Retweeted - %dd= @user.stats[:retweeted_count] + %dd= @stats[:retweeted_count] %dt Since %dd= @user.account.created_at diff --git a/config/routes.rb b/config/routes.rb index 3a463dc..5ae1ddd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,74 +10,70 @@ Aclog::Application.routes.draw do order: /(fav(orite[sd]?|(or)?ed|s)?|re?t(weet(s|ed)?|s)?)/, } - # static + # MainController root to: "main#index" - get "/about" => "main#about" - get "/about/api" => "main#api" - # internals - get "/i/callback" => "sessions#callback" - get "/i/logout" => "sessions#destroy" - - # other - get "/i/best" => "i#best" - get "/i/recent" => "i#recent" - get "/i/timeline" => "i#timeline" + get "/about" => "main#about", as: "about" + get "/about/api" => "main#api", as: "about_api" - get "/i/favoriters" => "users#favoriters", format: :json - get "/i/:id" => "users#show", constraints: constraints, as: "tweet" - get "/i/show" => "users#show" + # Internals / SessionsController + get "/i/callback" => "sessions#callback" + get "/i/logout" => "sessions#destroy", as: "logout" - # report + # ReportController get "/i/report" => "report#index", as: "report" post "/i/report/tweet" => "report#tweet" - get "/search" => "search#search" + # public + get "/i/best" => "tweets#best", as: "best" + get "/i/recent" => "tweets#recent", as: "recent" + get "/i/timeline" => "tweets#timeline", as: "timeline" + get "/i/:id" => "tweets#show", constraints: constraints, as: "tweet" + get "(/users)/:screen_name/status(es)/:id" => redirect("/i/%{id}"), constraints: constraints - # i -- end - get "/i(/:none)" => redirect("/") + # JSON API + scope :api do + get "/:controller/:action" + end - # user - get "/users" => redirect("/") - get "/users/best" => "users#best" - get "/users/recent" => "users#recent" - get "/users/timeline" => "users#timeline" - get "/users/discovered" => "users#discovered" - get "/users/info" => "users#info" - get "/users/favorited_by" => "users#favorited_by" - get "/users/retweeted_by" => "users#retweeted_by" - get "/users/given_favorites_to" => "users#given_favorites_to" - get "/users/given_retweets_to" => "users#given_retweets_to" + # User pages. + scope ":screen_name", controller: "users", constraints: constraints do + get "/info", action: "info", as: "user_info" + get "/discovered_by", action: "discovered_by", as: "user_discovered_by" + get "/discovered_of", action: "discovered_of", as: "user_discovered_of" + end + scope ":screen_name", controller: "tweets", constraints: constraints do + get "/(:page)", action: "best", as: "user_best" + get "/favorited(/:page)", action: "favorited", as: "user_favorited" + get "/retweeted(/:page)", action: "retweeted", as: "user_retweeted" + get "/recent(/:page)", action: "recent", as: "user_recent" + get "/timeline", action: "timeline", as: "user_timeline" + get "/discoveries", action: "discoveries", as: "user_discoveries" + get "/discovered_by/:screen_name_b", action: "discovered_by", as: "user_discovered_by_user" + end - get "/:screen_name(/:page)" => "users#best", constraints: constraints, as: "user" - get "/:screen_name/:order(/:page)" => "users#best", constraints: constraints - get "/:screen_name/timeline" => "users#timeline", constraints: constraints, as: "timeline" - get "/:screen_name/discovered" => "users#discovered", constraints: constraints, as: "discovered" - get "/:screen_name/discovered/:tweets" => "users#discovered", constraints: constraints - get "/:screen_name/info" => "users#info", constraints: constraints, as: "info" - get "/:screen_name/favorited_by(/:screen_name_b)" => "users#favorited_by", constraints: constraints, as: "favorited_by" - get "/:screen_name/retweeted_by(/:screen_name_b)" => "users#retweeted_by", constraints: constraints, as: "retweeted_by" - get "/:screen_name/given_favorites_to(/:screen_name_b)" => "users#given_favorites_to", constraints: constraints, as: "given_favorites_to" - get "/:screen_name/given_retweets_to(/:screen_name_b)" => "users#given_retweets_to", constraints: constraints, as: "given_retweets_to" - # will be removed..? - get "/:screen_name/recent(/:page)" => "users#recent", constraints: constraints, as: "recent" - get "/:screen_name/recent/:order(/:page)" => "users#recent", constraints: constraints + # Favstar redirects + scope "users/:screen_name", constraints: constraints do + get "/" => redirect("/%{screen_name}") + get "/most_favorited" => redirect("/%{screen_name}/favorite") + get "/most_retweeted" => redirect("/%{screen_name}/retweet") + get "/discovered" => redirect("/%{screen_name}/discovered") + get "/favorited" => redirect("/%{screen_name}/discovered/favorite") + get "/given" => redirect("/%{screen_name}/discovered/favorite") + get "/retweeted" => redirect("/%{screen_name}/discovered/retweet") + get "/recent" => redirect("/%{screen_name}/timeline") + get "/favs_from" => redirect("/%{screen_name}/favorited_by") + get "/favs_from/:screen_name_b" => redirect("/%{screen_name}/favorited_by/%{screen_name_b}") + get "/retweeted_by" => redirect("/%{screen_name}/retweeted_by") + get "/retweeted_by/:screen_name_b" => redirect("/%{screen_name}/retweeted_by/%{screen_name_b}") + get "/given_to" => redirect("/%{screen_name}/given_favorites_to") + get "/given_to/:screen_name_b" => redirect("/%{screen_name}/given_favorites_to/%{screen_name_b}") + end - # redirects - get "(/users)/:screen_name/status(es)/:id" => redirect("/i/%{id}"), constraints: constraints - get "/users/:screen_name" => redirect("/%{screen_name}"), constraints: constraints - get "/users/:screen_name/most_favorited" => redirect("/%{screen_name}/favorite"), constraints: constraints - get "/users/:screen_name/most_retweeted" => redirect("/%{screen_name}/retweet"), constraints: constraints - get "/users/:screen_name/discovered" => redirect("/%{screen_name}/discovered"), constraints: constraints - get "/users/:screen_name/favorited" => redirect("/%{screen_name}/discovered/favorite"), constraints: constraints - get "/users/:screen_name/given" => redirect("/%{screen_name}/discovered/favorite"), constraints: constraints - get "/users/:screen_name/retweeted" => redirect("/%{screen_name}/discovered/retweet"), constraints: constraints - get "/users/:screen_name/recent" => redirect("/%{screen_name}/timeline"), constraints: constraints - get "/users/:screen_name/favs_from" => redirect("/%{screen_name}/favorited_by"), constraints: constraints - get "/users/:screen_name/favs_from/:screen_name_b" => redirect("/%{screen_name}/favorited_by/%{screen_name_b}"), constraints: constraints - get "/users/:screen_name/retweeted_by" => redirect("/%{screen_name}/retweeted_by"), constraints: constraints - get "/users/:screen_name/retweeted_by/:screen_name_b" => redirect("/%{screen_name}/retweeted_by/%{screen_name_b}"), constraints: constraints - get "/users/:screen_name/given_to" => redirect("/%{screen_name}/given_favorites_to"), constraints: constraints - get "/users/:screen_name/given_to/:screen_name_b" => redirect("/%{screen_name}/given_favorites_to/%{screen_name_b}"), constraints: constraints + # deprecated API + get "/users/best" => "tweets#best" + get "/users/recent" => "tweets#recent" + get "/users/timeline" => "tweets#timeline" + get "/users/discovered" => "tweets#discoveries" end |