carraway 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carraway/category.rb +2 -2
- data/lib/carraway/post.rb +22 -13
- data/lib/carraway/server.rb +14 -15
- data/lib/carraway/version.rb +1 -1
- data/lib/carraway/views/edit.erb +5 -5
- data/lib/carraway/views/new.erb +0 -4
- data/lib/carraway/views/top.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7413bee588bc81463c7f6157ec89072fa668e57fb3dc82a9ac44d9122dbf1f75
|
4
|
+
data.tar.gz: 882068dfc6f541197e5090bb06fbd1deba5c878888cdbe75c1e4e43e1966dbee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2ae24be1f374f31f169b0a4df78ef67d663930b2822c8a3f2383efa8dc73c41d3f8fa28de9a0948c5a5f493154b747b46a368643b2346ca36d098e1ea1996b
|
7
|
+
data.tar.gz: 21e46ee4e9f196e3eb3f8469c0931f4f9551a066388115c04b6d73d1e8d1e0213dee6b0dfb3428dc0dc4684773f9ba459a62e385236b8603d1db221b3caa6092
|
data/lib/carraway/category.rb
CHANGED
data/lib/carraway/post.rb
CHANGED
@@ -6,10 +6,10 @@ module Carraway
|
|
6
6
|
def setup
|
7
7
|
client.create_table(
|
8
8
|
attribute_definitions: [
|
9
|
-
{ attribute_name: :
|
9
|
+
{ attribute_name: :uid, attribute_type: "S" },
|
10
10
|
],
|
11
11
|
key_schema: [
|
12
|
-
{ attribute_name: :
|
12
|
+
{ attribute_name: :uid, key_type: "HASH" },
|
13
13
|
],
|
14
14
|
provisioned_throughput: {
|
15
15
|
read_capacity_units: 5, # FIXME configurable
|
@@ -23,13 +23,17 @@ module Carraway
|
|
23
23
|
client.delete_table(table_name: Config.backend['table_name'])
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def generate_uid
|
27
|
+
[Time.now.strftime('%Y%m%d%H%M%S'), "%05d" % rand(10000)].join
|
28
|
+
end
|
29
|
+
|
30
|
+
def create(title:, body:, category_key:, at: Time.now)
|
27
31
|
category = Category.find(category_key)
|
28
32
|
# FIXME check path to prevent overwriting
|
29
33
|
post = new(
|
34
|
+
uid: generate_uid,
|
30
35
|
title: title,
|
31
36
|
body: body,
|
32
|
-
path: category.fullpath(path),
|
33
37
|
category: category,
|
34
38
|
created: at.to_i,
|
35
39
|
updated: at.to_i,
|
@@ -52,9 +56,9 @@ module Carraway
|
|
52
56
|
|
53
57
|
client.scan(query).items.map do |item|
|
54
58
|
new(
|
59
|
+
uid: item['uid'],
|
55
60
|
title: item['title'],
|
56
61
|
body: item['body'],
|
57
|
-
path: item['path'],
|
58
62
|
category: Category.find(item['category']),
|
59
63
|
created: Time.at(item['created']),
|
60
64
|
updated: Time.at(item['updated']),
|
@@ -63,18 +67,18 @@ module Carraway
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
|
-
def find(
|
70
|
+
def find(uid)
|
67
71
|
item = client.get_item(
|
68
72
|
key: {
|
69
|
-
|
73
|
+
uid: uid
|
70
74
|
},
|
71
75
|
table_name: Config.backend['table_name'],
|
72
76
|
).item
|
73
77
|
if item
|
74
78
|
new(
|
79
|
+
uid: item['uid'],
|
75
80
|
title: item['title'],
|
76
81
|
body: item['body'],
|
77
|
-
path: item['path'],
|
78
82
|
category: Category.find(item['category']),
|
79
83
|
created: Time.at(item['created']),
|
80
84
|
updated: Time.at(item['updated']),
|
@@ -97,13 +101,13 @@ module Carraway
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
100
|
-
attr_reader :
|
104
|
+
attr_reader :uid, :title, :body, :category, :created, :updated
|
101
105
|
attr_accessor :published
|
102
106
|
|
103
|
-
def initialize(title:, body:,
|
107
|
+
def initialize(uid:, title:, body:, category:, created:, updated:, published:)
|
108
|
+
@uid = uid
|
104
109
|
@title = title
|
105
110
|
@body = body
|
106
|
-
@path = path
|
107
111
|
@category = category
|
108
112
|
@created = created
|
109
113
|
@updated = updated
|
@@ -133,16 +137,21 @@ module Carraway
|
|
133
137
|
self.class.client.delete_item(
|
134
138
|
table_name: Config.backend['table_name'],
|
135
139
|
key: {
|
136
|
-
|
140
|
+
uid: @uid
|
137
141
|
}
|
138
142
|
)
|
139
143
|
end
|
140
144
|
|
145
|
+
def path
|
146
|
+
@category.fullpath(@uid)
|
147
|
+
end
|
148
|
+
|
141
149
|
def to_h
|
142
150
|
{
|
151
|
+
uid: @uid,
|
143
152
|
title: @title,
|
144
153
|
body: @body,
|
145
|
-
path:
|
154
|
+
path: path,
|
146
155
|
category: @category.key,
|
147
156
|
created: @created.to_i,
|
148
157
|
updated: @updated.to_i,
|
data/lib/carraway/server.rb
CHANGED
@@ -29,14 +29,14 @@ module Carraway
|
|
29
29
|
erb :new
|
30
30
|
end
|
31
31
|
|
32
|
-
get %r{/carraway/edit(
|
33
|
-
@post = Post.find(
|
32
|
+
get %r{/carraway/edit/(\d+)} do |uid|
|
33
|
+
@post = Post.find(uid)
|
34
34
|
# FIXME handle not found
|
35
35
|
erb :edit
|
36
36
|
end
|
37
37
|
|
38
|
-
get %r{/carraway/preview(
|
39
|
-
@post = Post.find(
|
38
|
+
get %r{/carraway/preview/(\d+)} do |uid|
|
39
|
+
@post = Post.find(uid)
|
40
40
|
# FIXME handle not found
|
41
41
|
|
42
42
|
# Refresh GatsbyJS
|
@@ -52,16 +52,15 @@ module Carraway
|
|
52
52
|
post '/carraway/' do
|
53
53
|
@post = Post.create(
|
54
54
|
title: params[:title],
|
55
|
-
path: params[:path],
|
56
55
|
body: params[:body],
|
57
56
|
category_key: params[:category]
|
58
57
|
)
|
59
58
|
flash[:message] = 'Created'
|
60
|
-
redirect "/carraway/edit
|
59
|
+
redirect "/carraway/edit/#{@post.uid}"
|
61
60
|
end
|
62
61
|
|
63
62
|
patch '/carraway/update' do
|
64
|
-
@post = Post.find(params[:
|
63
|
+
@post = Post.find(params[:uid])
|
65
64
|
# FIXME handle not found
|
66
65
|
@post.assign(
|
67
66
|
title: params[:title],
|
@@ -70,11 +69,11 @@ module Carraway
|
|
70
69
|
# FIXME validation
|
71
70
|
@post.save
|
72
71
|
flash[:message] = 'Updated'
|
73
|
-
redirect "/carraway/edit
|
72
|
+
redirect "/carraway/edit/#{@post.uid}"
|
74
73
|
end
|
75
74
|
|
76
75
|
patch '/carraway/publish' do
|
77
|
-
@post = Post.find(params[:
|
76
|
+
@post = Post.find(params[:uid])
|
78
77
|
# FIXME handle not found
|
79
78
|
published =
|
80
79
|
if params[:published] && params[:published].size > 0
|
@@ -87,24 +86,24 @@ module Carraway
|
|
87
86
|
# FIXME validation
|
88
87
|
@post.save
|
89
88
|
flash[:message] = 'Published'
|
90
|
-
redirect "/carraway/edit
|
89
|
+
redirect "/carraway/edit/#{@post.uid}"
|
91
90
|
end
|
92
91
|
|
93
92
|
patch '/carraway/unpublish' do
|
94
|
-
@post = Post.find(params[:
|
93
|
+
@post = Post.find(params[:uid])
|
95
94
|
# FIXME handle not found
|
96
95
|
@post.published = nil
|
97
96
|
# FIXME validation
|
98
97
|
@post.save
|
99
98
|
flash[:message] = 'Unpublished'
|
100
|
-
redirect "/carraway/edit
|
99
|
+
redirect "/carraway/edit/#{@post.uid}"
|
101
100
|
end
|
102
101
|
|
103
102
|
delete '/carraway/destroy' do
|
104
|
-
@post = Post.find(params[:
|
103
|
+
@post = Post.find(params[:uid]) # FIXME handle not found
|
105
104
|
@post.destroy
|
106
|
-
flash[:message] = "Deleted #{@post.
|
107
|
-
redirect "/carraway"
|
105
|
+
flash[:message] = "Deleted #{@post.uid}"
|
106
|
+
redirect "/carraway/"
|
108
107
|
end
|
109
108
|
end
|
110
109
|
end
|
data/lib/carraway/version.rb
CHANGED
data/lib/carraway/views/edit.erb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<td><%= @post.category.title %></td>
|
15
15
|
<td>
|
16
16
|
<%= @post.path %>
|
17
|
-
<input type="hidden" name="
|
17
|
+
<input type="hidden" name="uid" value="<%= @post.uid %>">
|
18
18
|
</td>
|
19
19
|
</tr>
|
20
20
|
</tbody>
|
@@ -32,11 +32,11 @@
|
|
32
32
|
<button type="submit" class="waves-effect waves-light btn">保存</button>
|
33
33
|
</div>
|
34
34
|
</form>
|
35
|
-
<a class="waves-effect waves-light btn blue" href="<%= "/carraway/preview
|
35
|
+
<a class="waves-effect waves-light btn blue" href="<%= "/carraway/preview/#{@post.uid}" %>" target="_blank">プレビュー</a>
|
36
36
|
<% if @post.published %>
|
37
37
|
<form action="/carraway/unpublish" method="POST" class="col s12">
|
38
38
|
<input type="hidden" name="_method" value="PATCH">
|
39
|
-
<input type="hidden" name="
|
39
|
+
<input type="hidden" name="uid" value="<%= @post.uid %>">
|
40
40
|
<div class="col s6">
|
41
41
|
<button type="submit" class="waves-effect waves-light btn orange">非公開</button>
|
42
42
|
</div>
|
@@ -44,7 +44,7 @@
|
|
44
44
|
<% else %>
|
45
45
|
<form action="/carraway/publish" method="POST" class="col s12">
|
46
46
|
<input type="hidden" name="_method" value="PATCH">
|
47
|
-
<input type="hidden" name="
|
47
|
+
<input type="hidden" name="uid" value="<%= @post.uid %>">
|
48
48
|
<div class="input-field col s12">
|
49
49
|
<input type="text" id="published" name="published" value="<%= @post.published_at %>" placeholder="2018-09-01 12:00:00">
|
50
50
|
<label for="published">公開日</label>
|
@@ -56,7 +56,7 @@
|
|
56
56
|
<% end %>
|
57
57
|
<form action="/carraway/destroy" method="POST" class="col s12">
|
58
58
|
<input type="hidden" name="_method" value="DELETE">
|
59
|
-
<input type="hidden" name="
|
59
|
+
<input type="hidden" name="uid" value="<%= @post.uid %>">
|
60
60
|
<div class="col s6">
|
61
61
|
<button type="submit" class="waves-effect waves-light btn red">削除</button>
|
62
62
|
</div>
|
data/lib/carraway/views/new.erb
CHANGED
@@ -8,10 +8,6 @@
|
|
8
8
|
<option value="<%= category.key %>"><%= category.title %></option>
|
9
9
|
<% end %>
|
10
10
|
</select>
|
11
|
-
<div class="input-field col s12">
|
12
|
-
<input type="text" id="path" name="path" placeholder="post_url_path">
|
13
|
-
<label for="path">Path</label>
|
14
|
-
</div>
|
15
11
|
<div class="input-field col s12">
|
16
12
|
<input type="text" id="title" name="title" placeholder="記事タイトル">
|
17
13
|
<label for="title">記事タイトル</label>
|
data/lib/carraway/views/top.erb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
<tbody>
|
13
13
|
<% Array(@category_posts[category.key]).each do |post| %>
|
14
14
|
<tr>
|
15
|
-
<td><a href="/carraway/edit
|
15
|
+
<td><a href="/carraway/edit/<%= post.uid %>"><%= post.title %></a></td>
|
16
16
|
<td><%= post.created_at %></td>
|
17
17
|
<td><%= post.updated_at %></td>
|
18
18
|
<td><%= post.published_at %></td>
|