apiculture 0.1.1 → 0.1.6

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
- SHA1:
3
- metadata.gz: 79df0d596559e585252fcc1f7ae0d1e16a77fb5d
4
- data.tar.gz: 98c6f7a14fb1578e56ac209ddf10b45b68a50902
2
+ SHA256:
3
+ metadata.gz: be857ef48fe8ec836d116ed89ed39c2cf55d2d60e4a25ae81eab0ccdf2b05f36
4
+ data.tar.gz: 737058ecf04cb0af193c24438f7c3a96c16a2551079aa13f4bcfbed2afa14fe8
5
5
  SHA512:
6
- metadata.gz: d8080b5a857dccd6e19749e631ada30e06b0c3aac6d6f93c5c8146a2a370e9f6349da49790850f0fd735b05c7bb89f4defc204617f1fe97c4bea36cbb77eba49
7
- data.tar.gz: 0c9452c60ff24d6a56211c0efc5417d400dd88d88291b8df288e71e3bbbf3592eb2734a585aa0c2b14b886533b9a75865dbe6cebc0a911609a033f25755e86a9
6
+ metadata.gz: 39564495733b83ca4ce0e1963b470d9836e5ce549827f93689bebfe4f5f8e57fb368497a407142f1c6c78143ad6c56a6a5a4f74ba29bdf199704bce58d720885
7
+ data.tar.gz: 6c1e15fe7e3c009349d17cf59d5686b81ccc6e6c94724a89b343b404afd3c013ee8505bebe75c3228774215f7065c1faf11872589de6e6b78abafe8d462f78f7
@@ -2,12 +2,10 @@ gemfile:
2
2
  - gemfiles/Gemfile.rack-1.x
3
3
  - gemfiles/Gemfile.rack-2.x
4
4
  rvm:
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
8
- - 2.6.0-preview1
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - 2.7
9
10
  sudo: false
10
11
  cache: bundler
11
- matrix:
12
- allow_failures:
13
- - rvm: 2.6.0-preview1
@@ -36,13 +36,13 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency 'mustermann', '~> 1'
37
37
  s.add_runtime_dependency 'builder', '~> 3'
38
38
  s.add_runtime_dependency 'rdiscount', '~> 2'
39
- s.add_runtime_dependency 'github-markup', '~> 1'
39
+ s.add_runtime_dependency 'github-markup', '~> 3'
40
40
  s.add_runtime_dependency 'mustache', '~> 1'
41
41
 
42
42
  s.add_development_dependency 'rack-test'
43
- s.add_development_dependency "rspec", "~> 3.1", '< 3.2'
43
+ s.add_development_dependency "rspec", "~> 3"
44
44
  s.add_development_dependency "rdoc", "~> 6.0"
45
- s.add_development_dependency "rake", "~> 10"
45
+ s.add_development_dependency "rake"
46
46
  s.add_development_dependency "bundler", "~> 1.0"
47
47
  s.add_development_dependency "simplecov", ">= 0"
48
48
  end
@@ -12,6 +12,6 @@ group :development do
12
12
  gem "rspec", "~> 3.1", '< 3.2'
13
13
  gem "rdoc", "~> 6.0"
14
14
  gem "rake", "~> 10"
15
- gem "bundler", "~> 1.0"
16
15
  gem "simplecov", ">= 0"
16
+ gem "bundler"
17
17
  end
@@ -12,6 +12,6 @@ group :development do
12
12
  gem "rspec", "~> 3.1", '< 3.2'
13
13
  gem "rdoc", "~> 6.0"
14
14
  gem "rake", "~> 10"
15
- gem "bundler", "~> 1.0"
16
15
  gem "simplecov", ">= 0"
16
+ gem "bundler"
17
17
  end
@@ -8,6 +8,7 @@ module Apiculture
8
8
  require_relative 'apiculture/action_definition'
9
9
  require_relative 'apiculture/markdown_segment'
10
10
  require_relative 'apiculture/timestamp_promise'
11
+ require_relative 'apiculture/app_documentation'
11
12
 
12
13
  def self.extended(in_class)
13
14
  in_class.send(:include, SinatraInstanceMethods)
@@ -202,7 +203,6 @@ module Apiculture
202
203
  # MyApi.api_documentation.to_markdown #=> "..."
203
204
  # MyApi.api_documentation.to_html #=> "..."
204
205
  def api_documentation
205
- require_relative 'apiculture/app_documentation'
206
206
  AppDocumentation.new(self, @apiculture_mounted_at.to_s, @apiculture_actions_and_docs || [])
207
207
  end
208
208
 
@@ -102,7 +102,7 @@ class Apiculture::App
102
102
  end
103
103
 
104
104
  def perform_action_block(&blk)
105
- # Execut the action in a Sinatra-like fashion - passing the route parameter values as
105
+ # Executes the action in a Sinatra-like fashion - passing the route parameter values as
106
106
  # arguments to the given block/callable. This is where in the future we should ditch
107
107
  # the Sinatra calling conventions - Sinatra mandates that the action accept the route parameters
108
108
  # as arguments and grab all the useful stuff from instance methods like `params` etc. whereas
@@ -96,8 +96,8 @@
96
96
  }
97
97
  </style>
98
98
  </head>
99
-
99
+
100
100
  <body>
101
101
  {{& html_fragment }}
102
102
  </body>
103
- </html>
103
+ </html>
@@ -1,4 +1,6 @@
1
1
  require 'builder'
2
+ require 'rdiscount'
3
+
2
4
  # Generates Markdown/HTML documentation about a single API action.
3
5
  #
4
6
  # Formats route parameters and request/QS parameters as a neat HTML
@@ -26,12 +28,15 @@ class Apiculture::MethodDocumentation
26
28
 
27
29
  # Compose an HTML string by converting the result of +to_markdown+
28
30
  def to_html_fragment
29
- require 'rdiscount'
30
- RDiscount.new(to_markdown).to_html
31
+ markdown_string_to_html(to_markdown)
31
32
  end
32
33
 
33
34
  private
34
35
 
36
+ def markdown_string_to_html(str)
37
+ RDiscount.new(str.to_s).to_html
38
+ end
39
+
35
40
  class StringBuf #:nodoc:
36
41
  def initialize; @blocks = []; end
37
42
  def <<(block); @blocks << block.to_s; self; end
@@ -59,7 +64,7 @@ class Apiculture::MethodDocumentation
59
64
  @definition.route_parameters.each do | param |
60
65
  html.tr do
61
66
  html.td { html.tt(':%s' % param.name) }
62
- html.td(param.description)
67
+ html.td { html << markdown_string_to_html(param.description) }
63
68
  end
64
69
  end
65
70
  end
@@ -98,7 +103,7 @@ class Apiculture::MethodDocumentation
98
103
  @definition.responses.each do | resp |
99
104
  html.tr do
100
105
  html.td { html.b(resp.http_status_code) }
101
- html.td resp.description
106
+ html.td { html << markdown_string_to_html(resp.description) }
102
107
  html.td { html.pre { html.code(body_example(resp)) }}
103
108
  end
104
109
  end
@@ -139,7 +144,7 @@ class Apiculture::MethodDocumentation
139
144
  html.td { html.tt(param.name.to_s) }
140
145
  html.td(param.required ? 'Yes' : 'No')
141
146
  html.td(param.matchable.inspect)
142
- html.td(param.description.to_s)
147
+ html.td { html << markdown_string_to_html(param.description) }
143
148
  end
144
149
  end
145
150
  end
@@ -1,3 +1,3 @@
1
1
  module Apiculture
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -1,28 +1,35 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe "Apiculture.api_documentation" do
4
- let(:app) {
4
+ let(:app) do
5
5
  Class.new(Apiculture::App) do
6
6
  extend Apiculture
7
-
7
+
8
8
  markdown_string 'This API is very important. Because it has to do with pancakes.'
9
-
9
+
10
10
  documentation_build_time!
11
-
11
+
12
12
  desc 'Order a pancake'
13
- required_param :diameter, "Diameter of the pancake", Integer
13
+ required_param :diameter, "Diameter of the pancake. The pancake will be **bold**", Integer
14
14
  param :topping, 'Type of topping', String
15
- responds_with 200, 'When the pancake is created succesfully', {id: 'abdef..c21'}
15
+ pancake_response_info = <<~EOS
16
+ When the pancake has been baked successfully
17
+ The pancake will have the following properties:
18
+
19
+ * It is going to be round
20
+ * It is going to be delicious
21
+ EOS
22
+ responds_with 200, pancake_response_info, { id: 'abdef..c21' }
16
23
  api_method :post, '/pancakes' do
17
24
  end
18
-
25
+
19
26
  desc 'Check the pancake status'
20
27
  route_param :id, 'Pancake ID to check status on'
21
- responds_with 200, 'When the pancake is found', {status: 'Baking'}
22
- responds_with 404, 'When no such pancake exists', {status: 'No such pancake'}
28
+ responds_with 200, 'When the pancake is found', { status: 'Baking' }
29
+ responds_with 404, 'When no such pancake exists', { status: 'No such pancake' }
23
30
  api_method :get, '/pancake/:id' do
24
31
  end
25
-
32
+
26
33
  desc 'Throw away the pancake'
27
34
  route_param :id, 'Pancake ID to delete'
28
35
  api_method :delete, '/pancake/:id' do
@@ -33,21 +40,21 @@ describe "Apiculture.api_documentation" do
33
40
  api_method :get, '/pancake/with/:topping_id' do |topping_id|
34
41
  end
35
42
  end
36
- }
37
-
43
+ end
44
+
38
45
  it 'generates app documentation as HTML without the body element' do
