Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rendezvous
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
rendezvous
Commits
863ec620
Commit
863ec620
authored
Jul 19, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add footprint
parent
56fc42f3
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
157 additions
and
31 deletions
+157
-31
app/controllers/posts_controller.rb
+3
-0
app/decorators/post_decorator.rb
+8
-0
app/models/footprint.rb
+4
-0
app/models/post.rb
+9
-0
app/models/user.rb
+8
-1
app/views/flow/show.html.slim
+0
-2
app/views/posts/_large_item.html.slim
+7
-6
app/views/posts/show.html.slim
+48
-18
app/views/templates/show.html.slim
+8
-3
db/migrate/20140719132802_create_footprints.rb
+13
-0
db/schema.rb
+11
-1
spec/controllers/posts_controller_spec.rb
+33
-0
spec/models/footprint_spec.rb
+5
-0
No files found.
app/controllers/posts_controller.rb
View file @
863ec620
...
...
@@ -8,6 +8,9 @@ class PostsController < ApplicationController
# GET /posts/1
# GET /posts/1.json
def
show
current_user
.
visit_post!
(
@post
)
@post
.
tags
.
each
do
|
_tag
|
add_breadcrumb
(
"#
#{
_tag
.
name
}
"
,
_tag
.
decorate
.
show_path
)
end
...
...
app/decorators/post_decorator.rb
View file @
863ec620
...
...
@@ -27,6 +27,14 @@ class PostDecorator < Draper::Decorator
end
end
def
created_date
model
.
created_at
.
strftime
(
'%Y-%m-%d'
)
end
def
updated_date
model
.
updated_at
.
strftime
(
'%Y-%m-%d'
)
end
def
display_specified_date
if
model
.
specified_date
model
.
specified_date
.
strftime
(
'%Y-%m-%d'
)
...
...
app/models/footprint.rb
0 → 100644
View file @
863ec620
class
Footprint
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:post
end
app/models/post.rb
View file @
863ec620
...
...
@@ -20,6 +20,7 @@ class Post < ActiveRecord::Base
has_many
:tags
,
through: :post_tags
belongs_to
:author
,
class_name:
'User'
has_many
:comments
has_many
:footprints
# default_scope { where(is_draft: false).order(:updated_at => :desc) }
...
...
@@ -68,6 +69,10 @@ class Post < ActiveRecord::Base
order
(
updated_at: :desc
).
limit
(
limit
)
}
######################################################################
# Instance method
######################################################################
# generate forked post (not saved)
def
generate_fork
(
user
)
...
...
@@ -91,4 +96,8 @@ class Post < ActiveRecord::Base
def
body_for_slideshow
self
.
body
.
gsub
(
/^#/
,
"---
\n\n
#"
)
end
def
visited_user_count
footprints
.
select
(
:user_id
).
uniq
.
count
end
end
app/models/user.rb
View file @
863ec620
...
...
@@ -38,6 +38,7 @@ class User < ActiveRecord::Base
has_many
:posts
,
foreign_key:
'author_id'
has_many
:comments
,
foreign_key:
'author_id'
has_many
:notifications
has_many
:footprints
######################################################################
# scope
...
...
@@ -80,6 +81,9 @@ class User < ActiveRecord::Base
user
end
######################################################################
# instance methods
######################################################################
# check if google oauth token is expired
def
google_oauth_token_expired?
...
...
@@ -111,5 +115,8 @@ class User < ActiveRecord::Base
notifications
.
create
(
detail_path:
detail_path
,
body:
body
,
is_read:
false
)
end
# record footprint
def
visit_post!
(
post
)
footprints
.
create!
(
post:
post
)
end
end
app/views/flow/show.html.slim
View file @
863ec620
...
...
@@ -27,5 +27,3 @@
a
.list-group-item
data-tag-id
=
tag
.id
href
=
search_path
(
q:
"#
#{
tag
.
name
}
"
)
=
tag
.
name
span
.badge
=
tag
.
posts_count
app/views/posts/_large_item.html.slim
View file @
863ec620
...
...
@@ -20,14 +20,15 @@ a.list-group-item.post-list.mod-hover-hidden data-post-id=post.id href=post_path
|
.col-xs-4
small
.pull-right
span
.glyphicon.glyphicon-time
span
.mod-hover-hidden-item
|
読了時間
span
.glyphicon.glyphicon-time
title
=
"読了時間"
|
#{
post
.
read_time
}
span
.glyphicon.glyphicon-comment
span
.mod-hover-hidden-item
|
コメント
span
.glyphicon.glyphicon-comment
title
=
"コメント"
|
#{
post
.
comments
.
count
}
span
.glyphicon.glyphicon-eye-open
title
=
"閲覧者数"
|
#{
post
.
visited_user_count
}
.row
.col-xs-12
small
.text-shadow
...
...
app/views/posts/show.html.slim
View file @
863ec620
=
render_breadcrumbs
.row
.panel.panel-default
.col-xs-9
.panel.panel-info
.panel-heading
h3
.panel-title
a
href
=
post_path
(
@post
)
=
@post
.
title
ul
.list-group
li
.list-group-item
-
@post
.
tags
.
each
do
|
tag
|
span
.label.label-success
a
href
=
tag
.decorate.show_path
|
#
#{
tag
.
name
}
|
span
.label.label-info
a
href
=
(
search_path
(
q:
"@
#{
@post
.
author
.
name
}
"
)
)
|
@
#{
@post
.
author
.
name
}
|
span
.label.label-danger
a
href
=
(
search_path
(
q:
"date:
#{
@post
.
display_date
}
"
)
)
=
@post
.
display_date
.btn-group.pull-right
style
=
(
"margin: -7px -12px 0 0;"
)
.panel-body.viewer.github
=
h_application_format_markdown
(
@post
.
body
)
.col-xs-3
p
.btn-group
a
.btn.btn-primary
href
=
edit_post_path
(
@post
)
|
編集
span
.glyphicon.glyphicon-pencil
button
.btn.btn-default.dropdown-toggle
data-toggle
=
"dropdown"
type
=
"button"
span
.caret
...
...
@@ -35,8 +28,45 @@
a
data-target
=
"#myModal"
data-toggle
=
"modal"
href
=
"#"
Mail
to
...
li
.divider
li
=
link_to
'Delete'
,
post_path
(
@post
),
method: :delete
,
data:
{
confirm:
'Are you sure?'
}
.panel-body.viewer.github
=
h_application_format_markdown
(
@post
.
body
)
.well
dl
dt
作成者
dd
a
href
=
(
search_path
(
q:
"@
#{
@post
.
author
.
name
}
"
)
)
|
@
#{
@post
.
author
.
name
}
dt
タグ
dd
-
@post
.
tags
.
each
do
|
tag
|
span
.label.label-success
a
href
=
tag
.decorate.show_path
|
#
#{
tag
.
name
}
|
dt
指定日
dd
a
href
=
(
search_path
(
q:
"date:
#{
@post
.
display_date
}
"
)
)
=
@post
.
display_date
dt
作成日
dd
=
@post
.
created_date
dt
最終更新日
dd
=
@post
.
updated_date
dt
閲覧者数
dd
=
@post
.
visited_user_count
dt
コメント数
dd
=
@post
.
comments
.
count
.row
.panel.panel-success
.panel-heading
h3
.panel-title
Comments
...
...
app/views/templates/show.html.slim
View file @
863ec620
h1
テンプレートから作成
/! view:templates/show
.row
.panel.panel-info
h1
|
Templates
small
-
テンプレートから作成
.panel.panel-info
.panel-heading
span
.glyphicon.glyphicon-info-sign
|
テンプレートの使い方
...
...
@@ -10,7 +15,7 @@ h1 テンプレートから作成
li
「template」
というタグをつけた投稿はこのページに現れます
li
コピーすることで同じフォーマットの文章が簡単に書けます
.list-group
.list-group
-
if
template_tag
=
Tag
.
find_by
(
name:
'template'
)
-
template_tag
.
posts
.
decorate
.
each
do
|
_post
|
=
render
partial:
'post'
,
locals:
{
post:
_post
}
...
...
db/migrate/20140719132802_create_footprints.rb
0 → 100644
View file @
863ec620
class
CreateFootprints
<
ActiveRecord
::
Migration
def
change
create_table
:footprints
do
|
t
|
t
.
integer
:user_id
,
null:
false
t
.
integer
:post_id
,
null:
false
t
.
timestamps
end
add_index
:footprints
,
[
:user_id
,
:post_id
]
add_index
:footprints
,
:post_id
end
end
db/schema.rb
View file @
863ec620
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20140
501045300
)
do
ActiveRecord
::
Schema
.
define
(
version:
20140
719132802
)
do
create_table
"comments"
,
force:
true
do
|
t
|
t
.
integer
"author_id"
...
...
@@ -24,6 +24,16 @@ ActiveRecord::Schema.define(version: 20140501045300) do
add_index
"comments"
,
[
"author_id"
,
"updated_at"
],
name:
"index_comments_on_author_id_and_updated_at"
,
using: :btree
add_index
"comments"
,
[
"post_id"
,
"updated_at"
],
name:
"index_comments_on_post_id_and_updated_at"
,
using: :btree
create_table
"footprints"
,
force:
true
do
|
t
|
t
.
integer
"user_id"
,
null:
false
t
.
integer
"post_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
add_index
"footprints"
,
[
"post_id"
],
name:
"index_footprints_on_post_id"
,
using: :btree
add_index
"footprints"
,
[
"user_id"
,
"post_id"
],
name:
"index_footprints_on_user_id_and_post_id"
,
using: :btree
create_table
"notifications"
,
force:
true
do
|
t
|
t
.
integer
"user_id"
t
.
datetime
"read_at"
...
...
spec/controllers/posts_controller_spec.rb
0 → 100644
View file @
863ec620
require
'rails_helper'
describe
PostsController
,
type: :controller
do
let
(
:post
)
{
FactoryGirl
.
create
(
:post
)
}
describe
"GET 'show' without login"
do
it
"returns http redirect"
do
get
'show'
,
id:
post
.
id
expect
(
response
).
to
redirect_to
(
'/'
)
end
end
describe
"GET 'show' with login"
do
let
(
:alice
)
{
FactoryGirl
.
create
(
:alice
)
}
it
"returns http success"
do
sign_in
FactoryGirl
.
create
(
:alice
)
get
'show'
,
id:
post
.
id
expect
(
response
).
to
be_success
end
it
"returns http success"
do
sign_in
alice
get
'show'
,
id:
post
.
id
expect
(
Footprint
.
where
(
user_id:
alice
.
id
,
post_id:
post
.
id
)).
to
exist
end
end
end
spec/models/footprint_spec.rb
0 → 100644
View file @
863ec620
require
'rails_helper'
RSpec
.
describe
Footprint
,
:type
=>
:model
do
pending
"add some examples to (or delete)
#{
__FILE__
}
"
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment