decko 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 966d3568b2b431aea47eb192ee3e945246a6f1b0
4
- data.tar.gz: a1e614eb82648621fe41e40aa7f4c9bdcaf1ef13
3
+ metadata.gz: c32627b7ed05eca4a8ff2f4a4b1f8888089fba82
4
+ data.tar.gz: f451e240fcd0d5db0a1588e1ebbc3f7205c1387f
5
5
  SHA512:
6
- metadata.gz: c552fb24c9c776b010feb149bb5bbe872d5f91c3d25e23f79ed2b9230c341e0ef8470645ddca56ef0795cc5d042827101c342f8757b53036a86bfc139d625b00
7
- data.tar.gz: bdb77c9c8d1782df48214e04ef222f0c91a5665deabad4ac8cadd473c64af82ef3d332abf560016da409f68d9833a79cd7f49c2c080e08be7c114cb7c8c52978
6
+ metadata.gz: 82ea35763d4a98be4e97c2d1bf502befb8335de8bed9e5359410b4e76d5fe754d1308a0e33408d730bb19c42798a4dfa6595dcce10a2c6f87049614ebf6aed0f
7
+ data.tar.gz: 2c2d0c373013647a373cfa5fe9a2c6cb5cb81d5a319b36ba4d989e41418350121734e47d2590421f4ecc347856bf591bfef5706ab0adf186a2f173b71f0bbd30
@@ -37,9 +37,12 @@ group :test do
37
37
  gem 'nokogumbo'
38
38
  end
39
39
 
40
+ group :test, :cypress do
41
+ gem 'cypress-on-rails', '~> 1.2'
42
+ end
43
+
40
44
  group :test, :development do
41
45
  gem 'colorize'
42
- gem 'cypress-on-rails', '~> 1.2'
43
46
  gem 'delayed_job_active_record', '~> 4.1'
44
47
  gem 'html2haml'
45
48
  gem 'rails-dev-tweaks'
@@ -39,6 +39,10 @@ module Decko
39
39
  show
40
40
  end
41
41
 
42
+ def reload
43
+ render json: { reload: true }
44
+ end
45
+
42
46
  def soft_redirect_params
43
47
  new_params = params.clone
44
48
  new_params.delete :card
@@ -121,7 +125,8 @@ module Decko
121
125
  end
122
126
 
123
127
  def view_does_not_require_name?
124
- Card::Format.tagged params[:view], :unknown_ok
128
+ return false unless (view = params[:view]&.to_sym)
129
+ Card::Set::Format::AbstractFormat::ViewOpts.unknown_ok[view]
125
130
  end
126
131
 
127
132
  # alters params