39
46
  docco = app.api_documentation
40
47
  generated_html = docco.to_html_fragment
41
-
48
+
42
49
  expect(generated_html).not_to include('<body')
43
50
  expect(generated_html).to include('Pancake ID to check status on')
44
51
  expect(generated_html).to include('Pancake ID to delete')
45
52
  end
46
-
53
+
47
54
  it 'generates app documentation in HTML' do
48
55
  docco = app.api_documentation
49
56
  generated_html = docco.to_html
50
-
57
+
51
58
  if ENV['SHOW_TEST_DOC']
52
59
  File.open('t.html', 'w') do |f|
53
60
  f.write(generated_html)
@@ -55,21 +62,22 @@ describe "Apiculture.api_documentation" do
55
62
  `open #{f.path}`
56
63
  end
57
64
  end
58
-
65
+
59
66
  expect(generated_html).to include('<body')
60
67
  expect(generated_html).to include('Pancake ID to check status on')
61
- expect(generated_html).to include('When the pancake is created succesfully')
68
+ expect(generated_html).to include('When the pancake has been baked successfully')
62
69
  expect(generated_html).to include('"id": "abdef..c21"')
70
+ expect(generated_html).to end_with("\n")
63
71
  end
64
-
72
+
65
73
  it 'generates app documentation in Markdown' do
66
74
  docco = app.api_documentation
67
75
  generated_markdown = docco.to_markdown
68
-
76
+
69
77
  expect(generated_markdown).not_to include('<body')
70
78
  expect(generated_markdown).to include('## POST /pancakes')
71
79
  end
72
-
80
+
73
81
  it 'generates app documentation honoring the mount point' do
74
82
  overridden = Class.new(Apiculture::App) do
75
83
  extend Apiculture
@@ -77,11 +85,11 @@ describe "Apiculture.api_documentation" do
77
85
  api_method :get, '/pancakes' do
78
86
  end
79
87
  end
80
-
88
+
81
89
  generated_markdown = overridden.api_documentation.to_markdown
82
90
  expect(generated_markdown).to include('## GET /api/v2/pancakes')
83
91
  end
84
-
92
+
85
93
  it 'generates app documentation injecting the inline Markdown strings' do
86
94
  app_class = Class.new(Apiculture::App) do
87
95
  extend Apiculture
@@ -91,16 +99,16 @@ describe "Apiculture.api_documentation" do
91
99
  markdown_string '# This describes even more important stuff'
92
100
  markdown_string 'This is a paragraph'
93
101
  end
94
-
102
+
95
103
  generated_html = app_class.api_documentation.to_html
96
104
  expect(generated_html).to include('<h2>GET /pancakes</h2>')
97
105
  expect(generated_html).to include('<h1>This describes even more important stuff')
98
106
  expect(generated_html).to include('<h1>This describes important stuff')
99
107
  expect(generated_html).to include('<p>This is a paragraph')
100
108
  end
101
-
109
+
102
110
  context 'with a file containing Markdown that has to be spliced into the docs' do
103
- before(:each) { File.open('./TEST.md', 'w') {|f| f << "# This is an important header"} }
111
+ before(:each) { File.open('./TEST.md', 'w') { |f| f << "# This is an important header" } }
104
112
  after(:each) { File.unlink('./TEST.md') }
105
113
  it 'splices the contents of the file using markdown_file' do
106
114
  app_class = Class.new(Apiculture::App) do
@@ -109,7 +117,7 @@ describe "Apiculture.api_documentation" do
109
117
  api_method :get, '/pancakes' do
110
118
  end
111
119
  end
112
-
120
+
113
121
  generated_html = app_class.api_documentation.to_html
