carraway 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e122c09ebf92ff9ddceb03a2568fca044c3fe35626707dc6b32b87db417f5ccc
4
- data.tar.gz: d41f83895d578a171c7816064b8cefd9da0e1a612320dc7ae7777d88ff0e5513
3
+ metadata.gz: 724e3bc4ea01e06cffc062e3468f7cfe1e35006f8e90c0319ffec322d04eacc6
4
+ data.tar.gz: a95d020769b4e5d78a88f883c03fd0c691d6ed37304fd4ebf00be2f6686be18a
5
5
  SHA512:
6
- metadata.gz: ea135d574dd9a6b5338b440b8fc80ab88003685ce7ad0d731de7f265d4341ac0d916a5145e8b522f2b2687ebe7719ede2f52f787bce3bfb3f2fe8e9083ed9955
7
- data.tar.gz: ca9c9ce46aeb111d063a6d716df73cda9856aa5bb564b2cd61dcde5bd9c8213257539857af59c26064869a1ffde9cb5fe993e4c252e57269cad6bf2f04fcc276
6
+ metadata.gz: 80985cd730b4a99672165a15a458ed4253b7b9056dd1b3c765cdce0d90cb3bf2524704adeae733c8c24b44484d60a0d103c16658ae197df6d2924feff194c95c
7
+ data.tar.gz: bdc5eb40307d682ebc96a963450763c406e50eab73ea2e5e0f6476032b658e1955c3c304a717a714d2acb7986cc92314b7a5177ed9baf9283936e97600b0c462
data/lib/carraway/post.rb CHANGED
@@ -32,21 +32,29 @@ module Carraway
32
32
  path: category.fullpath(path),
33
33
  category: category,
34
34
  created: at.to_i,
35
- updated: at.to_i
35
+ updated: at.to_i,
36
+ published: nil
36
37
  )
37
38
  post.save(at: at)
38
39
  post
39
40
  end
40
41
 
41
- def all
42
- client.scan(table_name: Config.backend['table_name']).items.map do |item|
42
+ def all(published_only: false)
43
+ query = { table_name: Config.backend['table_name'] }
44
+ if published_only
45
+ query[:filter_expression] = 'attribute_exists(published) AND (NOT attribute_type(published, :t))'
46
+ query[:expression_attribute_values] = { ':t' => 'NULL' }
47
+ end
48
+
49
+ client.scan(query).items.map do |item|
43
50
  new(
44
51
  title: item['title'],
45
52
  body: item['body'],
46
53
  path: item['path'],
47
54
  category: Category.find(item['category']),
48
55
  created: Time.at(item['created']),
49
- updated: Time.at(item['updated'])
56
+ updated: Time.at(item['updated']),
57
+ published: item['published'] && Time.at(item['published'])
50
58
  )
51
59
  end
52
60
  end
@@ -65,7 +73,8 @@ module Carraway
65
73
  path: item['path'],
66
74
  category: Category.find(item['category']),
67
75
  created: Time.at(item['created']),
68
- updated: Time.at(item['updated'])
76
+ updated: Time.at(item['updated']),
77
+ published: item['published'] && Time.at(item['published'])
69
78
  )
70
79
  end
71
80
  end
@@ -85,14 +94,23 @@ module Carraway
85
94
  end
86
95
 
87
96
  attr_reader :title, :body, :path, :category, :created, :updated
97
+ attr_accessor :published
88
98
 
89
- def initialize(title:, body:, path:, category:, created:, updated:)
99
+ def initialize(title:, body:, path:, category:, created:, updated:, published:)
90
100
  @title = title
91
101
  @body = body
92
102
  @path = path
93
103
  @category = category
94
104
  @created = created
95
105
  @updated = updated
106
+ @published = published
107
+ end
108
+
109
+ %i(created updated published).each do |col|
110
+ define_method("#{col}_at") do
111
+ at = send(col)
112
+ at && Time.at(at)
113
+ end
96
114
  end
97
115
 
98
116
  def assign(title:, body:)
@@ -124,6 +142,7 @@ module Carraway
124
142
  category: @category.key,
125
143
  created: @created.to_i,
126
144
  updated: @updated.to_i,
145
+ published: @published && @published.to_i
127
146
  }
