Skip to content

Commit

Permalink
add archive in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
twata701 committed Feb 20, 2014
1 parent eb94cbc commit 2922e29
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,5 @@ config/secrets.yml
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

nbproject/*
9 changes: 9 additions & 0 deletions app/controllers/tweets_controller.rb
Expand Up @@ -3,6 +3,7 @@
class TweetsController < ApplicationController
before_action :set_tweet, only: [:show, :edit, :update, :destroy]
before_action :check_user
before_action :make_archive

# GET /tweets
# GET /tweets.json
Expand Down Expand Up @@ -100,4 +101,12 @@ def check_user
end
end

# ユーザがログインしていなければ、ホームにリダイレクト
def make_archive
@user = current_user
@archives = @user.tweet.group("strftime('%Y%m', tweets.timestamp)")
.order("strftime('%Y%m', tweets.timestamp) desc")
.count
end

end
7 changes: 7 additions & 0 deletions app/helpers/tweets_helper.rb
@@ -1,2 +1,9 @@
# coding: utf-8
module TweetsHelper
def ymconv(yyyymm,cnt)
yyyy = yyyymm[0,4]
mm = yyyymm[4,2]

return yyyy + "年" + mm + "月 (" + cnt + ")"
end
end
81 changes: 81 additions & 0 deletions app/views/layouts/home.html.erb
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Twice" %></title>
<%= csrf_meta_tags %>

<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]-->

<%= stylesheet_link_tag "application", :media => "all" %>

<!-- For third-generation iPad with high-resolution Retina display: -->
<!-- Size should be 144 x 144 pixels -->
<%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %>

<!-- For iPhone with high-resolution Retina display: -->
<!-- Size should be 114 x 114 pixels -->
<%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %>

<!-- For first- and second-generation iPad: -->
<!-- Size should be 72 x 72 pixels -->
<%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %>

<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<!-- Size should be 57 x 57 pixels -->
<%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>

<!-- For all other devices -->
<!-- Size should be 32 x 32 pixels -->
<%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
<%= javascript_include_tag "application" %>
</head>
<body>

<div class="navbar navbar-fluid-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Twice</a>
<div class="container-fluid nav-collapse">
<ul class="nav">
<li><%= link_to "Link1", "/path1" %></li>
<li><%= link_to "Link2", "/path2" %></li>
<li><%= link_to "Link3", "/path3" %></li>
<% if user_signed_in? %>
<li><%= link_to "ログアウト", (destroy_user_session_path) %></li>
<% else %>
<li><%= link_to "ログイン", (user_omniauth_authorize_path :twitter) %></li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<%= bootstrap_flash %>
<%= yield %>
</div>
</div><!--/row-->

<footer>
<p>&copy; Company 2014</p>
</footer>

</div> <!-- /container -->

</body>
</html>
91 changes: 91 additions & 0 deletions app/views/layouts/tweets.html.erb
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Twice" %></title>
<%= csrf_meta_tags %>

<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]-->

<%= stylesheet_link_tag "application", :media => "all" %>

<!-- For third-generation iPad with high-resolution Retina display: -->
<!-- Size should be 144 x 144 pixels -->
<%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %>

<!-- For iPhone with high-resolution Retina display: -->
<!-- Size should be 114 x 114 pixels -->
<%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %>

<!-- For first- and second-generation iPad: -->
<!-- Size should be 72 x 72 pixels -->
<%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %>

<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<!-- Size should be 57 x 57 pixels -->
<%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>

<!-- For all other devices -->
<!-- Size should be 32 x 32 pixels -->
<%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
<%= javascript_include_tag "application" %>
</head>
<body>

<div class="navbar navbar-fluid-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Twice</a>
<div class="container-fluid nav-collapse">
<ul class="nav">
<li><%= link_to "Link1", "/path1" %></li>
<li><%= link_to "Link2", "/path2" %></li>
<li><%= link_to "Link3", "/path3" %></li>
<% if user_signed_in? %>
<li><%= link_to "ログアウト", (destroy_user_session_path) %></li>
<% else %>
<li><%= link_to "ログイン", (user_omniauth_authorize_path :twitter) %></li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Archives</li>
<% @archives.each do |yyyymm, count| %>
<li><%= ymconv(yyyymm, count.to_s) %><li>
<% end %>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<%= bootstrap_flash %>
<%= yield %>
</div>
</div><!--/row-->

<footer>
<p>&copy; Company 2014</p>
</footer>

</div> <!-- /container -->

</body>
</html>
7 changes: 6 additions & 1 deletion nbproject/private/private.xml
Expand Up @@ -11,6 +11,11 @@
</file>
</editor-bookmarks>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/Users/takahashi/dev/twice/app/controllers/application_controller.rb</file>
<file>file:/Users/takahashi/dev/twice/app/models/tweet.rb</file>
<file>file:/Users/takahashi/dev/twice/app/models/user.rb</file>
<file>file:/Users/takahashi/dev/twice/app/controllers/tweets_controller.rb</file>
</group>
</open-files>
</project-private>

0 comments on commit 2922e29

Please sign in to comment.