114
122
  expect(generated_html).to include('<h2>GET /pancakes</h2>')
115
123
  expect(generated_html).to include('<h1>This is an important header')
@@ -7,7 +7,7 @@ describe Apiculture::MethodDocumentation do
7
7
 
8
8
  definition.description = "This action bakes pancakes"
9
9
  definition.parameters << Apiculture::Parameter.new(:name, 'Pancake name', true, String, :to_s)
10
- definition.parameters << Apiculture::Parameter.new(:thickness, 'Pancake thickness', false, Float, :to_f)
10
+ definition.parameters << Apiculture::Parameter.new(:thickness, 'Pancake **thick**ness', false, Float, :to_f)
11
11
  definition.parameters << Apiculture::Parameter.new(:diameter, 'Pancake diameter', false, Integer, :to_i)
12
12
 
13
13
  definition.route_parameters << Apiculture::RouteParameter.new(:pan_id, 'ID of the pancake frying pan')
@@ -28,9 +28,9 @@ describe Apiculture::MethodDocumentation do
28
28
  expect(generated_html).to include('<h3>URL parameters</h3>')
29
29
  expect(generated_html).to include('ID of the pancake frying pan')
30
30
  expect(generated_html).to include('<h3>Request parameters</h3>')
31
- expect(generated_html).to include('<td>Pancake name</td>')
32
- expect(generated_html).to include('<td>Pancake has been baked</td>')
33
- expect(generated_html).to include('<td>Frying pan too cold</td>')
31
+ expect(generated_html).to include('<p>Pancake name</p>')
32
+ expect(generated_html).to include('<p>Pancake has been baked</p>')
33
+ expect(generated_html).to include('<p>Frying pan too cold</p>')
34
34
  end
35
35
 
36
36
  it 'generates HTML from an ActionDefinition without route params' do
@@ -38,7 +38,7 @@ describe Apiculture::MethodDocumentation do
38
38
 
39
39
  definition.description = "This action bakes pancakes"
40
40
  definition.parameters << Apiculture::Parameter.new(:name, 'Pancake name', true, String, :to_s)
41
- definition.parameters << Apiculture::Parameter.new(:thickness, 'Pancake thickness', false, Float, :to_f)
41
+ definition.parameters << Apiculture::Parameter.new(:thickness, 'Pancake **thick**ness', false, Float, :to_f)
42
42
  definition.parameters << Apiculture::Parameter.new(:diameter, 'Pancake diameter', false, Integer, :to_i)
43
43
 
44
44
  definition.http_verb = 'get'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiculture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-19 00:00:00.000000000 Z
12
+ date: 2021-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mustermann
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1'
62
+ version: '3'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1'
69
+ version: '3'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mustache
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -101,20 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '3.1'
105
- - - "<"
106
- - !ruby/object:Gem::Version
107
- version: '3.2'
104
+ version: '3'
108
105
  type: :development
109
106
  prerelease: false
110
107
  version_requirements: !ruby/object:Gem::Requirement
111
108
  requirements:
112
109
  - - "~>"
113
110
  - !ruby/object:Gem::Version
114
- version: '3.1'
115
- - - "<"
116
- - !ruby/object:Gem::Version
117
- version: '3.2'
111
+ version: '3'
118
112
  - !ruby/object:Gem::Dependency
119
113
  name: rdoc
120
114
  requirement: !ruby/object:Gem::Requirement
@@ -133,16 +127,16 @@ dependencies:
133
127
  name: rake
134
128
  requirement: !ruby/object:Gem::Requirement
135
129
  requirements:
136
- - - "~>"
130
+ - - ">="
137
131
  - !ruby/object:Gem::Version
138
- version: '10'
132
+ version: '0'
139
133
  type: :development
140
134
  prerelease: false
141
135
  version_requirements: !ruby/object:Gem::Requirement
142
136
  requirements:
143
- - - "~>"
137
+ - - ">="
144
138
  - !ruby/object:Gem::Version
145
- version: '10'
139
+ version: '0'
146
140
  - !ruby/object:Gem::Dependency
147
141
  name: bundler
148
142
  requirement: !ruby/object:Gem::Requirement
@@ -225,8 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
219
  - !ruby/object:Gem::Version
226
220
  version: '0'
227
221
  requirements: []
228
- rubyforge_project:
229
- rubygems_version: 2.6.11
222
+ rubygems_version: 3.0.3
230
223
  signing_key:
231
224
  specification_version: 4
232
225
  summary: Sweet API sauce on top of Rack