128
147
  end
129
148
  end
@@ -20,7 +20,7 @@ module Carraway
20
20
  end
21
21
 
22
22
  get '/carraway/api/posts' do
23
- posts = Post.all.map(&:to_h)
23
+ posts = Post.all(published_only: true).map(&:to_h)
24
24
  { data: { posts: posts } }.to_json
25
25
  end
26
26
 
@@ -72,6 +72,26 @@ module Carraway
72
72
  redirect "/carraway/edit#{@post.path}"
73
73
  end
74
74
 
75
+ patch '/carraway/publish' do
76
+ @post = Post.find(params[:path])
77
+ # FIXME handle not found
78
+ @post.published = Time.now.to_i
79
+ # FIXME validation
80
+ @post.save
81
+ flash[:message] = 'Published'
82
+ redirect "/carraway/edit#{@post.path}"
83
+ end
84
+
85
+ patch '/carraway/unpublish' do
86
+ @post = Post.find(params[:path])
87
+ # FIXME handle not found
88
+ @post.published = nil
89
+ # FIXME validation
90
+ @post.save
91
+ flash[:message] = 'Unpublished'
92
+ redirect "/carraway/edit#{@post.path}"
93
+ end
94
+
75
95
  delete '/carraway/destroy' do
76
96
  @post = Post.find(params[:path]) # FIXME handle not found
77
97
  @post.destroy
@@ -1,3 +1,3 @@
1
1
  module Carraway
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -33,6 +33,23 @@
33
33
  </div>
34
34
  </form>
35
35
  <a class="waves-effect waves-light btn blue" href="<%= "/carraway/preview#{@post.path}" %>" target="_blank">プレビュー</a>
36
+ <% if @post.published %>
37
+ <form action="/carraway/unpublish" method="POST" class="col s12">
38
+ <input type="hidden" name="_method" value="PATCH">
39
+ <input type="hidden" name="path" value="<%= @post.path %>">
40
+ <div class="col s6">
41
+ <button type="submit" class="waves-effect waves-light btn orange">非公開</button>
42
+ </div>
43
+ </form>
44
+ <% else %>
45
+ <form action="/carraway/publish" method="POST" class="col s12">
46
+ <input type="hidden" name="_method" value="PATCH">
47
+ <input type="hidden" name="path" value="<%= @post.path %>">
48
+ <div class="col s6">
49
+ <button type="submit" class="waves-effect waves-light btn orange">公開</button>
50
+ </div>
51
+ </form>
52
+ <% end %>
36
53
  <form action="/carraway/destroy" method="POST" class="col s12">
37
54
  <input type="hidden" name="_method" value="DELETE">
38
55
  <input type="hidden" name="path" value="<%= @post.path %>">
@@ -10,7 +10,7 @@
10
10
  <header>
11
11
  <nav>
12
12
  <div class="nav-wrapper">
13
- <a href="/carraway" class="brand-logo">Carraway</a>
13
+ <a href="/carraway/" class="brand-logo">Carraway</a>
14
14
  <ul id="nav-mobile" class="right hide-on-med-and-down">
15
15
  <li><a href="/carraway/">記事一覧</a></li>
16
16
  <li><a href="/carraway/new">新規作成</a></li>
@@ -1,12 +1,23 @@
1
1
  <% @categories.each do |category| %>
2
- <ul class="collection with-header">
3
- <li class="collection-header">
4
- <%= category.title %>
5
- </li>
2
+ <h3><%= category.title %></h2>
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>タイトル</th>
7
+ <th>作成日</th>
8
+ <th>更新日</th>
9
+ <th>公開日</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
6
13
  <% Array(@category_posts[category.key]).each do |post| %>
7
- <li class="collection-item">
8
- <a href="/carraway/edit<%= post.path %>"><%= post.title %></a>
9
- </li>
14
+ <tr>
15
+ <td><a href="/carraway/edit<%= post.path %>"><%= post.title %></a></td>
16
+ <td><%= post.created_at %></td>
17
+ <td><%= post.updated_at %></td>
18
+ <td><%= post.published_at %></td>
19
+ </tr>
10
20
  <% end %>
11
- </ul>
21
+ </tbody>
22
+ </table>
12
23
  <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carraway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adorechic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor