aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorre4k <re4k@re4k.info>2013-04-22 00:10:18 +0900
committerre4k <re4k@re4k.info>2013-04-22 00:10:18 +0900
commit667d88c12805d2a1f5b62b9ff4e04d6e9ba595fe (patch)
treede23f79ab04ed533364561f3fe44afa49c216797
parent88026553952be01d4b5e46d59c66444d93ad1410 (diff)
downloadaclog-667d88c12805d2a1f5b62b9ff4e04d6e9ba595fe.tar.gz
Unify format of hash, refactor some controller/helper methods
-rw-r--r--Gemfile.lock2
-rw-r--r--app/controllers/application_controller.rb33
-rw-r--r--app/controllers/errors_controller.rb14
-rw-r--r--app/controllers/i_controller.rb9
-rw-r--r--app/controllers/main_controller.rb2
-rw-r--r--app/controllers/report_controller.rb2
-rw-r--r--app/controllers/search_controller.rb12
-rw-r--r--app/controllers/sessions_controller.rb6
-rw-r--r--app/controllers/users_controller.rb61
-rw-r--r--app/helpers/application_helper.rb64
-rw-r--r--app/helpers/users_helper.rb6
-rw-r--r--app/models/account.rb14
-rw-r--r--app/models/favorite.rb10
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/retweet.rb12
-rw-r--r--app/models/stolen_tweet.rb4
-rw-r--r--app/models/tweet.rb42
-rw-r--r--app/models/user.rb26
-rw-r--r--app/views/layouts/_base.html.haml16
-rw-r--r--app/views/layouts/application.html.haml6
-rw-r--r--app/views/layouts/index.html.haml2
-rw-r--r--app/views/main/index.html.haml6
-rw-r--r--app/views/shared/_search.html.haml4
-rw-r--r--app/views/shared/_sidebar_i.html.haml12
-rw-r--r--app/views/shared/_sidebar_main.html.haml1
-rw-r--r--app/views/shared/_sidebar_search.html.haml12
-rw-r--r--app/views/shared/_sidebar_users.html.haml41
-rw-r--r--app/views/shared/_tweet.html.haml44
-rw-r--r--app/views/shared/_tweet.json.jbuilder26
-rw-r--r--app/views/shared/partial/_search.html.haml4
-rw-r--r--app/views/shared/partial/_tweet.html.haml44
-rw-r--r--app/views/shared/partial/_tweet.json.jbuilder24
-rw-r--r--app/views/shared/partial/_user.json.jbuilder (renamed from app/views/shared/_user.json.jbuilder)0
-rw-r--r--app/views/shared/sidebar/_i.html.haml12
-rw-r--r--app/views/shared/sidebar/_main.html.haml1
-rw-r--r--app/views/shared/sidebar/_search.html.haml12
-rw-r--r--app/views/shared/sidebar/_users.html.haml41
-rw-r--r--app/views/shared/tweets.html.haml16
-rw-r--r--app/views/shared/tweets.json.jbuilder2
-rw-r--r--app/views/shared/user_ranking.html.haml17
-rw-r--r--app/views/shared/user_ranking.json.jbuilder (renamed from app/views/shared/users.json.jbuilder)2
-rw-r--r--app/views/shared/users.html.haml18
-rw-r--r--app/views/users/info.json.jbuilder2
-rw-r--r--app/views/users/show.html.haml2
-rw-r--r--app/views/users/show.json.jbuilder2
-rw-r--r--config/environments/development.rb13
-rw-r--r--config/routes.rb78
-rw-r--r--lib/receiver/worker.rb2
48 files changed, 393 insertions, 390 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 39938f2..c10eab9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -36,7 +36,7 @@ GEM
after_commit_action (0.1.3)
activerecord (>= 3.0.0)
arel (4.0.0.beta2)
- atomic (1.1.7)
+ atomic (1.1.8)
bootstrap-sass (2.3.1.0)
sass (~> 3.2)
builder (3.1.4)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c0af3c8..3a727b5 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
class ApplicationController < ActionController::Base
protect_from_forgery
+
before_filter :set_format
after_filter :xhtml
- before_filter :get_include_user
+ helper_method :logged_in?, :page
+ helper_method :get_bool, :get_int
def render_timeline(a = nil, &blk)
@items = a || blk.call
@@ -11,36 +13,19 @@ class ApplicationController < ActionController::Base
@items = @items.where("tweets.id <= ?", max_id) if max_id
@items = @items.where("tweets.id > ?", since_id) if since_id
- if @force_page || page
- @items = @items.page(page || 1).per(count)
- else
- @items = @items.limit(count)
- end
+ @items = @items.limit(count)
+ @items = @items.offset(((page || 1) - 1) * count) if page
render "shared/tweets"
end
+ def logged_in?; session[:user_id] != nil end
+
# params
def page; get_int(params[:page], nil){|i| i > 0} end
def count; get_int(params[:count], 10){|i| (1..100) === i} end
def max_id; get_int(params[:max_id], nil){|i| i >= 0} end
def since_id; get_int(params[:since_id], nil){|i| i >= 0} end
- def user_limit; get_int(params[:limit], 20){|i| i >= 0} end
-
- def force_page
- @force_page = true
- end
-
- def order
- case params[:order]
- when /^fav/
- :favorite
- when /^re?t/
- :retweet
- else
- :default
- end
- end
private
def set_format
@@ -58,10 +43,6 @@ class ApplicationController < ActionController::Base
end
end
- def get_include_user
- @include_user ||= get_bool(params[:include_user])
- end
-
def get_bool(str)
/^(t|true|1)$/ =~ str
end
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index 03b8929..f7087fa 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -10,20 +10,20 @@ class ErrorsController < ApplicationController
# /i/callback
redirect_to root_path
when Aclog::Exceptions::TweetNotFound
- render "error", :status => 404
+ render "error", status: 404
when Aclog::Exceptions::UserNotFound
- render "error", :status => 404
+ render "error", status: 404
when Aclog::Exceptions::UserNotRegistered
- render "error", :status => 404
+ render "error", status: 404
when Aclog::Exceptions::UserProtected
- render "error", :status => 403
+ render "error", status: 403
when Aclog::Exceptions::LoginRequired
- render "error", :status => 403
+ render "error", status: 403
when ActionController::RoutingError
- render "error", :status => 404
+ render "error", status: 404
else
warn @exception
- render "error", :status => 500
+ render "error", status: 500
end
end
end
diff --git a/app/controllers/i_controller.rb b/app/controllers/i_controller.rb
index 46c66b4..8f80762 100644
--- a/app/controllers/i_controller.rb
+++ b/app/controllers/i_controller.rb
@@ -1,12 +1,11 @@
class IController < ApplicationController
- before_filter :force_page, :only => [:best, :recent]
+ before_filter :force_page, only: [:best, :recent]
def best
@title = "Best Tweets"
render_timeline do
Tweet
.reacted
- .not_protected
.original
.order_by_reactions
end
@@ -18,7 +17,6 @@ class IController < ApplicationController
Tweet
.recent
.reacted
- .not_protected
.original
.order_by_reactions
end
@@ -33,4 +31,9 @@ class IController < ApplicationController
.order_by_id
end
end
+
+ private
+ def force_page
+ params[:page] = "1" unless page
+ end
end
diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb
index 0daa55d..ddeb2d2 100644
--- a/app/controllers/main_controller.rb
+++ b/app/controllers/main_controller.rb
@@ -1,7 +1,7 @@
class MainController < ApplicationController
def index
@title = "aclog"
- render :layout => "index"
+ render layout: "index"
end
def about
diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb
index e50e10d..c522986 100644
--- a/app/controllers/report_controller.rb
+++ b/app/controllers/report_controller.rb
@@ -64,6 +64,6 @@ class ReportController < ApplicationController
def add_issue_stolen(resolved, tweet_id, original_id)
Issue.register(Aclog::Constants::IssueType::TWEET_STOLEN,
resolved ? Aclog::Constants::IssueStatus::RESOLVED : Aclog::Constants::IssueStatus::PENDING,
- {:tweet_id => tweet_id, :original_id => original_id})
+ {tweet_id: tweet_id, original_id: original_id})
end
end
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 45f10b1..d344312 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -2,12 +2,14 @@
require "shellwords"
class SearchController < ApplicationController
+ before_filter :force_page
+
def search
@show_search = true
# TODO: OR とか () とか対応したいよね
unless params[:query]
- render_page(Tweet.where(:id => -1))
+ render_timeline(Tweet.where(id: -1))
return
end
words = Shellwords.shellwords(params[:query])
@@ -24,7 +26,7 @@ class SearchController < ApplicationController
if key[0] == "-"
tweets.where("user_id != ?", user ? user.id : -1)
else
- tweets.where(:user_id => user ? user.id : -1)
+ tweets.where(user_id: user ? user.id : -1)
end
when /^-?fav/
search_unless_zero(tweets, "favorites_count", key[0], value)
@@ -66,7 +68,7 @@ class SearchController < ApplicationController
if word[0] == "-"
tweets.where("id < ? OR id >= ?", first_id_of_time(since), first_id_of_time(to))
else
- tweets.where(:id => first_id_of_time(since)...first_id_of_time(to))
+ tweets.where(id: first_id_of_time(since)...first_id_of_time(to))
end
else
# TODO: ツイート検索
@@ -74,7 +76,7 @@ class SearchController < ApplicationController
end
end
- render_page(result)
+ render_timeline(result)
end
private
@@ -87,7 +89,7 @@ class SearchController < ApplicationController
n = flag == "-"
unless num == 0
- tweets.where("#{column}#{n ? "<" : ">="} ?", num)
+ tweets.where("#{column} #{n ? "<" : ">="} ?", num)
else
tweets
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 6138aeb..6ea6aaf 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -13,9 +13,9 @@ class SessionsController < ApplicationController
begin
UNIXSocket.open(Settings.register_server_path) do |socket|
- socket.write({:type => "register",
- :id => account.id,
- :user_id => account.user_id}.to_msgpack)
+ socket.write({type: "register",
+ id: account.id,
+ user_id: account.user_id}.to_msgpack)
end
rescue Exception
# receiver not started?
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index dbd1206..8f932b3 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,17 +1,18 @@
class UsersController < ApplicationController
- before_filter :force_page, :only => [:best, :recent]
- before_filter :require_user, :except => [:show, :favoriters]
- before_filter :include_user_b, :only => [:favorited_by, :retweeted_by, :given_favorites_to, :given_retweets_to]
+ before_filter :force_page, only: [:best, :recent]
+ 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_timeline do
- case order
- when :favorite
+ case params[:order]
+ when /^fav/
@user.tweets.reacted.order_by_favorites
- when :retweet
+ when /^re?t/
@user.tweets.reacted.order_by_retweets
else
@user.tweets.reacted.order_by_reactions
@@ -23,10 +24,10 @@ class UsersController < ApplicationController
@title = "@#{@user.screen_name}'s Recent Best Tweets"
render_timeline do
- case order
- when :favorite
+ case params[:order]
+ when /^fav/
@user.tweets.recent.reacted.order_by_favorites
- when :retweet
+ when /^re?t/
@user.tweets.recent.reacted.order_by_retweets
else
@user.tweets.recent.reacted.order_by_reactions
@@ -65,8 +66,6 @@ class UsersController < ApplicationController
raise Aclog::Exceptions::UserNotRegistered unless @user.registered?
@title = "@#{@user.screen_name} (#{@user.name})'s Profile"
-
- @include_user_stats = true
end
def favorited_by
@@ -102,10 +101,6 @@ class UsersController < ApplicationController
end
def show
- tweet_id = params[:id].to_i
- @item = Tweet.where(:id => tweet_id).first
-
- raise Aclog::Exceptions::TweetNotFound unless @item
@user = @item.user
# import 100
@@ -113,21 +108,14 @@ class UsersController < ApplicationController
session[:account].import_favorites(@item.id)
end
- helpers = ApplicationController.helpers
- @title = "\"#{helpers.strip_tags(helpers.format_tweet_text(@item.text))[0...30]}\" from @#{@user.screen_name}"
+ text = ApplicationController.helpers.format_tweet_text(@item.text)[0...30]
+ @title = "\"#{text}\" from @#{@user.screen_name}"
@title_b = "@#{@user.screen_name}'s Tweet"
-
- @full = get_bool(params[:full])
end
# only json
def favoriters
- tweet_id = params[:id].to_i
- @item = Tweet.where(:id => tweet_id).first
-
- raise Aclog::Exceptions::TweetNotFound unless @item
-
- render json: @item.favorites.map{|f| f.user_id}
+ render json: @item.favorites.load.map{|f| f.user_id}
end
private
@@ -165,7 +153,7 @@ class UsersController < ApplicationController
.inject(Hash.new(0)){|hash, obj| hash[obj.user_id] += 1; hash}
.sort_by{|id, count| -count}
- render "shared/users"
+ render "shared/user_ranking"
end
def render_user_to_user
@@ -187,6 +175,10 @@ class UsersController < ApplicationController
end
end
+ def force_page
+ params[:page] = "1" unless page
+ end
+
def require_user
if params[:screen_name] == "me"
if session[:user_id]
@@ -215,16 +207,25 @@ class UsersController < ApplicationController
end
if !user_b && params[:screen_name_b]
- user_b = User.where(:screen_name => params[:screen_name_b]).first
+ user_b = User.where(screen_name: params[:screen_name_b]).first
end
@user_b = user_b
end
+ def require_tweet
+ tweet_id = params[:id].to_i
+ item = Tweet.where(id: tweet_id).first
+
+ raise Aclog::Exceptions::TweetNotFound unless item
+
+ @item = item
+ end
+
def check_protected
- if @user && @user.protected? && !@user.registered?
- unless session[:account] && session[:account].user_id == @user.id
- raise Aclog::Exceptions::UserProtected if @user.protected
+ if @user && @user.protected?
+ if !@user.registered? || !session[:account] || session[:account].user_id != @user.id
+ raise Aclog::Exceptions::UserProtected
end
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1ce3b7b..52c098e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,26 +1,33 @@
-require "time"
-
module ApplicationHelper
def format_time(dt)
dt.to_time.localtime("+09:00").strftime("%Y-%m-%d %H:%M:%S")
end
- def format_date_ago(dt)
- "#{(DateTime.now.utc - dt.to_datetime).to_i}d ago"
- end
-
def format_tweet_text(text)
- text
- .gsub(/<url:(.+?):(.+?)>/){link_to(CGI.unescape($2), CGI.unescape($1), :target => "_blank")}
- .gsub(/<hashtag:(.+?)>/){link_to("##{CGI.unescape($1)}", "https://twitter.com/search?q=%23#{$1}")}
- .gsub(/<cashtag:(.+?)>/){link_to("$#{CGI.unescape($1)}", "https://twitter.com/search?q=%23#{$1}")}
- .gsub(/<mention:(.+?)>/){link_to("@#{CGI.unescape($1)}", "/#{$1}")}
- .gsub(/\r\n|\r|\n/, "<br />")
- end
+ ret = text.gsub(/<([a-z]+?):(.+?)(?::(.+?))?>/) do
+ case $1
+ when "mention"
+ screen_name = CGI.unescape($2)
+ link_to("@#{screen_name}", "/#{screen_name}")
+ when "url"
+ display = CGI.unescape($3)
+ expanded_url = CGI.unescape($2)
+ link_to(display, expanded_url)
+ when "hashtag"
+ hashtag = CGI.unescape($2)
+ link_to("##{hashtag}", "https://twitter.com/search?q=#{CGI.escape("##{hashtag}")}")
+ when "symbol"
+ symbol = CGI.unescape($2)
+ link_to("##{symbol}", "https://twitter.com/search?q=#{CGI.escape("$#{symbol}")}")
+ else
+ $&
+ end
+ end
+ ret.gsub!(/\r\n|\r|\n/, "<br />")
- def format_source_text(text)
- format_tweet_text(text)
+ return ret
end
+ alias format_source_text format_tweet_text
def twitter_status_url(tweet)
"https://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id}"
@@ -30,33 +37,28 @@ module ApplicationHelper
"https://twitter.com/#{screen_name}"
end
- def link_to_user_page(screen_name, &blk)
- if block_given?
- body = capture(&blk)
- end
-
- body ||= "@#{screen_name}"
- link_to(body, :controller => "users", :action => "best", :screen_name => screen_name)
+ def user_icon_link(user)
+ logger.error("DEPRECATED user_icon_link")
+ link_to(image_tag(user.profile_image_url, alt: user.screen_name, title: user.name), user_path(user.screen_name))
end
+ def include_user?; get_bool(params[:include_user]) end
def user_limit
i = params[:limit].to_i
- if i == 0
+ if i > 0
+ return i
+ elsif i == -1
+ return nil
+ else
if params[:action] == "show"
- if params[:full] == "true"
- return nil
- else
- return 100
- end
+ return 100
else
return 20
end
- else
- return i
end
end
- # utf8
+ # utf8, form
def utf8_enforcer_tag
raw ""
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 0000000..2610ca2
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,6 @@
+require "time"
+module UsersHelper
+ def format_date_ago(dt)
+ "#{(DateTime.now.utc - dt.to_datetime).to_i}d ago"
+ end
+end
diff --git a/app/models/account.rb b/app/models/account.rb
index 2eb9032..30319f8 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -1,6 +1,6 @@
class Account < ActiveRecord::Base
def self.register_or_update(hash)
- account = where(:user_id => hash[:user_id]).first_or_initialize
+ account = where(user_id: hash[:user_id]).first_or_initialize
account.oauth_token = hash[:oauth_token]
account.oauth_token_secret = hash[:oauth_token_secret]
account.consumer_version = hash[:consumer_version]
@@ -14,15 +14,15 @@ class Account < ActiveRecord::Base
def client
Twitter::Client.new(
- :consumer_key => Settings.consumer[consumer_version.to_i].key,
- :consumer_secret => Settings.consumer[consumer_version.to_i].secret,
- :oauth_token => oauth_token,
- :oauth_token_secret => oauth_token_secret)
+ consumer_key: Settings.consumer[consumer_version.to_i].key,
+ consumer_secret: Settings.consumer[consumer_version.to_i].secret,
+ oauth_token: oauth_token,
+ oauth_token_secret: oauth_token_secret)
end
def twitter_user(uid = nil)
uid ||= user_id
- Rails.cache.fetch("twitter_user/#{uid}", :expires_in => 1.hour) do
+ Rails.cache.fetch("twitter_user/#{uid}", expires_in: 1.hour) do
client.user(uid) rescue nil
end
end
@@ -39,7 +39,7 @@ class Account < ActiveRecord::Base
end
# rts 回収・RTのステータスIDを取得する必要がある
- client.retweets(id, :count => 100).each do |status|
+ client.retweets(id, count: 100).each do |status|
Retweet.from_tweet_object(status)
end
end
diff --git a/app/models/favorite.rb b/app/models/favorite.rb
index f1fc836..df894fc 100644
--- a/app/models/favorite.rb
+++ b/app/models/favorite.rb
@@ -17,8 +17,8 @@ class Favorite < ActiveRecord::Base
def self.from_hash(hash)
begin
- f = create!(:tweet_id => hash[:tweet_id],
- :user_id => hash[:user_id])
+ f = create!(tweet_id: hash[:tweet_id],
+ user_id: hash[:user_id])
logger.debug("Created Favorite: #{hash[:user_id]} => #{hash[:tweet_id]}")
return f
@@ -32,14 +32,14 @@ class Favorite < ActiveRecord::Base
def self.from_tweet_object(tweet_object)
if tweet_object.favoriters.is_a? Array
tweet_object.favoriters.reverse.map do |uid|
- from_hash(:user_id => uid, :tweet_id => tweet_object.id)
+ from_hash(user_id: uid, tweet_id: tweet_object.id)
end
end
end
def self.delete_from_hash(hash)
- where(:tweet_id => hash[:tweet_id])
- .where(:user_id => hash[:user_id])
+ where(tweet_id: hash[:tweet_id])
+ .where(user_id: hash[:user_id])
.destroy_all
end
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 9444304..ad99a02 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -1,7 +1,7 @@
class Issue < ActiveRecord::Base
def self.register(issue_type, status, data)
begin
- create!(:issue_type => issue_type, :status => status, :data => Yajl::Encoder::encode(data))
+ create!(issue_type: issue_type, status: status, data: Yajl::Encoder::encode(data))
rescue
logger.error($!)
logger.error($@)
diff --git a/app/models/retweet.rb b/app/models/retweet.rb
index 032c242..5509c7f 100644
--- a/app/models/retweet.rb
+++ b/app/models/retweet.rb
@@ -17,9 +17,9 @@ class Retweet < ActiveRecord::Base
def self.from_hash(hash)
begin
- r = create!(:id => hash[:id],
- :tweet_id => hash[:tweet_id],
- :user_id => hash[:user_id])
+ r = create!(id: hash[:id],
+ tweet_id: hash[:tweet_id],
+ user_id: hash[:user_id])
logger.debug("Created Retweet: #{hash[:id]}: #{hash[:user_id]} => #{hash[:tweet_id]}")
return r
@@ -32,8 +32,8 @@ class Retweet < ActiveRecord::Base
def self.from_tweet_object(status)
User.from_user_object(status.user)
- from_hash(:id => status.id,
- :user_id => status.user.id,
- :tweet_id => status.retweeted_status.id)
+ from_hash(id: status.id,
+ user_id: status.user.id,
+ tweet_id: status.retweeted_status.id)
end
end
diff --git a/app/models/stolen_tweet.rb b/app/models/stolen_tweet.rb
index b3f7da1..aa2d01d 100644
--- a/app/models/stolen_tweet.rb
+++ b/app/models/stolen_tweet.rb
@@ -1,10 +1,10 @@
class StolenTweet < ActiveRecord::Base
belongs_to :tweet
- belongs_to :original, :class_name => :Tweet
+ belongs_to :original, class_name: :Tweet
def self.register(original_tweet, the_tweet)
begin
- create!(:tweet_id => the_tweet.id, :original_id => original_tweet.id)
+ create!(tweet_id: the_tweet.id, original_id: original_tweet.id)
rescue ActiveRecord::RecordNotUnique
logger.error("Duplicate Stolen Info")
rescue
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index 98b4f84..59a4575 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -1,13 +1,13 @@
class Tweet < ActiveRecord::Base
belongs_to :user
- has_many :favorites, ->{order("favorites.id")}, :dependent => :delete_all
- has_many :retweets, ->{order("retweets.id")}, :dependent => :delete_all
- has_many :favoriters, ->{order("favorites.id")}, :through => :favorites, :source => :user
- has_many :retweeters, ->{order("retweets.id")}, :through => :retweets, :source => :user
+ has_many :favorites, ->{order("favorites.id")}, dependent: :delete_all
+ has_many :retweets, ->{order("retweets.id")}, dependent: :delete_all
+ has_many :favoriters, ->{order("favorites.id")}, through: :favorites, source: :user
+ has_many :retweeters, ->{order("retweets.id")}, through: :retweets, source: :user
- has_one :stolen_tweet, ->{includes(:original)}, :dependent => :delete
- has_one :original, :through => :stolen_tweet, :source => :original
+ has_one :stolen_tweet, ->{includes(:original)}, dependent: :delete
+ has_one :original, through: :stolen_tweet, source: :original
scope :recent, -> do
where("tweets.tweeted_at > ?", Time.zone.now - 3.days)
@@ -34,11 +34,11 @@ class Tweet < ActiveRecord::Base
end
scope :favorited_by, -> user do
- joins(:favorites).where(:favorites => {:user_id => user.id})
+ joins(:favorites).where(favorites: {user_id: user.id})
end
scope :retweeted_by, -> user do
- joins(:retweets).where(:retweets => {:user_id => user.id})
+ joins(:retweets).where(retweets: {user_id: user.id})
end
scope :discovered_by, -> user do
@@ -50,16 +50,16 @@ class Tweet < ActiveRecord::Base
end
scope :original, -> do
- joins("LEFT JOIN stolen_tweets ON tweets.id = stolen_tweets.tweet_id").where(:stolen_tweets => {:tweet_id => nil})
+ joins("LEFT JOIN stolen_tweets ON tweets.id = stolen_tweets.tweet_id").where(stolen_tweets: {tweet_id: nil})
end
scope :not_protected, -> do
- includes(:user).where(:users => {:protected => false})
+ includes(:user).where(users: {protected: false})
end
def self.cached(id)
- Rails.cache.fetch("tweet/#{id}", :expires_in => 3.hour) do
- where(:id => id).first
+ Rails.cache.fetch("tweet/#{id}", expires_in: 3.hour) do
+ where(id: id).first
end
end
@@ -76,12 +76,12 @@ class Tweet < ActiveRecord::Base
def self.delete_from_id(id)
begin
# counter_cache の無駄を省くために delete_all で
- deleted_tweets = Tweet.delete_all(:id => id)
+ deleted_tweets = Tweet.delete_all(id: id)
if deleted_tweets.to_i > 0
- Favorite.delete_all(:tweet_id => id)
- Retweet.delete_all(:tweet_id => id)
+ Favorite.delete_all(tweet_id: id)
+ Retweet.delete_all(tweet_id: id)
else
- Retweet.where(:id => id).destroy_all # counter_cache
+ Retweet.where(id: id).destroy_all # counter_cache
end
rescue
logger.error("Unknown error while deleting tweet: #{$!}/#{$@}")
@@ -90,11 +90,11 @@ class Tweet < ActiveRecord::Base
def self.from_hash(hash)
begin
- t = create!(:id => hash[:id],
- :text => hash[:text],
- :source => hash[:source],
- :tweeted_at => hash[:tweeted_at],
- :user_id => hash[:user_id])
+ t = create!(id: hash[:id],
+ text: hash[:text],
+ source: hash[:source],
+ tweeted_at: hash[:tweeted_at],
+ user_id: hash[:user_id])
return t
rescue ActiveRecord::RecordNotUnique
logger.debug("Duplicate Tweet: #{hash[:id]}")
diff --git a/app/models/user.rb b/app/models/user.rb
index 57ed545..9cf6886 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,17 +1,17 @@
class User < ActiveRecord::Base
- has_many :tweets, :dependent => :delete_all
- has_many :favorites, :dependent => :delete_all
- has_many :retweets, :dependent => :delete_all
+ has_many :tweets, dependent: :delete_all
+ has_many :favorites, dependent: :delete_all
+ has_many :retweets, dependent: :delete_all
def self.cached(identity)
if identity.is_a?(Fixnum) || identity.is_a?(Bignum)
- Rails.cache.fetch("user/#{identity}", :expires_in => 3.hour) do
- where(:id => identity).first
+ Rails.cache.fetch("user/#{identity}", expires_in: 3.hour) do
+ where(id: identity).first
end
elsif identity.is_a?(String)
if /^[A-Za-z0-9_]{1,15}$/ =~ identity
- uid = Rails.cache.fetch("screen_name/#{identity}", :expires_in => 3.hour) do
- if user = where(:screen_name => identity).first
+ uid = Rails.cache.fetch("screen_name/#{identity}", expires_in: 3.hour) do
+ if user = where(screen_name: identity).first
user.id
end
end
@@ -50,11 +50,11 @@ class User < ActiveRecord::Base
end
def self.from_user_object(user_object)
- from_hash(:id => user_object.id,
- :screen_name => user_object.screen_name,
- :name => user_object.name,
- :profile_image_url => user_object.profile_image_url_https,
- :protected => user_object.protected)
+ from_hash(id: user_object.id,
+ screen_name: user_object.screen_name,
+ name: user_object.name,
+ profile_image_url: user_object.profile_image_url_https,
+ protected: user_object.protected)
end
def self.delete_cache(uid)
@@ -71,7 +71,7 @@ class User < ActiveRecord::Base
end
def account
- Account.where(:user_id => id).first
+ Account.where(user_id: id).first
end
def profile_image_url_original
diff --git a/app/views/layouts/_base.html.haml b/app/views/layouts/_base.html.haml
index ddae521..d0c876c 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= raw @title.to_s + " - aclog"
+ %title= strip_tags(@title.to_s) + " - aclog"
= stylesheet_link_tag "application"
= javascript_include_tag "twitter"
= javascript_include_tag "application"
@@ -10,17 +10,17 @@
.navbar-inner
.container
.brand
- = link_to "aclog", :controller => "main", :action => "index"
+ = link_to "aclog", controller: "main", action: "index"
%ul.nav.pull-right
%li
- = link_to "report", :controller => "report", :action => "index"
+ = link_to "report", controller: "report", action: "index"
%li
- = link_to "search", :controller => "search", :action => "search"
+ = link_to "search", controller: "search", action: "search"
%li
- = link_to "about", :controller => "main", :action => "about"
- - if session[:user_id]
- %li= link_to "logout", :controller => "sessions", :action => "destroy"
- %li= link_to_user_page session[:account].user.screen_name
+ = link_to "about", controller: "main", action: "about"
+ - 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)
- 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 0da35f7..aeee99b 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -1,7 +1,7 @@
-= render :layout => "layouts/base" do
+= render layout: "layouts/base" do
.row
.span2
- .sidebar= render :partial => "shared/sidebar_#{params[:controller]}"
+ .sidebar= render partial: "shared/sidebar/#{params[:controller]}"
.span10
- %h1= @title_b || @title
+ %h1= strip_tags(@title_b || @title)
= yield
diff --git a/app/views/layouts/index.html.haml b/app/views/layouts/index.html.haml
index 4c0da9c..f56cabd 100644
--- a/app/views/layouts/index.html.haml
+++ b/app/views/layouts/index.html.haml
@@ -1,2 +1,2 @@
-= render :layout => "layouts/base" do
+= render layout: "layouts/base" do
= yield
diff --git a/app/views/main/index.html.haml b/app/views/main/index.html.haml
index 7e1bbf2..a420e34 100644
--- a/app/views/main/index.html.haml
+++ b/app/views/main/index.html.haml
@@ -11,7 +11,7 @@
= link_to "アプリ連携", "https://twitter.com/settings/applications"
から不要な "AcLog" と "Aclog2" は解除しても大丈夫です。
%h4
- 今後の予定(2013/04/16)
+ 今後の予定(2013/04/20)
%ul
%li ふぁぼ爆撃対策: TLふぁぼり(エタフォ)・ユーザーTLふぁぼり(fav2you)対策
%li 通知を細かく設定できるように
@@ -21,7 +21,7 @@
%p
ふぁぼ爆撃(無差別なふぁぼなど)と判断された場合は数時間ふぁぼりの記録が停止されます。基準は相当高く設定しているので誤判定はまずないとは思いますがもしなにかあれば連絡ください。
%p
- = link_to "ツイート", "https://twitter.com/share", :class => "twitter-share-button", :"data-text" => "aclog", :"data-count" => "none", :"data-url" => "http://aclog.koba789.com/"
+ = link_to "ツイート", "https://twitter.com/share", class: "twitter-share-button", data: {text: "aclog", count: "none", url: "http://aclog.koba789.com"}
%hr
%h5
連絡先
@@ -29,5 +29,5 @@
%dt Twitter
%dd= link_to "@cn", "https://twitter.com/cn"
%dt メール(あんまり見ていません)
- %dd= link_to "contact@re4k.info", "mailto:contact@re4k.info"
+ %dd= mail_to "contact@re4k.info"
diff --git a/app/views/shared/_search.html.haml b/app/views/shared/_search.html.haml
deleted file mode 100644
index 2eeb390..0000000
--- a/app/views/shared/_search.html.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-.search
- = form_tag({:controller => "search", :action => "search"}, {:method => :get}) do
- = text_field_tag :query, params[:query]
- = submit_tag "search", :name => nil
diff --git a/app/views/shared/_sidebar_i.html.haml b/app/views/shared/_sidebar_i.html.haml
deleted file mode 100644
index 098b35c..0000000
--- a/app/views/shared/_sidebar_i.html.haml
+++ /dev/null
@@ -1,12 +0,0 @@
-%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
deleted file mode 100644
index dcc2630..0000000
--- a/app/views/shared/_sidebar_main.html.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render "shared/sidebar_i"
diff --git a/app/views/shared/_sidebar_search.html.haml b/app/views/shared/_sidebar_search.html.haml
deleted file mode 100644
index 098b35c..0000000
--- a/app/views/shared/_sidebar_search.html.haml
+++ /dev/null
@@ -1,12 +0,0 @@
-%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_users.html.haml b/app/views/shared/_sidebar_users.html.haml
deleted file mode 100644
index c5475ce..0000000
--- a/app/views/shared/_sidebar_users.html.haml
+++ /dev/null
@@ -1,41 +0,0 @@
-.sidebar
- .avatar
- = link_to_user_page @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?
- %ul.records
- %li
- %span favorited
- %span.data= @user.stats[:favorited_count]
- %li
- %span retweeted
- %span.data= @user.stats[:retweeted_count]
- %li
- %span avg. fav
- %span.data= ((@user.stats[:favorited_count] + 0.0) / @user.stats[:tweets_count]).round(2)
- %li
- %span joined
- %span.data= format_date_ago(@user.created_at)
- - 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 "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 "retweeted 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
deleted file mode 100644
index c8c3a09..0000000
--- a/app/views/shared/_tweet.html.haml
+++ /dev/null
@@ -1,44 +0,0 @@
-.item
- .tweet
- .left
- .avatar
- = link_to image_tag(item.user.profile_image_url, :alt => item.user.screen_name, :title => item.user.name), :controller => "users", :action => "best", :screen_name => item.user.screen_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}"
- .tweet_content_fix
- .tweet_content
- .user
- %span.name
- = link_to_user_page item.user.screen_name do
- = item.user.name
- %span.screen_name= link_to_user_page item.user.screen_name
- .text{:class => item.stolen_tweet ? "copied" : nil}
- = raw format_tweet_text(item.text)
- .meta.clearfix
- %span.twitter_bird
- = link_to image_tag("bird_gray_16.png", :alt => "Twitter"), twitter_status_url(item), :target => "_blank"
- %span.created_at
- = link_to format_time(item.tweeted_at), :controller => "users", :action => "show", :id => item.id
- - if item.stolen_tweet
- %span.copied
- = link_to "original", :controller => "users", :action => "show", :id => item.original.id
- %span.source
- = raw format_source_text(item.source)
- .stats
- - [["favs", item.favoriters], ["retweets", item.retweeters]].select{|m| m[1].count > 0}.each do |type, actions|
- %dl.dl-horizontal
- %dt
- %span.count= actions.count
- %span.type= type
- - if user_limit && params[:action] == "show"
- %span.full
- = link_to "show full", params.merge(:full => true)
- %dd
- %ul.inline
- - actions.take(user_limit || actions.count).each do |m|
- %li
- = link_to_user_page m.screen_name do
- = image_tag m.profile_image_url, :alt => m.screen_name, :title => m.name
diff --git a/app/views/shared/_tweet.json.jbuilder b/app/views/shared/_tweet.json.jbuilder
deleted file mode 100644
index 15dae1b..0000000
--- a/app/views/shared/_tweet.json.jbuilder
+++ /dev/null
@@ -1,26 +0,0 @@
-json.(item, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count)
-
-json.user do
- json.id item.user_id
- if @include_user
- json.partial! "shared/user", :user => item.user
- end
-end
-
-render_actions = -> name, data, render_id do
- n = 0
- json.__send__(name, data) do |action|
- json.id action.id if render_id
- json.user do
- json.id action.user_id
- if @include_user && (!user_limit || n < user_limit)
- json.partial! "shared/user", :user => action.user
- end
- end
- n += 1
- end
-end
-
-render_actions.call(:favorites, item.favorites.includes(:user), false)
-render_actions.call(:retweets, item.retweets.includes(:user), true)
-
diff --git a/app/views/shared/partial/_search.html.haml b/app/views/shared/partial/_search.html.haml
new file mode 100644
index 0000000..14a15d1
--- /dev/null
+++ b/app/views/shared/partial/_search.html.haml
@@ -0,0 +1,4 @@
+.search
+ = form_tag({controller: "search", action: "search"}, {method: :get}) do
+ = text_field_tag :query, params[:query]
+ = submit_tag "search", name: nil
diff --git a/app/views/shared/partial/_tweet.html.haml b/app/views/shared/partial/_tweet.html.haml
new file mode 100644
index 0000000..a1b3c7a
--- /dev/null
+++ b/app/views/shared/partial/_tweet.html.haml
@@ -0,0 +1,44 @@
+.item
+ .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
+ %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}"
+ .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)
+ .meta.clearfix
+ %span.twitter_bird
+ = link_to image_tag("bird_gray_16.png", alt: "Twitter"), twitter_status_url(item), target: "_blank"
+ %span.created_at
+ = link_to format_time(item.tweeted_at), tweet_path(item.id)
+ - if params[:action] == "show"
+ %span.full
+ = link_to "full", params.merge(limit: -1)
+ - if item.stolen_tweet
+ %span.copied
+ = link_to "original", tweet_path(item.original.id)
+ %span.source
+ = raw format_source_text(item.source)
+ .stats
+ - [["favs", item.favoriters], ["retweets", item.retweeters]].each do |type, actions|
+ - if actions.count > 0
+ %dl.dl-horizontal
+ %dt
+ %span.count= actions.count
+ %span.type= type
+ %dd
+ %ul.inline
+ - actions.limit(user_limit).each do |m|
+ %li
+ = link_to user_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
new file mode 100644
index 0000000..eb15878
--- /dev/null
+++ b/app/views/shared/partial/_tweet.json.jbuilder
@@ -0,0 +1,24 @@
+json.(item, :id, :text, :source, :tweeted_at, :favorites_count, :retweets_count)
+
+json.user do
+ json.id item.user_id
+ if include_user?
+ json.partial! "shared/partial/user", user: item.user
+ end
+end
+
+render_actions = -> name, data, render_id do
+ json.__send__(name, data.includes(:user).limit(user_limit).load) do |action|
+ json.id action.id if render_id
+ json.user do
+ json.id action.user_id
+ if include_user?
+ json.partial! "shared/partial/user", user: action.user
+ end
+ end
+ end
+end
+
+render_actions.call(:favorites, item.favorites, false)
+render_actions.call(:retweets, item.retweets, true)
+
diff --git a/app/views/shared/_user.json.jbuilder b/app/views/shared/partial/_user.json.jbuilder
index fe64d8d..fe64d8d 100644
--- a/app/views/shared/_user.json.jbuilder
+++ b/app/views/shared/partial/_user.json.jbuilder
diff --git a/app/views/shared/sidebar/_i.html.haml b/app/views/shared/sidebar/_i.html.haml
new file mode 100644
index 0000000..fe298ac
--- /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..774d930
--- /dev/null
+++ b/app/views/shared/sidebar/_main.html.haml
@@ -0,0 +1 @@
+= render "shared/sidebar/i"
diff --git a/app/views/shared/sidebar/_search.html.haml b/app/views/shared/sidebar/_search.html.haml
new file mode 100644
index 0000000..fe298ac
--- /dev/null
+++ b/app/views/shared/sidebar/_search.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/_users.html.haml b/app/views/shared/sidebar/_users.html.haml
new file mode 100644
index 0000000..eaba8b1
--- /dev/null
+++ b/app/views/shared/sidebar/_users.html.haml
@@ -0,0 +1,41 @@
+.sidebar
+ .avatar
+ = link_to user_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?
+ %ul.records
+ %li
+ %span favorited
+ %span.data= @user.stats[:favorited_count]
+ %li
+ %span retweeted
+ %span.data= @user.stats[:retweeted_count]
+ %li
+ %span avg. fav
+ %span.data= ((@user.stats[:favorited_count] + 0.0) / @user.stats[:tweets_count]).round(2)
+ %li
+ %span joined
+ %span.data= format_date_ago(@user.created_at)
+ - 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", info_path(@user.screen_name)
+ %li
+ = link_to "best", user_path(@user.screen_name)
+ %li
+ = link_to "timeline", timeline_path(@user.screen_name)
+ %li
+ = link_to "discovered", discovered_path(@user.screen_name)
+ %li
+ = link_to "favorited by", favorited_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)
diff --git a/app/views/shared/tweets.html.haml b/app/views/shared/tweets.html.haml
index 55e8e42..04fb985 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/search"
+ = render partial: "shared/partial/search"
.items
- = render :partial => "shared/tweet", :collection => @items, :as => :item
+ = render partial: "shared/partial/tweet", collection: @items, as: :item
.loading
- = image_tag "loading.gif", :alt => "loading...", :title => nil
-- if /offset/i =~ @items.to_sql
- = paginate(@items)
-- elsif @items.last
- .pagination
- = link_to raw("Next &#8250;"), params.merge(:max_id => @items.last.id - 1), :rel => :next
+ = image_tag "loading.gif", alt: "loading...", title: nil
+.pagination
+ - if page
+ = link_to raw("Next &#8250;"), params.merge(page: (page || 1) + 1), rel: :next
+ - elsif @items.last
+ = link_to raw("Next &#8250;"), params.merge(max_id: @items.last.id - 1), rel: :next
diff --git a/app/views/shared/tweets.json.jbuilder b/app/views/shared/tweets.json.jbuilder
index d2637d3..b623a1e 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/tweet", :item => item
+ json.partial! "shared/partial/tweet", item: item
end
diff --git a/app/views/shared/user_ranking.html.haml b/app/views/shared/user_ranking.html.haml
new file mode 100644
index 0000000..c7e1a63
--- /dev/null
+++ b/app/views/shared/user_ranking.html.haml
@@ -0,0 +1,17 @@
+.users
+ %ul.inline
+ - @usermap.take(50).each do |user_id, count|
+ - user = User.cached(user_id)
+ %li
+ - if user
+ .avatar
+ = link_to user_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
+ - 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/shared/users.json.jbuilder b/app/views/shared/user_ranking.json.jbuilder
index d58c584..8bbdd42 100644
--- a/app/views/shared/users.json.jbuilder
+++ b/app/views/shared/user_ranking.json.jbuilder
@@ -3,7 +3,7 @@ json.array! @usermap do |json, u|
json.user do |json|
json.id u[0]
if @include_user
- json.partial! "shared/user", :user => User.cached(u[0])
+ json.partial! "shared/partial/user", user: User.cached(u[0])
end
end
end
diff --git a/app/views/shared/users.html.haml b/app/views/shared/users.html.haml
deleted file mode 100644
index 22085f3..0000000
--- a/app/views/shared/users.html.haml
+++ /dev/null
@@ -1,18 +0,0 @@
-.users
- %ul.inline
- - @usermap.take(50).each do |user_id, count|
- - user = User.cached(user_id)
- %li
- - if user
- = link_to_user_page user.screen_name do
- .avatar= 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
- .type= @event_type
- - else
- .avatar= image_tag asset_path("missing_profile_image.png"), :alt => "Missing User: #{user_id}", :title => "Missing User: #{user_id}"
- .data
- .count= count
- .type= @event_type
-
diff --git a/app/views/users/info.json.jbuilder b/app/views/users/info.json.jbuilder
index cae64a6..6969d81 100644
--- a/app/views/users/info.json.jbuilder
+++ b/app/views/users/info.json.jbuilder
@@ -1 +1 @@
-json.partial! "shared/user", :user => @user
+json.partial! "shared/partial/user", user: @user
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index 653cf6f..f36774a 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -1,3 +1,3 @@
.items
- = render :partial => "shared/tweet", :locals => {:item => @item}
+ = render partial: "shared/partial/tweet", locals: {item: @item}
diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder
index bca1b00..8b23df5 100644
--- a/app/views/users/show.json.jbuilder
+++ b/app/views/users/show.json.jbuilder
@@ -1,2 +1,2 @@
-json.partial! "shared/tweet", :item => @item
+json.partial! "shared/partial/tweet", item: @item
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 59f205b..37cf220 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -25,5 +25,16 @@ Aclog::Application.configure do
# Expands the lines which load the assets.
config.assets.debug = true
- config.cache_store = :dalli_store
+ # Ommit logging when serving assets.
+ config.assets.logger = false
+ Rails::Rack::Logger.class_eval do
+ def call_with_quiet_assets(env)
+ previous_level = Rails.logger.level
+ Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
+ call_without_quiet_assets(env).tap do
+ Rails.logger.level = previous_level
+ end
+ end
+ alias_method_chain :call, :quiet_assets
+ end
end
diff --git a/config/routes.rb b/config/routes.rb
index 62c89a1..4d15ffa 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,17 +1,17 @@
Aclog::Application.routes.draw do
constraints = {
- :id => /[0-9]+/,
- :user_id => /[0-9]+/,
- :screen_name => /[a-zA-Z0-9_]{1,20}/,
- :screen_name_b => /[a-zA-Z0-9_]{1,20}/,
- :page => /[0-9]+/,
- :count => /[0-9]+/,
- :tweets => /(all|fav(orite[sd]?|(or)?ed|s)?|re?t(weet(s|ed)?|s)?)/,
- :order => /(fav(orite[sd]?|(or)?ed|s)?|re?t(weet(s|ed)?|s)?)/,
+ id: /[0-9]+/,
+ user_id: /[0-9]+/,
+ screen_name: /[a-zA-Z0-9_]{1,20}/,
+ screen_name_b: /[a-zA-Z0-9_]{1,20}/,
+ page: /[0-9]+/,
+ count: /[0-9]+/,
+ tweets: /(all|fav(orite[sd]?|(or)?ed|s)?|re?t(weet(s|ed)?|s)?)/,
+ order: /(fav(orite[sd]?|(or)?ed|s)?|re?t(weet(s|ed)?|s)?)/,
}
# static
- root :to => "main#index"
+ root to: "main#index"
get "/about" => "main#about"
get "/about/api" => "main#api"
@@ -24,12 +24,12 @@ Aclog::Application.routes.draw do
get "/i/recent" => "i#recent"
get "/i/timeline" => "i#timeline"
+ get "/i/favoriters" => "users#favoriters", format: :json
+ get "/i/:id" => "users#show", constraints: constraints, as: "tweet"
get "/i/show" => "users#show"
- get "/i/favoriters" => "users#favoriters", :format => :json
- get "/i/:id" => "users#show", :constraints => constraints
# report
- get "/i/report" => "report#index"
+ get "/i/report" => "report#index", as: "report"
post "/i/report/tweet" => "report#tweet"
get "/search" => "search#search"
@@ -49,33 +49,33 @@ Aclog::Application.routes.draw do
get "/users/given_favorites_to" => "users#given_favorites_to"
get "/users/given_retweets_to" => "users#given_retweets_to"
- get "/:screen_name(/:page)" => "users#best", :constraints => constraints
- get "/:screen_name/:order(/:page)" => "users#best", :constraints => constraints
- get "/:screen_name/recent(/:page)" => "users#recent", :constraints => constraints
- get "/:screen_name/recent/:order(/:page)" => "users#recent", :constraints => constraints
- get "/:screen_name/timeline(/:page)" => "users#timeline", :constraints => constraints
- get "/:screen_name/discovered(/:page)" => "users#discovered", :constraints => constraints
- get "/:screen_name/discovered/:tweets(/:page)" => "users#discovered", :constraints => constraints
- get "/:screen_name/info" => "users#info", :constraints => constraints
- get "/:screen_name/favorited_by(/:screen_name_b)" => "users#favorited_by", :constraints => constraints
- get "/:screen_name/retweeted_by(/:screen_name_b)" => "users#retweeted_by", :constraints => constraints
- get "/:screen_name/given_favorites_to(/:screen_name_b)" => "users#given_favorites_to", :constraints => constraints
- get "/:screen_name/given_retweets_to(/:screen_name_b)" => "users#given_retweets_to", :constraints => constraints
+ get "/:screen_name(/:page)" => "users#best", constraints: constraints, as: "user"
+ get "/:screen_name/:order(/:page)" => "users#best", constraints: constraints
+ get "/:screen_name/recent(/:page)" => "users#recent", constraints: constraints, as: "recent"
+ get "/:screen_name/recent/:order(/:page)" => "users#recent", constraints: constraints
+ get "/:screen_name/timeline(/:page)" => "users#timeline", constraints: constraints, as: "timeline"
+ get "/:screen_name/discovered(/:page)" => "users#discovered", constraints: constraints, as: "discovered"
+ get "/:screen_name/discovered/:tweets(/:page)" => "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"
# 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
+ 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
end
diff --git a/lib/receiver/worker.rb b/lib/receiver/worker.rb
index 36feec2..87c8738 100644
--- a/lib/receiver/worker.rb
+++ b/lib/receiver/worker.rb
@@ -241,7 +241,7 @@ class Receiver::Worker < DaemonSpawn::Base
end
def initialize(opts = {})
- super(opts)
+ super(opts) unless opts.empty?
_logger = Logger.new(STDOUT)
_logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG
ActiveRecord::Base.logger = Rails.logger = _logger