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
3a981ef7
Commit
3a981ef7
authored
Nov 02, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conform to rubocop
parent
cc5dc7dc
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
102 additions
and
95 deletions
+102
-95
.rubocop.yml
+8
-0
.travis.yml
+1
-1
app/controllers/apis_controller.rb
+1
-1
app/controllers/application_controller.rb
+5
-5
app/controllers/posts_controller.rb
+8
-8
app/controllers/tags_controller.rb
+1
-1
app/decorators/post_decorator.rb
+3
-3
app/decorators/posts_decorator.rb
+2
-2
app/decorators/tag_decorator.rb
+9
-9
app/decorators/tags_decorator.rb
+7
-7
app/helpers/application_helper.rb
+0
-5
app/models/markdown_renderer.rb
+2
-1
app/models/notification.rb
+4
-4
app/models/post.rb
+25
-25
app/models/tag.rb
+4
-4
app/models/user.rb
+12
-12
lib/tasks/migrations.rake
+3
-3
spec/models/markdown_renderer_spec.rb
+5
-2
spec/models/tag_spec.rb
+2
-2
No files found.
.rubocop.yml
View file @
3a981ef7
...
...
@@ -47,3 +47,11 @@ Style/RescueModifier:
# and/orを許容
Style/AndOr
:
Enabled
:
false
# ABCチェックを無効
Metrics/AbcSize
:
Enabled
:
false
# ???
Style/RaiseArgs
:
Enabled
:
false
.travis.yml
View file @
3a981ef7
...
...
@@ -22,4 +22,4 @@ before_script:
-
mysql -e 'CREATE DATABASE rendezvous_test;'
after_script
:
-
ruby script/travis/bundle_cache.rb
script
:
bundle exec rake db:create db:test:load spec teaspoon
script
:
bundle exec rake db:create db:test:load spec teaspoon
; bundle exec rubocop
app/controllers/apis_controller.rb
View file @
3a981ef7
...
...
@@ -48,7 +48,7 @@ class ApisController < ApplicationController
end
def
user_mention
name_list
=
User
.
search
(
params
[
:q
]).
map
{
|
_user
|
"
#{
_user
.
nickname
}
[
#{
_
user
.
name
}
]"
}
name_list
=
User
.
search
(
params
[
:q
]).
map
{
|
user
|
"
#{
user
.
nickname
}
[
#{
user
.
name
}
]"
}
render
json:
name_list
end
...
...
app/controllers/application_controller.rb
View file @
3a981ef7
...
...
@@ -8,11 +8,11 @@ class ApplicationController < ActionController::Base
before_action
:redirect_unless_signed_in
def
redirect_unless_signed_in
unless
user_signed_in?
flash
[
:alert
]
=
'You need Login!'
session
[
:login_redirect_to
]
=
request
.
url
redirect_to
root_path
end
return
if
user_signed_in?
flash
[
:alert
]
=
'You need Login!'
session
[
:login_redirect_to
]
=
request
.
url
redirect_to
root_path
end
def
after_sign_in_path_for
(
resource
)
...
...
app/controllers/posts_controller.rb
View file @
3a981ef7
...
...
@@ -10,8 +10,8 @@ class PostsController < ApplicationController
def
show
current_user
.
visit_post!
(
@post
)
@post
.
tags
.
each
do
|
_
tag
|
add_breadcrumb
(
"#
#{
_tag
.
name
}
"
,
_
tag
.
decorate
.
show_path
)
@post
.
tags
.
each
do
|
tag
|
add_breadcrumb
(
"#
#{
tag
.
name
}
"
,
tag
.
decorate
.
show_path
)
end
add_breadcrumb
(
@post
.
title
)
end
...
...
@@ -131,17 +131,17 @@ class PostsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def
post_params
@post_params
||=
begin
_
param_hash
=
params
.
require
(
:post
).
permit
(
:title
,
:body
,
:tags
,
:is_draft
,
:specified_date
).
to_hash
param_hash
=
params
.
require
(
:post
).
permit
(
:title
,
:body
,
:tags
,
:is_draft
,
:specified_date
).
to_hash
# tags_text == 'Javascript,Ruby'
tags_text
=
_
param_hash
.
delete
(
'tags'
)
tags_text
=
param_hash
.
delete
(
'tags'
)
tags
=
tags_text
.
split
(
','
).
map
do
|
_
tag_name
|
Tag
.
find_or_create_by
(
name:
_
tag_name
)
tags
=
tags_text
.
split
(
','
).
map
do
|
tag_name
|
Tag
.
find_or_create_by
(
name:
tag_name
)
end
_
param_hash
[
'tag_ids'
]
=
tags
.
map
(
&
:id
)
param_hash
[
'tag_ids'
]
=
tags
.
map
(
&
:id
)
_
param_hash
param_hash
end
end
...
...
app/controllers/tags_controller.rb
View file @
3a981ef7
...
...
@@ -66,7 +66,7 @@ class TagsController < ApplicationController
def
move_to
@move_to_tag
=
Tag
.
find_by
(
name:
params
[
:move_to_name
])
or
fail
ActiveRecord
::
RecordNotFound
@tag
.
set_parent!
(
@move_to_tag
)
@tag
.
parent_tag
=
@move_to_tag
flash
[
:notice
]
=
"「
#{
@tag
.
name
}
」は「
#{
@move_to_tag
.
name
}
」の下に移動しました"
...
...
app/decorators/post_decorator.rb
View file @
3a981ef7
...
...
@@ -12,12 +12,12 @@ class PostDecorator < Draper::Decorator
# 読了時間
# 500文字/1分換算
def
read_time
_
time_min
=
model
.
body
.
length
/
500
case
_
time_min
time_min
=
model
.
body
.
length
/
500
case
time_min
when
0
'< 1 min.'
when
1
..
10
"
#{
_
time_min
}
min."
"
#{
time_min
}
min."
else
'> 10 min.'
end
...
...
app/decorators/posts_decorator.rb
View file @
3a981ef7
class
PostsDecorator
<
Draper
::
CollectionDecorator
def
related_tags
_
tags
=
map
(
&
:tags
).
flatten
.
uniq
tags
=
map
(
&
:tags
).
flatten
.
uniq
TagDecorator
.
decorate_collection
(
_
tags
)
TagDecorator
.
decorate_collection
(
tags
)
end
def
related_authors
...
...
app/decorators/tag_decorator.rb
View file @
3a981ef7
...
...
@@ -28,22 +28,22 @@ class TagDecorator < Draper::Decorator
# tagをtree viewで表示する
def
tree_view_node
_
html
=
''
html
=
''
_
html
+=
%(
html
+=
%(
<a href="#{ show_path }" data-name="#{model.name}">
#{model.name} <span class="badge">#{model.posts.size}</span>
</a>
)
_
html
+=
'<ul>'
model
.
children
.
each
do
|
_
child
|
_
html
+=
'<li>'
_html
<<
_
child
.
decorate
.
tree_view_node
_
html
+=
'</li>'
html
+=
'<ul>'
model
.
children
.
each
do
|
child
|
html
+=
'<li>'
html
<<
child
.
decorate
.
tree_view_node
html
+=
'</li>'
end
_
html
+=
'</ul>'
html
+=
'</ul>'
_
html
.
html_safe
html
.
html_safe
end
end
app/decorators/tags_decorator.rb
View file @
3a981ef7
class
TagsDecorator
<
Draper
::
CollectionDecorator
# tagをtree viewで表示する
def
tree_view
_
html
=
''
_
html
+=
%(
html
=
''
html
+=
%(
<ul class="mod-tag-tree">
<input type="search" class="mod-tag-tree-filter form-control" placeholder="filter...">
)
each
do
|
_
node
|
_
html
+=
%(
each
do
|
node
|
html
+=
%(
<li>
#{
_
node.decorate.tree_view_node}
#{node.decorate.tree_view_node}
</li>
)
end
_
html
+=
'</ul>'
html
+=
'</ul>'
_
html
.
html_safe
html
.
html_safe
end
end
app/helpers/application_helper.rb
View file @
3a981ef7
module
ApplicationHelper
def
h_application_format_markdown
(
text
)
fail
'deplicated error'
text
=
GitHub
::
Markdown
.
render_gfm
(
text
)
text
.
html_safe
end
end
app/models/markdown_renderer.rb
View file @
3a981ef7
...
...
@@ -11,7 +11,8 @@ class MarkdownRenderer
text
=
@text
.
gsub
(
/!slide!\(([^\)]+)\)/
)
do
|
_
|
slide_urls
<<
%(
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/##{Regexp.last_match[1]}" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe style="text-align:center;" src="/ViewerJS/##{Regexp.last_match[1]}"
width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>
)
"%%slide:
#{
slide_urls
.
size
-
1
}
%%"
...
...
app/models/notification.rb
View file @
3a981ef7
...
...
@@ -19,13 +19,13 @@ class Notification < ActiveRecord::Base
# Named scope
######################################################################
scope
:unread
,
->
{
scope
:unread
,
(
lambda
do
where
(
is_read:
false
)
}
end
)
scope
:recent
,
->
{
scope
:recent
,
(
lambda
do
where
(
arel_table
[
:created_at
].
gt
7
.
day
.
ago
)
}
end
)
######################################################################
# Instance method
...
...
app/models/post.rb
View file @
3a981ef7
...
...
@@ -47,40 +47,40 @@ class Post < ActiveRecord::Base
# Named scope
######################################################################
scope
:search
,
(
lambda
do
|
query
|
_
where_list
=
includes
(
:author
,
:tags
).
order
(
updated_at: :desc
)
where_list
=
includes
(
:author
,
:tags
).
order
(
updated_at: :desc
)
# Convert spaces to one space.
query_list
=
query
.
split
(
/[\s ]+/
)
query_list
.
each
do
|
_query
|
case
_query
query_list
.
each
do
|
where
_query
|
case
where
_query
when
/\Aid:(.+)/
_where_list
=
_
where_list
.
where
(
id:
Regexp
.
last_match
[
1
])
where_list
=
where_list
.
where
(
id:
Regexp
.
last_match
[
1
])
when
/\Atitle:(.+)/
_where_list
=
_
where_list
.
where
(
'posts.title LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
where_list
=
where_list
.
where
(
'posts.title LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
when
/\Abody:(.+)/
_where_list
=
_
where_list
.
where
(
'posts.body LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
where_list
=
where_list
.
where
(
'posts.body LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
when
/\A@(.+)/
_where_list
=
_
where_list
.
where
(
users:
{
nickname:
Regexp
.
last_match
[
1
]
})
where_list
=
where_list
.
where
(
users:
{
nickname:
Regexp
.
last_match
[
1
]
})
when
/\A#(.+)/
_where_list
=
_
where_list
.
where
(
tags:
{
name:
Regexp
.
last_match
[
1
]
})
where_list
=
where_list
.
where
(
tags:
{
name:
Regexp
.
last_match
[
1
]
})
when
/\Adate:(\d+)-(\d+)-(\d+)/
_
date
=
Time
.
new
(
Regexp
.
last_match
[
1
],
Regexp
.
last_match
[
2
],
Regexp
.
last_match
[
3
])
_where_list
=
_where_list
.
where
(
'posts.updated_at > ? AND posts.updated_at < ?'
,
_date
,
_
date
+
1
.
day
)
date
=
Time
.
new
(
Regexp
.
last_match
[
1
],
Regexp
.
last_match
[
2
],
Regexp
.
last_match
[
3
])
where_list
=
where_list
.
where
(
'posts.updated_at > ? AND posts.updated_at < ?'
,
date
,
date
+
1
.
day
)
when
/\Adraft:1/
_where_list
=
_
where_list
.
where
(
is_draft:
true
)
where_list
=
where_list
.
where
(
is_draft:
true
)
else
_where_list
=
_where_list
.
where
(
'posts.title LIKE ? OR posts.body LIKE ?'
,
"%
#{
_query
}
%"
,
"%
#{
_query
}
%"
)
where_list
=
where_list
.
where
(
'posts.title LIKE ? OR posts.body LIKE ?'
,
"%
#{
where_query
}
%"
,
"%
#{
where
_query
}
%"
)
end
end
_
where_list
where_list
end
)
# 最新のPostを取得
scope
:recent
,
->
(
limit
=
10
)
{
scope
:recent
,
(
lambda
do
|
limit
=
10
|
order
(
updated_at: :desc
).
limit
(
limit
)
}
end
)
######################################################################
# Instance method
...
...
@@ -89,19 +89,19 @@ class Post < ActiveRecord::Base
# generate forked post (not saved)
def
generate_fork
(
user
)
# `id`以外をコピーする
_
forked_post
=
Post
.
new
(
attributes
.
except
(
'id'
))
forked_post
=
Post
.
new
(
attributes
.
except
(
'id'
))
# `%name`をユーザー名に置換
_forked_post
.
title
=
_
forked_post
.
title
.
gsub
(
/%name/
,
user
.
name
)
forked_post
.
title
=
forked_post
.
title
.
gsub
(
/%name/
,
user
.
name
)
# `%Y`などを日付に変換
_forked_post
.
title
=
Time
.
now
.
strftime
(
_
forked_post
.
title
)
# TODO
_forked_post
.
title
=
_
forked_post
.
title
forked_post
.
title
=
Time
.
now
.
strftime
(
forked_post
.
title
)
# TODO
forked_post
.
title
=
forked_post
.
title
_
forked_post
.
tag_ids
=
tag_ids
_
forked_post
.
author
=
user
_
forked_post
.
specified_date
=
Date
.
today
forked_post
.
tag_ids
=
tag_ids
forked_post
.
author
=
user
forked_post
.
specified_date
=
Date
.
today
_
forked_post
forked_post
end
# slideshow用のbody
...
...
@@ -113,9 +113,9 @@ class Post < ActiveRecord::Base
footprints
.
select
(
:user_id
).
uniq
.
count
end
# FIXME:
# FIXME:
正常に動作しないため動作しないため一時的にメソッドを作成
# has_many :watchers, :through => :watches
#
正常に動作しないため動作しないため一時的にメソッドを作成
#
# def watchers
# watches.map { |watch| watch.watcher }
# end
...
...
app/models/tag.rb
View file @
3a981ef7
...
...
@@ -43,14 +43,14 @@ class Tag < ActiveRecord::Base
# 自分のタグに紐づくPostをすべて`other_tag`へ移動する
def
move_all_posts_to!
(
other_tag
)
posts
.
each
do
|
_post
|
_post
.
tags
.
delete
(
self
)
_post
.
tags
<<
other_tag
unless
_post
.
tags
.
include?
(
other_tag
)
posts
.
each
do
|
moving
_post
|
moving
_post
.
tags
.
delete
(
self
)
moving_post
.
tags
<<
other_tag
unless
moving
_post
.
tags
.
include?
(
other_tag
)
end
end
# 親タグを設定する
def
set_parent!
(
other_tag
)
def
parent_tag
=
(
other_tag
)
self
.
parent
=
other_tag
self
.
save!
end
...
...
app/models/user.rb
View file @
3a981ef7
...
...
@@ -46,12 +46,12 @@ class User < ActiveRecord::Base
######################################################################
# scope
######################################################################
scope
:post_recently
,
->
{
scope
:post_recently
,
(
lambda
do
User
.
joins
(
:posts
).
group
(
'id'
).
order
(
'posts.updated_at desc'
)
}
end
)
scope
:search
,
(
lambda
do
|
_
query
|
where
(
'name LIKE ? OR nickname LIKE ?'
,
"%
#{
_query
}
%"
,
"%
#{
_
query
}
%"
)
scope
:search
,
(
lambda
do
|
query
|
where
(
'name LIKE ? OR nickname LIKE ?'
,
"%
#{
query
}
%"
,
"%
#{
query
}
%"
)
end
)
######################################################################
...
...
@@ -66,11 +66,11 @@ class User < ActiveRecord::Base
# Device
def
self
.
find_for_google_oauth2
(
access_token
,
_signed_in_resource
=
nil
)
user
=
where
(
email:
access_token
.
info
[
'email'
]).
first_or_create
do
|
_user
|
_user
.
name
=
access_token
.
info
[
'name'
]
_user
.
image_url
=
access_token
.
info
[
'image'
]
_user
.
password
=
Devise
.
friendly_token
[
0
,
20
]
_user
.
nickname
=
((
'a'
..
'z'
).
to_a
+
(
'A'
..
'Z'
).
to_a
+
(
0
..
9
).
to_a
).
shuffle
[
0
..
4
].
join
user
=
where
(
email:
access_token
.
info
[
'email'
]).
first_or_create
do
|
u
|
u
.
name
=
access_token
.
info
[
'name'
]
u
.
image_url
=
access_token
.
info
[
'image'
]
u
.
password
=
Devise
.
friendly_token
[
0
,
20
]
u
.
nickname
=
((
'a'
..
'z'
).
to_a
+
(
'A'
..
'Z'
).
to_a
+
(
0
..
9
).
to_a
).
shuffle
[
0
..
4
].
join
end
user
.
update
(
...
...
@@ -113,9 +113,9 @@ class User < ActiveRecord::Base
# push通知を追加
def
push_notification
(
detail_path
,
body
)
unless
notifications
.
where
(
detail_path:
detail_path
).
unread
.
exists?
notifications
.
create
(
detail_path:
detail_path
,
body:
body
,
is_read:
false
)
end
return
if
notifications
.
where
(
detail_path:
detail_path
).
unread
.
exists?
notifications
.
create
(
detail_path:
detail_path
,
body:
body
,
is_read:
false
)
end
# record footprint
...
...
lib/tasks/migrations.rake
View file @
3a981ef7
...
...
@@ -3,11 +3,11 @@ namespace :migrations do
desc
'001 nicknameを自動付与'
task
task_001_user_nickname: :environment
do
User
.
all
.
each
do
|
_
user
|
next
if
_
user
.
nickname
.
present?
User
.
all
.
each
do
|
user
|
next
if
user
.
nickname
.
present?
new_nickname
=
((
'a'
..
'z'
).
to_a
+
(
'A'
..
'Z'
).
to_a
+
(
0
..
9
).
to_a
).
shuffle
[
0
..
4
].
join
_
user
.
update_attributes!
(
nickname:
new_nickname
)
user
.
update_attributes!
(
nickname:
new_nickname
)
end
end
...
...
spec/models/markdown_renderer_spec.rb
View file @
3a981ef7
...
...
@@ -8,6 +8,7 @@ RSpec.describe MarkdownRenderer, type: :model do
- body
- test
EOS
expect
(
renderer
.
render
.
to_s
.
gsub
(
/^ +/
,
''
)).
to
eq
(
<<
EOS
)
<h1>title</h1>
...
...
@@ -26,12 +27,14 @@ EOS
expect
(
renderer
.
render
.
to_s
.
gsub
(
/^ +/
,
''
)).
to
eq
(
<<
EOS
)
<p>
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-1.pdf" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-1.pdf"
width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>
<br>
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-2.pdf" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-2.pdf"
width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>
</p>
EOS
...
...
spec/models/tag_spec.rb
View file @
3a981ef7
...
...
@@ -33,7 +33,7 @@ describe Tag do
end
end
describe
'#
set_parent!
'
do
describe
'#
parent_tag=
'
do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_lang
=
Tag
.
create
(
name:
'lang'
)
...
...
@@ -42,7 +42,7 @@ describe Tag do
it
'successfully moved'
do
expect
(
@tag_ruby
.
parent
).
not_to
eq
(
@tag_lang
)
expect
(
@tag_lang
.
children
).
not_to
include
(
@tag_ruby
)
@tag_ruby
.
set_parent!
(
@tag_lang
)
@tag_ruby
.
parent_tag
=
@tag_lang
expect
(
@tag_ruby
.
parent
).
to
eq
(
@tag_lang
)
expect
(
@tag_lang
.
children
).
to
include
(
@tag_ruby
)
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