@@ -0,0 +1,46 @@
1
+ module Decko
2
+ # hacky first go at swagger generation.
3
+ #
4
+ # In decko, it really just converts yaml to ruby and back again.
5
+ #
6
+ # But it's useful for generating decko swagger docs.
7
+ class Swagger
8
+ attr_accessor :yaml_dir
9
+
10
+ def initialize yaml_dir=nil
11
+ @yaml_dir = yaml_dir
12
+ end
13
+
14
+ def read_yml filename, dir=nil
15
+ dir ||= yaml_dir || gem_input_dir
16
+ YAML.load_file File.join(dir, "#{filename}.yml")
17
+ end
18
+
19
+ def gem_swagger_dir
20
+ File.join Decko.gem_root, "lib/decko/swagger"
21
+ end
22
+
23
+ def gem_input_dir
24
+ File.join gem_swagger_dir, "input_yml"
25
+ end
26
+
27
+ def gem_swag
28
+ read_yml :layout, gem_input_dir
29
+ end
30
+
31
+ def merge_swag filename, dir=nil
32
+ yaml = read_yml filename, dir
33
+ gem_swag.deep_merge yaml
34
+ end
35
+
36
+ def output_file filename=nil, dir=nil
37
+ filename ||= "output.yml"
38
+ dir ||= yaml_dir || gem_input_dir
39
+ File.join dir, filename
40
+ end
41
+
42
+ def output_to_file hash, filename=nil, dir=nil
43
+ File.write output_file(filename, dir), hash.to_yaml
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,261 @@
1
+ openapi: 3.0.0
2
+ info:
3
+ description: >-
4
+ Decko organizes data into "cards." Decko's API supports retrieval and alteration of card data.
5
+
6
+ To get the JSON responses as described below, do _any_ of the following:
7
+ 1. Set the http access header to `application/json` in your request
8
+ 2. Add `.json` to the url, or
9
+ 3. Add `format=json` to the query params.
10
+
11
+ version: "0.8.0"
12
+ title: Decko API
13
+ contact:
14
+ email: info@decko.org
15
+ license:
16
+ name: GPL-2.0
17
+ url: 'https://opensource.org/licenses/GPL-2.0'
18
+ tags:
19
+ - name: create
20
+ - name: read
21
+ - name: update
22
+ - name: delete
23
+
24
+ paths:
25
+ /{mark}:
26
+ get:
27
+ tags:
28
+ - Decko
29
+ summary: "get specified view of card"
30
+ description: |-
31
+ All read operations involve producing a _view_ of a card.
32
+
33
+ The request can come in several variants, eg\:
34
+ 1. /{mark}?view={view} (standard)
35
+ 1. /{mark}/{view}
36
+ 1. /?mark={mark}&view={view}
37
+
38
+ parameters:
39
+ - $ref: '#/components/parameters/cardmark'
40
+ - $ref: '#/components/parameters/view'
41
+ responses:
42
+ 200:
43
+ $ref: '#/components/responses/200'
44
+ 404:
45
+ $ref: '#/components/responses/404'
46
+ put:
47
+ tags:
48
+ - Decko
49
+ summary: "update a card"
50
+ description: |-
51
+ Update a card's name, type, and/or content. It's also possible to use
52
+ a GET request with /update/{mark}
53
+ parameters:
54
+ - $ref: '#/components/parameters/cardmark'
55
+ - $ref: '#/components/parameters/card'
56
+ - $ref: '#/components/parameters/success'
57
+ responses:
58
+ 200:
59
+ $ref: '#/components/responses/200'
60
+ 404:
61
+ $ref: '#/components/responses/404'
62
+ # TODO: add patch
63
+ delete:
64
+ tags:
65
+ - Decko
66
+ summary: "delete a card"
67
+ parameters:
68
+ - $ref: '#/components/parameters/cardmark'
69
+ - $ref: '#/components/parameters/success'
70
+ responses:
71
+ 200:
72
+ $ref: '#/components/responses/200'
73
+ 404:
74
+ $ref: '#/components/responses/404'
75
+ /:
76
+ post:
77
+ tags:
78
+ - Decko
79
+ summary: "create a card"
80
+ description: |-
81
+ Create a card, setting its name, type, and/or content. It's also possible to use
82
+ a GET request with /card/create
83
+ parameters:
84
+ - $ref: '#/components/parameters/cardmark'
85
+ - $ref: '#/components/parameters/card'
86
+ - $ref: '#/components/parameters/success'
87
+ responses:
88
+ 200:
89
+ $ref: '#/components/responses/200'
90
+ 404:
91
+ $ref: '#/components/responses/404'
92
+
93
+ externalDocs:
94
+ description: Find out more about Decko
95
+ url: 'http://decko.org'
96
+ servers:
97
+ - url: 'http://decko.org'
98
+
99
+ components:
100
+ parameters:
101
+ cardmark:
102
+ name: mark
103
+ in: path
104
+ required: true
105
+ description: >-
106
+ A card's "mark" can be a name, an id, or a codename. Prefix ids with a tilde (~) and codenames with a colon (\:).
107
+
108
+ - **name:** Every card has a unique name. A name can have many variants. For example, `Berlin`, `berlin`, and `BERLIN!` all refer to the same card. The singularized, lower-cased, underscored variant of a name is called its "key."
109
+
110
+ - **id:** Every card stored in the database has a unique numerical id. _Note: some cards, called 'virtual cards', are not stored in the database and therefore do not have a numerical id. For example, the name `Menu+*refer to` identifies a virtual Search card that finds all the cards that refer to the `Menu` card.Because it is based on patterns that apply to all cards with names ending in `+*refer to`, there is no need to store each instance of that pattern._
111
+
112
+ - **codename:** Some cards also have special identifiers called "codenames". Card names can be edited by Decko users. If these names were used directly in code, then renaming would break that code. Codename identifiers solve this problem by providing persistent readable identifiers. Only cards referred to directly in code have codenames.
113
+
114
+ schema:
115
+ type: string
116
+ enum:
117
+ - '{name}'
118
+ - '~{id}'
119
+ - ':{codename}'
120
+ view:
121
+ name: view
122
+ in: query
123
+ required: false
124
+ schema:
125
+ type: string
126
+ enum:
127
+ - nucleus
128
+ - atom
129
+ - molecule
130
+ - id
131
+ - codename
132
+ - name
133
+ - key
134
+ - content
135
+ - type
136
+ default: molecule
137
+ description: The view determines the contents of the response JSON. See the corresponding schema for more details.
138
+ card:
139
+ name: card
140
+ in: header
141
+ schema:
142
+ type: object
143
+ properties:
144
+ name:
145
+ type: string
146
+ type:
147
+ type: string
148
+ content:
149
+ type: string
150
+ description: >-
151
+ The card parameter contains card field data, subcard field data.
152
+ It follows RubyOnRails hash parameter pattern; for example, a card's name is represented as `card[name]=foobar`.
153
+
154
+ The most common fields are:
155
+
156
+ - **name:** Every card has a unique name.
157
+
158
+ - **type:** The card\'s type. Note that every card has a type, and the value of this field should be the type card\'s name. You can alternatively use **type_id** or **type_code** with the type card\s id
159
+ or mark respectively.
160
+
161
+ - **content:** The card\'s content (in string form)
162
+
163
+ - **subcards** A hash that contains information about additional cards to be handled in the same transaction. Each key is a card name, and each value is a card hash. Eg `cards[subcards][+color][content]=red`
164
+
165
+ success:
166
+ name: success
167
+ in: header
168
+ schema:
169
+ type: object
170
+ description: >-
171
+ parameters hash to pass on to the GET request to which a successful
172
+ request will be redirected. Eg, `success[mark]=mycardname`
173
+
174
+ schemas:
175
+ "nucleus view":
176
+ name: "nucleus view"
177
+ type: object
178
+ properties:
179
+ id:
180
+ type: integer
181
+ format: int32
182
+ name:
183
+ type: string
184
+ url:
185
+ type: string
186
+ type:
187
+ type: string
188
+ codename:
189
+ type: string
190
+
191
+ "atom view":
192
+ name: "atom view"
193
+ type: object
194
+ properties:
195
+ id:
196
+ type: integer
197
+ format: int32
198
+ name:
199
+ type: string
200
+ url:
201
+ type: string
202
+ type:
203
+ type: string
204
+ codename:
205
+ type: string
206
+ content:
207
+ type: string
208
+
209
+ "molecule view":
210
+ type: object
211
+ properties:
212
+ id:
213
+ type: integer
214
+ name:
215
+ type: string
216
+ url:
217
+ type: string
218
+ type:
219
+ $ref: '#/components/schemas/nucleus%20view'
220
+ codename:
221
+ type: string
222
+ content:
223
+ type: string
224
+ html_url:
225
+ type: string
226
+ items:
227
+ type: array
228
+ items:
229
+ $ref: '#/components/schemas/atom%20view'
230
+ links:
231
+ type: array
232
+ items:
233
+ type: string
234
+ ancestors:
235
+ type: array
236
+ items:
237
+ $ref: "#/components/schemas/atom%20view"
238
+
239
+ "errors view":
240
+ type: object
241
+ properties:
242
+ error_status:
243
+ type: integer
244
+ error:
245
+ type: array
246
+ items:
247
+ type: string
248
+
249
+ responses:
250
+ 200:
251
+ description: "card data"
252
+ content:
253
+ application/json:
254
+ schema:
255
+ $ref: '#/components/schemas/molecule%20view'
256
+ 404:
257
+ description: "Could not find the card requested."
258
+ content:
259
+ application/json:
260
+ schema:
261
+ $ref: '#/components/schemas/errors%20view'
@@ -0,0 +1,233 @@
1
+ ---
2
+ openapi: 3.0.0
3
+ info:
4
+ description: |-
5
+ Decko organizes data into "cards." Decko's API supports retrieval and alteration of card data.
6
+ To get the JSON responses as described below, do _any_ of the following:
7
+ 1. Set the http access header to `application/json` in your request
8
+ 2. Add `.json` to the url, or
9
+ 3. Add `format=json` to the query params.
10
+ version: 0.8.0
11
+ title: Decko API
12
+ contact:
13
+ email: info@decko.org
14
+ license:
15
+ name: GPL-2.0
16
+ url: https://opensource.org/licenses/GPL-2.0
17
+ tags:
18
+ - name: create
19
+ - name: read
20
+ - name: update
21
+ - name: delete
22
+ paths:
23
+ "/{mark}":
24
+ get:
25
+ tags:
26
+ - read
27
+ summary: get specified view of card
28
+ description: |-
29
+ All read operations involve producing a _view_ of a card.
30
+ The request can come in several variants, eg\:
31
+ 1. /{mark}?view={view} (standard)
32
+ 1. /{mark}/{view}
33
+ 1. /?mark={mark}&view={view}
34
+ parameters:
35
+ - "$ref": "#/components/parameters/cardmark"
36
+ - "$ref": "#/components/parameters/view"
37
+ responses:
38
+ 200:
39
+ "$ref": "#/components/responses/200"
40
+ 404:
41
+ "$ref": "#/components/responses/404"
42
+ put:
43
+ tags:
44
+ - update
45
+ summary: update a card
46
+ parameters:
47
+ - "$ref": "#/components/parameters/cardmark"
48
+ - "$ref": "#/components/parameters/card"
49
+ - "$ref": "#/components/parameters/success"
50
+ responses:
51
+ 200:
52
+ "$ref": "#/components/responses/200"
53
+ 404:
54
+ "$ref": "#/components/responses/404"
55
+ delete:
56
+ tags:
57
+ - delete
58
+ summary: delete a card
59
+ parameters:
60
+ - "$ref": "#/components/parameters/cardmark"
61
+ - "$ref": "#/components/parameters/success"
62
+ responses:
63
+ 200:
64
+ "$ref": "#/components/responses/200"
65
+ 404:
66
+ "$ref": "#/components/responses/404"
67
+ "/":
68
+ post:
69
+ tags:
70
+ - create
71
+ summary: create a card
72
+ parameters:
73
+ - "$ref": "#/components/parameters/cardmark"
74
+ - "$ref": "#/components/parameters/card"
75
+ - "$ref": "#/components/parameters/success"
76
+ responses:
77
+ 200:
78
+ "$ref": "#/components/responses/200"
79
+ 404:
80
+ "$ref": "#/components/responses/404"
81
+ externalDocs:
82
+ description: Find out more about Decko
83
+ url: http://decko.org
84
+ servers:
85
+ - url: http://decko.org
86
+ components:
87
+ parameters:
88
+ cardmark:
89
+ name: mark
90
+ in: path
91
+ required: true
92
+ description: |-
93
+ A card's "mark" can be a name, an id, or a codename. Prefix ids with a tilde (~) and codenames with a colon (\:).
94
+ - **name:** Every card has a unique name. A name can have many variants. For example, `Berlin`, `berlin`, and `BERLIN!` all refer to the same card. The singularized, lower-cased, underscored variant of a name is called its "key."
95
+ - **id:** Every card stored in the database has a unique numerical id. _Note: some cards, called 'virtual cards', are not stored in the database and therefore do not have a numerical id. For example, the name `Menu+*refer to` identifies a virtual Search card that finds all the cards that refer to the `Menu` card.Because it is based on patterns that apply to all cards with names ending in `+*refer to`, there is no need to store each instance of that pattern._
96
+ - **codename:** Some cards also have special identifiers called "codenames". Card names can be edited by Decko users. If these names were used directly in code, then renaming would break that code. Codename identifiers solve this problem by providing persistent readable identifiers. Only cards referred to directly in code have codenames.
97
+ schema:
98
+ type: string
99
+ enum:
100
+ - "{name}"
101
+ - "~{id}"
102
+ - ":{codename}"
103
+ view:
104
+ name: view
105
+ in: query
106
+ required: false
107
+ schema:
108
+ type: string
109
+ enum:
110
+ - nucleus
111
+ - atom
112
+ - molecule
113
+ - id
114
+ - codename
115
+ - name
116
+ - key
117
+ - content
118
+ - type
119
+ default: molecule
120
+ description: The view determines the contents of the response JSON. See the
121
+ corresponding schema for more details.
122
+ card:
123
+ name: card
124
+ in: header
125
+ schema:
126
+ type: object
127
+ properties:
128
+ name:
129
+ type: string
130
+ type:
131
+ type: string
132
+ content:
133
+ type: string
134
+ description: |-
135
+ The card parameter contains card field data, subcard field data. It follows RubyOnRails hash parameter pattern; for example, a card's name is represented as `card[name]=foobar`.
136
+ The most common fields are:
137
+ - **name:** Every card has a unique name.
138
+ - **type:** The card\'s type. Note that every card has a type, and the value of this field should be the type card\'s name. You can alternatively use **type_id** or **type_code** with the type card\s id
139
+ or mark respectively.
140
+
141
+ - **content:** The card\'s content (in string form)
142
+ - **subcards** A hash that contains information about additional cards to be handled in the same transaction. Each key is a card name, and each value is a card hash. Eg `cards[subcards][+color][content]=red`
143
+ success:
144
+ name: success
145
+ in: header
146
+ schema:
147
+ type: object
148
+ description: parameters hash to pass on to the GET request to which a successful
149
+ request will be redirected. Eg, `success[mark]=mycardname`
150
+ schemas:
151
+ nucleus view:
152
+ name: nucleus view
153
+ type: object
154
+ properties:
155
+ id:
156
+ type: integer
157
+ format: int32
158
+ name:
159
+ type: string
160
+ url:
161
+ type: string
162
+ type:
163
+ type: string
164
+ codename:
165
+ type: string
166
+ atom view:
167
+ name: atom view
168
+ type: object
169
+ properties:
170
+ id:
171
+ type: integer
172
+ format: int32
173
+ name:
174
+ type: string
175
+ url:
176
+ type: string
177
+ type:
178
+ type: string
179
+ codename:
180
+ type: string
181
+ content:
182
+ type: string
183
+ molecule view:
184
+ type: object
185
+ properties:
186
+ id:
187
+ type: integer
188
+ name:
189
+ type: string
190
+ url:
191
+ type: string
192
+ type:
193
+ "$ref": "#/components/schemas/nucleus%20view"
194
+ codename:
195
+ type: string
196
+ content:
197
+ type: string
198
+ html_url:
199
+ type: string
200
+ items:
201
+ type: array
202
+ items:
203
+ "$ref": "#/components/schemas/atom%20view"
204
+ links:
205
+ type: array
206
+ items:
207
+ type: string
208
+ ancestors:
209
+ type: array
210
+ items:
211
+ "$ref": "#/components/schemas/atom%20view"
212
+ errors view:
213
+ type: object
214
+ properties:
215
+ error_status:
216
+ type: integer
217
+ error:
218
+ type: array
219
+ items:
220
+ type: string
221
+ responses:
222
+ 200:
223
+ description: card data
224
+ content:
225
+ application/json:
226
+ schema:
227
+ "$ref": "#/components/schemas/molecule%20view"
228
+ 404:
229
+ description: Could not find the card requested.
230
+ content:
231
+ application/json:
232
+ schema:
233
+ "$ref": "#/components/schemas/errors%20view"
@@ -100,7 +100,9 @@ class CardController < ActionController::Base
100
100
  # successful create, update, or delete action
