aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorre4k <re4k@re4k.info>2013-03-06 20:56:58 +0900
committerre4k <re4k@re4k.info>2013-03-06 20:56:58 +0900
commitb377c6af210e6d1e8b550c3c377b84299cd111d8 (patch)
tree975ef33017e060f7c0a977566739e7f97ef65451
parenta6a3e8317e1f9fa435ad434c05dc4336b8f2e299 (diff)
downloadaclog-b377c6af210e6d1e8b550c3c377b84299cd111d8.tar.gz
* Reduce the number of calling DB.
* Improve design(a little).
-rw-r--r--.gitignore4
-rw-r--r--web/app/assets/stylesheets/_tweets.css.sass75
-rw-r--r--web/app/assets/stylesheets/application.css.sass34
-rw-r--r--web/app/controllers/application_controller.rb18
-rw-r--r--web/app/controllers/sessions_controller.rb1
-rw-r--r--web/app/controllers/users_controller.rb4
-rw-r--r--web/app/helpers/application_helper.rb17
-rw-r--r--web/app/views/layouts/application.haml18
-rw-r--r--web/app/views/main/index.haml3
-rw-r--r--web/app/views/shared/._tweet.haml.swpbin12288 -> 12288 bytes
-rw-r--r--web/app/views/shared/_tweet.haml51
-rw-r--r--web/log/development.log30
-rw-r--r--web/log/production.log0
13 files changed, 166 insertions, 89 deletions
diff --git a/.gitignore b/.gitignore
index eb96b5a..28797c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,8 +11,8 @@
web/db/*.sqlite3
# Ignore all logfiles and tempfiles.
-log/*.log
-tmp
+web/log/*.log
+web/tmp
web/config/settings.local.yml
web/config/settings/*.local.yml
diff --git a/web/app/assets/stylesheets/_tweets.css.sass b/web/app/assets/stylesheets/_tweets.css.sass
new file mode 100644
index 0000000..47dd575
--- /dev/null
+++ b/web/app/assets/stylesheets/_tweets.css.sass
@@ -0,0 +1,75 @@
+.items
+ :width 572px
+ :margin 15px 0 15px 18px
+ .item
+ :margin 15px 0
+ .tweet
+ :overflow hidden
+ :background #ffffff
+ :border 1px solid #c1c5cb
+ :border-width 1px 0
+ //:border-radius 4px 4px 0 0
+ :padding 15px
+ .avatar
+ :width 60px
+ :float left
+ img
+ :width 48px
+ :height 48px
+ .tweet_content_fix
+ :float left
+ :width 1px
+ :height 85px
+ .tweet_content
+ :float left
+ :width 473px
+ .user
+ :font-weight bold
+ :color #666666
+ .name
+ :font-size 14px
+ .screen_name
+ :font-size 12px
+ .text
+ :font-size 18px
+ :line-height 25px
+ :padding 0 5px 15px
+ :word-wrap break-word
+ .meta
+ :color #666666
+ :font-size 12px
+ .created_at
+ :display block
+ :float left
+ .source
+ :display block
+ :float right
+ .stats
+ :clear both
+ //:border 1px solid #c1c5cb
+ //:border-width 0 1px 1px
+ //:border-radius 0 0 4px 4px
+ :padding 15px
+ //:background #edf0f4
+ .type_row
+ .info
+ :width 60px
+ :float left
+ .count,
+ .type
+ :color #666666
+ :display block
+ .count
+ :font-weight bold
+ :font-size 14px
+ .type
+ :font-size 10px
+ ul.users_row
+ :list-style none
+ :float left
+ li
+ :float left
+ img
+ :width 48px
+ :height 48px
+
diff --git a/web/app/assets/stylesheets/application.css.sass b/web/app/assets/stylesheets/application.css.sass
index cc6ec33..a54fea5 100644
--- a/web/app/assets/stylesheets/application.css.sass
+++ b/web/app/assets/stylesheets/application.css.sass
@@ -1,20 +1,16 @@
-.item
- :border-bottom 1px solid #999999
- .tweet
- :width 800px
- .icon
- :width 100px
- :float left
- .right
- :float left
- .meta
- .created_at
- :display block
- :float left
- .source
- :display block
- :float right
- .data
- :width 800px
- :clear both
+@import "tweets"
+
+*
+ :vertical-align baseline
+ :margin 0
+ :padding 0
+a
+ :text-decoration none
+ :color inherit
+.clearfix:after
+ :content "."
+ :visibility hidden
+ :display block
+ :height 0
+ :clear both
diff --git a/web/app/controllers/application_controller.rb b/web/app/controllers/application_controller.rb
index 80361c9..15abd84 100644
--- a/web/app/controllers/application_controller.rb
+++ b/web/app/controllers/application_controller.rb
@@ -7,13 +7,21 @@ class ApplicationController < ActionController::Base
end
def get_page_number(params)
- if params[:page]
- i = params[:page].to_i
- if i && i > 0
+ if params[:page] && i = params[:page].to_i
+ if i > 0
return i
- else
- return 1
end
end
+ return 1
+ end
+
+ def get_user_cache(items)
+ Hash[
+ User.find(@items
+ .map{|m| m.favorites.map{|u| u.user_id} + m.retweets.map{|u| u.user_id}}
+ .flatten
+ .uniq)
+ .map{|m| [m.id, m]}
+ ]
end
end
diff --git a/web/app/controllers/sessions_controller.rb b/web/app/controllers/sessions_controller.rb
index 9155529..a93fb6a 100644
--- a/web/app/controllers/sessions_controller.rb
+++ b/web/app/controllers/sessions_controller.rb
@@ -5,6 +5,7 @@ class SessionsController < ApplicationController
user.update_attributes(:oauth_token => auth["credentials"]["token"],
:oauth_token_secret => auth["credentials"]["secret"])
session[:user_id] = user.id
+ session[:screen_name] = auth["info"]["nickname"]
EM.defer do
EM.connect("127.0.0.1", Settings.worker_port) do |client|
def client.post_init
diff --git a/web/app/controllers/users_controller.rb b/web/app/controllers/users_controller.rb
index 369fff6..57e5474 100644
--- a/web/app/controllers/users_controller.rb
+++ b/web/app/controllers/users_controller.rb
@@ -11,6 +11,7 @@ class UsersController < ApplicationController
else
@items = []
end
+ @user_cache = get_user_cache(@items)
end
def recent
@@ -25,6 +26,7 @@ class UsersController < ApplicationController
else
@items = []
end
+ @user_cache = get_user_cache(@items)
end
def timeline
@@ -38,6 +40,7 @@ class UsersController < ApplicationController
else
@items = []
end
+ @user_cache = get_user_cache(@items)
end
def my
@@ -63,6 +66,7 @@ class UsersController < ApplicationController
else
@items = []
end
+ @user_cache = get_user_cache(@items)
end
def info
diff --git a/web/app/helpers/application_helper.rb b/web/app/helpers/application_helper.rb
index a01f54a..4a7f55f 100644
--- a/web/app/helpers/application_helper.rb
+++ b/web/app/helpers/application_helper.rb
@@ -1,6 +1,8 @@
+require "time"
+
module ApplicationHelper
def format_tweet_created_at(dt)
- dt.to_s
+ dt.to_time.localtime("+09:00").strftime("%Y-%m-%d %H:%M:%S")
end
def format_tweet_text(text)
@@ -8,5 +10,18 @@ module ApplicationHelper
.gsub(/<url:((?:https?|ftp).+?):(.+?)>/){link_to($2, $1, :target => "_blank")}
.gsub(/<hashtag:(.+?)>/){link_to("##{$1}", "https://twitter.com/search?q=%23#{$1}")}
.gsub(/<mention:(.+?)>/){link_to("@#{$1}", "/#{$1}")}
+ .gsub(/\r\n|\r|\n/, "<br />")
+ end
+
+ def format_source_text(text)
+ text
+ end
+
+ def status_url(tweet)
+ "https://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id}"
+ end
+
+ def user_url(user)
+ "/#{user.screen_name}"
end
end
diff --git a/web/app/views/layouts/application.haml b/web/app/views/layouts/application.haml
index 524a715..46ca718 100644
--- a/web/app/views/layouts/application.haml
+++ b/web/app/views/layouts/application.haml
@@ -1,8 +1,20 @@
!!! xml
%html{xmlns: "http://www.w3.org/1999/xhtml"}
%head
- %title Aclog
+ %title= @title
= stylesheet_link_tag "application"
- /= javascript_include_tag "application"
%body
- = yield
+ .container
+ .left
+ %h1><
+ Aclog
+ %span.version beta
+ %div
+ - if session[:screen_name]
+ %span= link_to "@#{session[:screen_name]}", :controller => "users", :action => "best", :screen_name => session[:screen_name]
+ %span= link_to "Logout", :controller => "sessions", :action => "destroy"
+ - else
+ %span= link_to "Login", "/i/login"
+ .body
+ %h2= @title
+ = yield
diff --git a/web/app/views/main/index.haml b/web/app/views/main/index.haml
index e72b8b7..1a8c52d 100644
--- a/web/app/views/main/index.haml
+++ b/web/app/views/main/index.haml
@@ -1,2 +1 @@
-%a{:href => "/i/login"}
- Login
+(´へεへ`*) < トップページだよ〜〜
diff --git a/web/app/views/shared/._tweet.haml.swp b/web/app/views/shared/._tweet.haml.swp
index 9c6ebb8..a497f1b 100644
--- a/web/app/views/shared/._tweet.haml.swp
+++ b/web/app/views/shared/._tweet.haml.swp
Binary files differ
diff --git a/web/app/views/shared/_tweet.haml b/web/app/views/shared/_tweet.haml
index db10dcf..1d18b70 100644
--- a/web/app/views/shared/_tweet.haml
+++ b/web/app/views/shared/_tweet.haml
@@ -1,35 +1,32 @@
.item
.tweet
- .icon
- %img{:src => item.user.profile_image_url}
- .right
+ .avatar
+ %a{href: user_url(item.user)}
+ %img{src: item.user.profile_image_url}
+ .tweet_content_fix
+ .tweet_content
.user
- %span
- = item.user.name
- %span
- = "@#{item.user.screen_name}"
+ %span.name
+ = link_to item.user.name, user_url(item.user)
+ %span.screen_name
+ = link_to "@#{item.user.screen_name}", user_url(item.user)
.text
= raw format_tweet_text(item.text)
- .meta
+ .meta.clearfix
%span.created_at
- = format_tweet_created_at(item.tweeted_at)
+ = link_to format_tweet_created_at(item.tweeted_at), status_url(item)
%span.source
- = raw item.source
- .data
- .favorites
- FAV
- - item.favorites.map{|m| m.user}.each_slice(10) do |row|
- .users_row
- - row.each do |u|
- %a{:href => "/#{u.screen_name}", :title => u.screen_name}
- %img{:src => u.profile_image_url}
- .retweets
- RETWEET
- - item.retweets.map{|m| m.user}.each_slice(10) do |row|
- .users_row
- - row.each do |u|
- %a{:href => "/#{u.screen_name}", :title => u.screen_name}
- %img{:src => u.profile_image_url}
-
-
+ = raw format_source_text(item.source)
+ .stats
+ - [["FAVS", item.favorites], ["RETWEETS", item.retweets]].each do |type, data|
+ .type_row.clearfix
+ .info
+ %span.count= data.length
+ %span.type= type
+ - data.map{|m| @user_cache[m.user_id]}.each_slice(10) do |row|
+ %ul.users_row.clearfix
+ - row.each do |u|
+ %li
+ %a{href: user_url(u)}><
+ %img{src: u.profile_image_url}
diff --git a/web/log/development.log b/web/log/development.log
deleted file mode 100644
index b9db4b6..0000000
--- a/web/log/development.log
+++ /dev/null
@@ -1,30 +0,0 @@
-  (275.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
-  (255.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
-Migrating to CreateAccounts (20130225123010)
-  (0.1ms) begin transaction
-  (0.6ms) CREATE TABLE "accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "oauth_token" varchar(255), "oauth_token_secret" varchar(255), "created_at" datetime, "updated_at" datetime) 
- SQL (2.4ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130225123010"]]
-  (280.2ms) commit transaction
-Migrating to CreateUsers (20130226145932)
-  (0.2ms) begin transaction
-  (0.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "screen_name" varchar(255), "name" varchar(255), "profile_image_url" text, "created_at" datetime, "updated_at" datetime) 
-  (0.1ms) CREATE INDEX "index_users_on_screen_name" ON "users" ("screen_name")
- SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130226145932"]]
-  (284.4ms) commit transaction
-Migrating to CreateTweets (20130226150329)
-  (0.2ms) begin transaction
-  (0.5ms) CREATE TABLE "tweets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "text" text, "source" text, "user_id" integer(8), "tweeted_at" datetime, "favorites_count" integer, "retweets_count" integer)
- SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130226150329"]]
-  (284.5ms) commit transaction
-Migrating to CreateFavorites (20130226150829)
-  (0.1ms) begin transaction
-  (0.2ms) CREATE TABLE "favorites" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tweet_id" integer(8), "user_id" integer(8))
- SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130226150829"]]
-  (254.0ms) commit transaction
-Migrating to CreateRetweets (20130226151042)
-  (0.1ms) begin transaction
-  (0.5ms) CREATE TABLE "retweets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tweet_id" integer(8), "user_id" integer(8))
- SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130226151042"]]
-  (262.1ms) commit transaction
- ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
diff --git a/web/log/production.log b/web/log/production.log
deleted file mode 100644
index e69de29..0000000
--- a/web/log/production.log
+++ /dev/null