carraway 0.9.0 → 0.10.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: 2fa7bf196fef42d4f8131df73bcec5885b3fd0501603495c9e60fde6ca94f288
4
- data.tar.gz: da4a03acb56e94e169463ade2399f8163afa03afa8333d0282b7c28a4012c75b
3
+ metadata.gz: d415ec6e6ae471fa9ae3efa61f5def1465f9ee389f4493c79fa9346b6a48403f
4
+ data.tar.gz: afbdce1993f0df85e123a52c700b9752ddc211a294a49ec79e25db4450dcd1f4
5
5
  SHA512:
6
- metadata.gz: dbb157533c82f9cb6b4e18eb713b34f658a879785ecdac0c26aad5830981808c550dee0e0cda5477f26e60eaf0b371852eed4ea6561e4ba5849430034720cb7d
7
- data.tar.gz: ee328b4c377160bd03d81314279fff864dbd524164e2d887415b86d32ba91340a403b305acb39a8be11e022275c7661d93a60fc55f6b226fafef387e7de94baa
6
+ metadata.gz: 54455684723a8cf69b68c04625340d84efe035fd2787d3b5d36fd971ec23b9b97b30f6909cc97f83c690343848805d613c6b2f0527bcb1a27435580e0d0fbe14
7
+ data.tar.gz: be647d4c395a25a290ae1c93d12f9d5ff0b72aabe379ce609dcaa94b035d200552fcb157cc242f1758099a1c69bcd6c4b35717b744bc4af0b6041187b48c34f8
data/.travis.yml CHANGED
@@ -1,5 +1,17 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.5
5
+ - 2.6
6
+ env:
7
+ global:
8
+ - CC_TEST_REPORTER_ID=6163381913794d34d745b65d61b589c603cda50fb74c94a54ab0c6305c249bc3
9
+ before_install:
10
+ - gem install bundler -v 1.16.2
11
+ - docker-compose -f docker/docker-compose.yml up -d
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/README.md CHANGED
@@ -1,8 +1,15 @@
1
- # Carraway
1
+ # Carraway [![Build Status](https://travis-ci.org/adorechic/carraway.svg?branch=master)](https://travis-ci.org/adorechic/carraway) [![Maintainability](https://api.codeclimate.com/v1/badges/0c6800daedd07274f11c/maintainability)](https://codeclimate.com/github/adorechic/carraway/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/0c6800daedd07274f11c/test_coverage)](https://codeclimate.com/github/adorechic/carraway/test_coverage)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/carraway`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Carraway is a lightweight CMS backend for [Gatsby](https://www.gatsbyjs.org/).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Carraway provides
6
+ - Web console to edit contents
7
+ - Web preview for contents on Gatsby
8
+ - REST API for Gatsby to integrate with Carraway
9
+
10
+ [gatsby-source-carraway](https://github.com/adorechic/gatsby-source-carraway) is a source plugin for Gatsby to integrate with Carraway.
11
+
12
+ Carraway is required on Gatsby build and contents editting, so you don't have to keep running Carraway process.
6
13
 
7
14
  ## Installation
8
15
 
@@ -21,11 +28,62 @@ Or install it yourself as:
21
28
  $ gem install carraway
22
29
 
23
30
  ## Usage
31
+ Put carraway.yml
32
+
33
+ ```yaml
34
+ backend:
35
+ table_name: 'carraway_table' # If you use DynamoDB Local, set endpoint option
36
+ file_backend:
37
+ bucket: 'carraway_bucket'
38
+ prefix: 'files'
39
+ categories:
40
+ category_key:
41
+ title: 'Category Name'
42
+ dir: '/category/path'
43
+ ```
44
+
45
+ Create DynamoDB table.
46
+
47
+ ```
48
+ carraway setup
49
+
50
+ # You can use different config file name
51
+ # carrway setup -c your_config.yml
52
+ ```
24
53
 
25
- TODO: Write usage instructions here
54
+ Run carrway
55
+
56
+ ```
57
+ carraway start
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ ```yaml
63
+ port: 5000 # Optional. Defailt port is 5000
64
+ gatsby_endpoint: 'http://localhost:8000' # Optional. Default is http://localhost:8000
65
+ backend: # Required
66
+ table_name: 'carraway_table' # Required.
67
+ endpoint: http://localhost:6000 # Optional. Set if you use DynamoDB Local
68
+ region: ap-northeast-1 # Optional.
69
+ file_backend:
70
+ bucket: 'carraway_bucket' # Required
71
+ prefix: 'files' # Required.
72
+ categories: # Least one category is required
73
+ category_key:
74
+ title: 'Category Name'
75
+ dir: '/category/path'
76
+ labels:
77
+ label_key: 'Label title'
78
+ ```
26
79
 
27
80
  ## Development
28
81
 
82
+ ### Run DynamoDB Local
83
+ ```
84
+ docker-compose -f docker/docker-compose.yml up
85
+ ```
86
+
29
87
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
88
 
31
89
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/carraway.gemspec CHANGED
@@ -31,4 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
33
  spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "rack-test"
35
+ spec.add_development_dependency "webmock"
36
+ spec.add_development_dependency "simplecov"
34
37
  end
@@ -0,0 +1,9 @@
1
+ version: '3'
2
+ services:
3
+ dynamodb:
4
+ image: amazon/dynamodb-local
5
+ ports:
6
+ - '6000:6000'
7
+ command: -jar DynamoDBLocal.jar -dbPath /var/lib/dynamodb -port 6000
8
+ volumes:
9
+ - /tmp:/var/lib/dynamodb
@@ -23,6 +23,10 @@ module Carraway
23
23
  def file_backend
24
24
  @config['file_backend']
25
25
  end
26
+
27
+ def labels
28
+ @config['labels'] || {}
29
+ end
26
30
  end
27
31
  end
28
32
  end
data/lib/carraway/file.rb CHANGED
@@ -3,38 +3,7 @@ require 'aws-sdk-s3'
3
3
 
4
4
  module Carraway
5
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
6
+ attr_reader :title, :uid, :created, :file
38
7
 
39
8
  def initialize(title:, file: nil, uid: nil, created: nil)
40
9
  @title = title
@@ -50,36 +19,17 @@ module Carraway
50
19
  end
51
20
  end
52
21
 
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
22
  def path
63
23
  ext = '.pdf' # FIXME Accept other type
24
+ # Seems prefix does not have to required parameter
64
25
  [Config.file_backend['prefix'], '/', @uid, ext].join
65
26
  end
66
27
 
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
- )
28
+ private
29
+
30
+ # FIXME duplicate impl on Post
31
+ def generate_uid
32
+ [Time.now.strftime('%Y%m%d%H%M%S'), "%05d" % rand(10000)].join
83
33
  end
84
34
  end
85
35
  end
@@ -0,0 +1,58 @@
1
+ module Carraway
2
+ class FileRepository
3
+ def all
4
+ query = { table_name: Config.backend['table_name'] }
5
+ query[:filter_expression] = <<~FILTER
6
+ record_type = :type
7
+ FILTER
8
+ query[:expression_attribute_values] = {
9
+ ':type' => 'file'
10
+ }
11
+
12
+ client.scan(query).items.map do |item|
13
+ Carraway::File.new(
14
+ uid: item['uid'],
15
+ title: item['title'],
16
+ created: item['created']
17
+ )
18
+ end
19
+ end
20
+
21
+ def save(file, at: Time.now)
22
+ client.put_item(
23
+ table_name: Config.backend['table_name'],
24
+ item: {
25
+ uid: file.uid,
26
+ record_type: 'file',
27
+ title: file.title,
28
+ created: at.to_i
29
+ }
30
+ )
31
+ s3_client.put_object(
32
+ body: file.file[:tempfile],
33
+ bucket: Config.file_backend['bucket'],
34
+ acl: 'public-read',
35
+ key: file.path
36
+ )
37
+ end
38
+
39
+ private
40
+
41
+ def client
42
+ if Config.backend['endpoint']
43
+ Aws::DynamoDB::Client.new(
44
+ endpoint: Config.backend['endpoint'],
45
+ region: Config.backend['region'],
46
+ access_key_id: 'dummy',
47
+ secret_access_key: 'dummy'
48
+ )
49
+ else
50
+ Aws::DynamoDB::Client.new
51
+ end
52
+ end
53
+
54
+ def s3_client
55
+ Aws::S3::Client.new
56
+ end
57
+ end
58
+ end
data/lib/carraway/post.rb CHANGED
@@ -27,7 +27,7 @@ module Carraway
27
27
  [Time.now.strftime('%Y%m%d%H%M%S'), "%05d" % rand(10000)].join
28
28
  end
29
29
 
30
- def create(title:, body:, category_key:, at: Time.now)
30
+ def create(title:, body:, category_key:, at: Time.now, published: nil, labels: nil)
31
31
  category = Category.find(category_key)
32
32
  # FIXME check path to prevent overwriting
33
33
  post = new(
@@ -35,9 +35,10 @@ module Carraway
35
35
  title: title,
36
36
  body: body,
37
37
  category: category,
38
+ labels: labels,
38
39
  created: at.to_i,
39
40
  updated: at.to_i,
40
- published: nil
41
+ published: published
41
42
  )
42
43
  post.save(at: at)
43
44
  post
@@ -65,6 +66,7 @@ module Carraway
65
66
  uid: item['uid'],
66
67
  title: item['title'],
67
68
  body: item['body'],
69
+ labels: item['labels'],
68
70
  category: Category.find(item['category']),
69
71
  created: Time.at(item['created']),
70
72
  updated: Time.at(item['updated']),
@@ -85,6 +87,7 @@ module Carraway
85
87
  uid: item['uid'],
86
88
  title: item['title'],
87
89
  body: item['body'],
90
+ labels: item['labels'],
88
91
  category: Category.find(item['category']),
89
92
  created: Time.at(item['created']),
90
93
  updated: Time.at(item['updated']),
@@ -108,13 +111,14 @@ module Carraway
108
111
  end
109
112
 
110
113
  attr_reader :uid, :title, :body, :category, :created, :updated
111
- attr_accessor :published
114
+ attr_accessor :published, :labels
112
115
 
113
- def initialize(uid:, title:, body:, category:, created:, updated:, published:)
116
+ def initialize(uid:, title:, body:, category:, created:, updated:, published:, labels: nil)
114
117
  @uid = uid
115
118
  @title = title
116
119
  @body = body
117
120
  @category = category
121
+ @labels = labels
118
122
  @created = created
119
123
  @updated = updated
120
124
  @published = published
@@ -127,9 +131,10 @@ module Carraway
127
131
  end
128
132
  end
129
133
 
130
- def assign(title:, body:)
134
+ def assign(title:, body:, labels: nil)
131
135
  @title = title
132
136
  @body = body
137
+ @labels = labels
133
138
  end
134
139
 
135
140
  def save(at: Time.now)
@@ -158,6 +163,7 @@ module Carraway
158
163
  title: @title,
159
164
  body: @body,
160
165
  path: path,
166
+ labels: @labels,
161
167
  record_type: 'post',
162
168
  category: @category.key,
163
169
  created: @created.to_i,
@@ -38,13 +38,13 @@ module Carraway
38
38
  end
39
39
 
40
40
  get '/carraway/new' do
41
- @files = File.all
41
+ @files = FileRepository.new.all
42
42
  erb :new
43
43
  end
44
44
 
45
45
  get %r{/carraway/edit/(\d+)} do |uid|
46
46
  @post = Post.find(uid)
47
- @files = File.all
47
+ @files = FileRepository.new.all
48
48
  # FIXME handle not found
49
49
  erb :edit
50
50
  end
@@ -67,7 +67,8 @@ module Carraway
67
67
  @post = Post.create(
68
68
  title: params[:title],
69
69
  body: params[:body],
70
- category_key: params[:category]
70
+ category_key: params[:category],
71
+ labels: params[:labels],
71
72
  )
72
73
  flash[:message] = 'Created'
73
74
  redirect "/carraway/edit/#{@post.uid}"
@@ -78,7 +79,8 @@ module Carraway
78
79
  # FIXME handle not found
79
80
  @post.assign(
80
81
  title: params[:title],
81
- body: params[:body]
82
+ body: params[:body],
83
+ labels: params[:labels],
82
84
  )
83
85
  # FIXME validation
84
86
  @post.save
@@ -121,13 +123,14 @@ module Carraway
121
123
  end
122
124
 
123
125
  get '/carraway/files' do
124
- @files = File.all
126
+ @files = FileRepository.new.all
125
127
  erb :files
126
128
  end
127
129
 
128
130
  post '/carraway/files' do
129
131
  file = File.new(title: params[:title], file: params[:file])
130
- file.save # FIXME validation and error
132
+ # FIXME validation and error
133
+ FileRepository.new.save(file)
131
134
  flash[:message] = "Saved #{file.path}"
132
135
  redirect "/carraway/files"
133
136
  end
@@ -1,3 +1,3 @@
1
1
  module Carraway
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -19,6 +19,14 @@
19
19
  </tr>
20
20
  </tbody>
21
21
  </table>
22
+ <% Carraway::Config.labels.each do |key, title| %>
23
+ <p>
24
+ <label>
25
+ <input type="checkbox" class="filled-in" name="labels[]" value="<%= key %>" <%= @post.labels&.include?(key) ? 'checked' : nil %> />
26
+ <span><%= title %></span>
27
+ </label>
28
+ </p>
29
+ <% end %>
22
30
  <div class="input-field col s12">
23
31
  <input type="text" id="title" name="title" placeholder="記事タイトル" value="<%= @post.title %>">
24
32
  <label for="title">記事タイトル</label>
@@ -8,6 +8,14 @@
8
8
  <option value="<%= category.key %>"><%= category.title %></option>
9
9
  <% end %>
10
10
  </select>
11
+ <% Carraway::Config.labels.each do |key, title| %>
12
+ <p>
13
+ <label>
14
+ <input type="checkbox" class="filled-in" name="labels[]" value="<%= key %>" />
15
+ <span><%= title %></span>
16
+ </label>
17
+ </p>
18
+ <% end %>
11
19
  <div class="input-field col s12">
12
20
  <input type="text" id="title" name="title" placeholder="記事タイトル">
13
21
  <label for="title">記事タイトル</label>
data/lib/carraway.rb CHANGED
@@ -5,5 +5,6 @@ require 'carraway/version'
5
5
  require 'carraway/category'
6
6
  require 'carraway/post'
7
7
  require 'carraway/file'
8
+ require 'carraway/file_repository'
8
9
  require 'carraway/config'
9
10
  require 'carraway/server'
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.9.0
4
+ version: 0.10.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-11-07 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -150,6 +150,48 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack-test
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
153
195
  description: GatsbyJS backend
154
196
  email:
155
197
  - adorechic@gmail.com
@@ -170,12 +212,14 @@ files:
170
212
  - bin/develop
171
213
  - bin/setup
172
214
  - carraway.gemspec
215
+ - docker/docker-compose.yml
173
216
  - exe/carraway
174
217
  - lib/carraway.rb
175
218
  - lib/carraway/category.rb
176
219
  - lib/carraway/cli.rb
177
220
  - lib/carraway/config.rb
178
221
  - lib/carraway/file.rb
222
+ - lib/carraway/file_repository.rb
179
223
  - lib/carraway/post.rb
180
224
  - lib/carraway/server.rb
181
225
  - lib/carraway/version.rb