101
101
  def render_success
102
102
  success = Card::Env.success.in_context card.name
103
- if Card::Env.ajax? && !success.hard_redirect?
103
+ if success.reload?
104
+ reload
105
+ elsif Card::Env.ajax? && !success.hard_redirect?
104
106
  soft_redirect success
105
107
  else
106
108
  hard_redirect success.to_url
@@ -140,8 +142,10 @@ class CardController < ActionController::Base
140
142
  end
141
143
 
142
144
  class << self
143
- def rescue_from_class klass
144
- rescue_from(klass) { |exception| handle_exception exception }
145
+ def rescue_from_class *klasses
146
+ klasses.each do |klass|
147
+ rescue_from(klass) { |exception| handle_exception exception }
148
+ end
145
149
  end
146
150
 
147
151
  def rescue_all?
@@ -149,7 +153,6 @@ class CardController < ActionController::Base
149
153
  end
150
154
  end
151
155
 
152
- rescue_from_class ActiveRecord::RecordInvalid
153
- rescue_from_class Card::Error::UserError
156
+ rescue_from_class(*Card::Error::UserError.user_error_classes)
154
157
  rescue_from_class StandardError if rescue_all?
155
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-04-11 00:00:00.000000000 Z
14
+ date: 2019-07-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: card
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 1.97.0.1
22
+ version: 1.98.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.97.0.1
29
+ version: 1.98.0
30
30
  description: a wiki approach to stuctured data, dynamic interaction, and web design
31
31
  email:
32
32
  - info@decko.org
@@ -118,6 +118,9 @@ files:
118
118
  - lib/decko/response.rb
119
119
  - lib/decko/rest_spec_helper.rb
120
120
  - lib/decko/script_decko_loader.rb
121
+ - lib/decko/swagger.rb
122
+ - lib/decko/swagger/input_yml/layout.yml
123
+ - lib/decko/swagger/output.yml
121
124
  - lib/decko/tasks/alias.rb
122
125
  - lib/decko/tasks/cucumber.rake
123
126
  - lib/decko/tasks/db.rake