carraway 0.6.0 → 0.7.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 +4 -4
- data/carraway.gemspec +1 -0
- data/lib/carraway.rb +1 -0
- data/lib/carraway/config.rb +4 -0
- data/lib/carraway/file.rb +85 -0
- data/lib/carraway/post.rb +9 -2
- data/lib/carraway/server.rb +15 -1
- data/lib/carraway/version.rb +1 -1
- data/lib/carraway/views/edit.erb +2 -0
- data/lib/carraway/views/file_modal.erb +39 -0
- data/lib/carraway/views/files.erb +34 -0
- data/lib/carraway/views/layout.erb +1 -0
- data/lib/carraway/views/new.erb +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e471f5dd46965102f05fa1ea09778a917a597ab013e3bafccf65609985a047b3
|
4
|
+
data.tar.gz: 8b3a5647ec657e5536bc5a66081bfdbb46355f3ddf153dc2bea13af53c9d25b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aac3ab9b4b42cd867ea13618e61950ff9178be52f3ea768e6ed78e8d7087c38a3a7cc2c4ff050d8ef072028ed6e8ef1aebe48b4cfce626ad23dc9658d87050a5
|
7
|
+
data.tar.gz: dbd5e5c8a049a62b139dfb55082bcc50cfa74b7dd80d8bdebc4a78b056ce23720c6344d479391275bf9c43a613d0a7524df18ab898534d0c0d8c7f57e37ba87e
|
data/carraway.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'thor'
|
24
24
|
spec.add_dependency 'sinatra'
|
25
25
|
spec.add_dependency 'aws-sdk-dynamodb'
|
26
|
+
spec.add_dependency 'aws-sdk-s3'
|
26
27
|
spec.add_dependency 'rack-flash3'
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.16"
|
data/lib/carraway.rb
CHANGED
data/lib/carraway/config.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'aws-sdk-dynamodb'
|
2
|
+
require 'aws-sdk-s3'
|
3
|
+
|
4
|
+
module Carraway
|
5
|
+
class File
|
6
|
+
class << self
|
7
|
+
def all
|
8
|
+
query = { table_name: Config.backend['table_name'] }
|
9
|
+
query[:filter_expression] = <<~FILTER
|
10
|
+
record_type = :type
|
11
|
+
FILTER
|
12
|
+
query[:expression_attribute_values] = { ':type' => 'file' }
|
13
|
+
|
14
|
+
dynamo_client.scan(query).items.map do |item|
|
15
|
+
new(
|
16
|
+
uid: item['uid'],
|
17
|
+
title: item['title'],
|
18
|
+
created: item['created']
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def dynamo_client
|
24
|
+
if Config.backend['endpoint']
|
25
|
+
Aws::DynamoDB::Client.new(
|
26
|
+
endpoint: Config.backend['endpoint'],
|
27
|
+
region: Config.backend['region'],
|
28
|
+
access_key_id: 'dummy',
|
29
|
+
secret_access_key: 'dummy'
|
30
|
+
)
|
31
|
+
else
|
32
|
+
Aws::DynamoDB::Client.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :title, :uid, :created
|
38
|
+
|
39
|
+
def initialize(title:, file: nil, uid: nil, created: nil)
|
40
|
+
@title = title
|
41
|
+
@file = file
|
42
|
+
@uid = uid || generate_uid
|
43
|
+
@created = created
|
44
|
+
end
|
45
|
+
|
46
|
+
%i(created).each do |col|
|
47
|
+
define_method("#{col}_at") do
|
48
|
+
at = send(col)
|
49
|
+
at && Time.at(at)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# FIXME duplicate impl on Post
|
54
|
+
def generate_uid
|
55
|
+
[Time.now.strftime('%Y%m%d%H%M%S'), "%05d" % rand(10000)].join
|
56
|
+
end
|
57
|
+
|
58
|
+
def s3_client
|
59
|
+
Aws::S3::Client.new
|
60
|
+
end
|
61
|
+
|
62
|
+
def path
|
63
|
+
ext = '.pdf' # FIXME Accept other type
|
64
|
+
[Config.file_backend['prefix'], '/', @uid, ext].join
|
65
|
+
end
|
66
|
+
|
67
|
+
def save(at = Time.now)
|
68
|
+
self.class.dynamo_client.put_item(
|
69
|
+
table_name: Config.backend['table_name'],
|
70
|
+
item: {
|
71
|
+
uid: @uid,
|
72
|
+
record_type: 'file',
|
73
|
+
title: @title,
|
74
|
+
created: at.to_i
|
75
|
+
}
|
76
|
+
)
|
77
|
+
s3_client.put_object(
|
78
|
+
body: @file[:tempfile],
|
79
|
+
bucket: Config.file_backend['bucket'],
|
80
|
+
acl: 'public-read',
|
81
|
+
key: path
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/carraway/post.rb
CHANGED
@@ -47,11 +47,17 @@ module Carraway
|
|
47
47
|
query = { table_name: Config.backend['table_name'] }
|
48
48
|
if published_only
|
49
49
|
query[:filter_expression] = <<~FILTER
|
50
|
-
|
50
|
+
record_type = :type
|
51
|
+
AND attribute_exists(published)
|
51
52
|
AND (NOT attribute_type(published, :t))
|
52
53
|
AND published < :now
|
53
54
|
FILTER
|
54
|
-
query[:expression_attribute_values] = { ':t' => 'NULL', ':now' => Time.now.to_i }
|
55
|
+
query[:expression_attribute_values] = { ':t' => 'NULL', ':now' => Time.now.to_i, ':type' => 'post' }
|
56
|
+
else
|
57
|
+
query[:filter_expression] = <<~FILTER
|
58
|
+
record_type = :type
|
59
|
+
FILTER
|
60
|
+
query[:expression_attribute_values] = { ':type' => 'post' }
|
55
61
|
end
|
56
62
|
|
57
63
|
client.scan(query).items.map do |item|
|
@@ -152,6 +158,7 @@ module Carraway
|
|
152
158
|
title: @title,
|
153
159
|
body: @body,
|
154
160
|
path: path,
|
161
|
+
record_type: 'post',
|
155
162
|
category: @category.key,
|
156
163
|
created: @created.to_i,
|
157
164
|
updated: @updated.to_i,
|
data/lib/carraway/server.rb
CHANGED
@@ -5,7 +5,7 @@ require 'time'
|
|
5
5
|
|
6
6
|
module Carraway
|
7
7
|
class Server < Sinatra::Base
|
8
|
-
set :views, File.expand_path('../views', __FILE__)
|
8
|
+
set :views, ::File.expand_path('../views', __FILE__)
|
9
9
|
set :method_override, true
|
10
10
|
enable :sessions
|
11
11
|
use Rack::Flash
|
@@ -26,11 +26,13 @@ module Carraway
|
|
26
26
|
end
|
27
27
|
|
28
28
|
get '/carraway/new' do
|
29
|
+
@files = File.all
|
29
30
|
erb :new
|
30
31
|
end
|
31
32
|
|
32
33
|
get %r{/carraway/edit/(\d+)} do |uid|
|
33
34
|
@post = Post.find(uid)
|
35
|
+
@files = File.all
|
34
36
|
# FIXME handle not found
|
35
37
|
erb :edit
|
36
38
|
end
|
@@ -105,5 +107,17 @@ module Carraway
|
|
105
107
|
flash[:message] = "Deleted #{@post.uid}"
|
106
108
|
redirect "/carraway/"
|
107
109
|
end
|
110
|
+
|
111
|
+
get '/carraway/files' do
|
112
|
+
@files = File.all
|
113
|
+
erb :files
|
114
|
+
end
|
115
|
+
|
116
|
+
post '/carraway/files' do
|
117
|
+
file = File.new(title: params[:title], file: params[:file])
|
118
|
+
file.save # FIXME validation and error
|
119
|
+
flash[:message] = "Saved #{file.path}"
|
120
|
+
redirect "/carraway/files"
|
121
|
+
end
|
108
122
|
end
|
109
123
|
end
|
data/lib/carraway/version.rb
CHANGED
data/lib/carraway/views/edit.erb
CHANGED
@@ -32,6 +32,8 @@
|
|
32
32
|
<button type="submit" class="waves-effect waves-light btn">保存</button>
|
33
33
|
</div>
|
34
34
|
</form>
|
35
|
+
<%= erb :file_modal, layout: false %>
|
36
|
+
|
35
37
|
<a class="waves-effect waves-light btn blue" href="<%= "/carraway/preview/#{@post.uid}" %>" target="_blank">プレビュー</a>
|
36
38
|
<% if @post.published %>
|
37
39
|
<form action="/carraway/unpublish" method="POST" class="col s12">
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<a class="waves-effect waves-light btn modal-trigger" href="#file-modal">ファイルをリンク</a>
|
2
|
+
<div id="file-modal" class="modal">
|
3
|
+
<div class="modal-content">
|
4
|
+
<table>
|
5
|
+
<thead>
|
6
|
+
<tr>
|
7
|
+
<th></th>
|
8
|
+
<th>タイトル</th>
|
9
|
+
<th>作成日</th>
|
10
|
+
<th>パス</th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
<tbody>
|
14
|
+
<% @files.each do |file| %>
|
15
|
+
<tr>
|
16
|
+
<td><button onclick="useFile('<%= file.title %>', '<%= file.path%>')">使う</button></td>
|
17
|
+
<td><%= file.title %></td>
|
18
|
+
<td><%= file.created_at %></td>
|
19
|
+
<td><%= file.path %></td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
</table>
|
24
|
+
</div>
|
25
|
+
<div class="modal-footer">
|
26
|
+
<a href="#!" class="modal-close waves-effect waves-green btn-flat">閉じる</a>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
<script>
|
30
|
+
var useFile = function(title, path) {
|
31
|
+
var body = document.getElementById('body');
|
32
|
+
body.value = body.value + '[' + title + '](/' + path + ')'
|
33
|
+
}
|
34
|
+
|
35
|
+
document.addEventListener('DOMContentLoaded', function() {
|
36
|
+
var elems = document.querySelectorAll('.modal');
|
37
|
+
var instances = M.Modal.init(elems);
|
38
|
+
});
|
39
|
+
</script>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<h3>Files</h3>
|
2
|
+
<div class="row">
|
3
|
+
<form action="/carraway/files" method="POST" class="col s12" enctype="multipart/form-data">
|
4
|
+
<div class="row">
|
5
|
+
<div class="input-field col s12">
|
6
|
+
<input type="text" id="title" name="title" placeholder="ファイルタイトル">
|
7
|
+
<label for="title">ファイルタイトル</label>
|
8
|
+
</div>
|
9
|
+
<div class="input-field col s12">
|
10
|
+
<input type="file" id="file" name="file" placeholder="ファイル">
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<button type="submit" class="waves-effect waves-light btn">保存</button>
|
15
|
+
</form>
|
16
|
+
</div>
|
17
|
+
<table>
|
18
|
+
<thead>
|
19
|
+
<tr>
|
20
|
+
<th>タイトル</th>
|
21
|
+
<th>作成日</th>
|
22
|
+
<th>パス</th>
|
23
|
+
</tr>
|
24
|
+
</thead>
|
25
|
+
<tbody>
|
26
|
+
<% @files.each do |file| %>
|
27
|
+
<tr>
|
28
|
+
<td><%= file.title %></td>
|
29
|
+
<td><%= file.created_at %></td>
|
30
|
+
<td><%= file.path %></td>
|
31
|
+
</tr>
|
32
|
+
<% end %>
|
33
|
+
</tbody>
|
34
|
+
</table>
|
@@ -13,6 +13,7 @@
|
|
13
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
|
+
<li><a href="/carraway/files">ファイル一覧</a></li>
|
16
17
|
<li><a href="/carraway/new">新規作成</a></li>
|
17
18
|
</ul>
|
18
19
|
</div>
|
data/lib/carraway/views/new.erb
CHANGED
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.
|
4
|
+
version: 0.7.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-09-
|
11
|
+
date: 2018-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk-s3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rack-flash3
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,10 +161,13 @@ files:
|
|
147
161
|
- lib/carraway/category.rb
|
148
162
|
- lib/carraway/cli.rb
|
149
163
|
- lib/carraway/config.rb
|
164
|
+
- lib/carraway/file.rb
|
150
165
|
- lib/carraway/post.rb
|
151
166
|
- lib/carraway/server.rb
|
152
167
|
- lib/carraway/version.rb
|
153
168
|
- lib/carraway/views/edit.erb
|
169
|
+
- lib/carraway/views/file_modal.erb
|
170
|
+
- lib/carraway/views/files.erb
|
154
171
|
- lib/carraway/views/layout.erb
|
155
172
|
- lib/carraway/views/new.erb
|
156
173
|
- lib/carraway/views/top.erb
|