cabbage_doc 0.0.6 → 0.0.7

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: 02e3cccfa65913a1525028740ac3965dabb841d6
4
- data.tar.gz: e5bd2ff47666cd7ec72ae81dbbc64a946f2db9c0
3
+ metadata.gz: 91e6336597672b91cdc338a24ad44aa2856e8cfa
4
+ data.tar.gz: 1ccc5abce46f5a6a37dae2665c9def1fcce02130
5
5
  SHA512:
6
- metadata.gz: 429e21350f3360728f512015cc0b0feb78a9fd0802e0bbac120039d7cecbf51eb803051372c6f2981ee62a1504ac8b7e5aa991ab49367679bc8f9398586bac02
7
- data.tar.gz: 6ee6ebd33a9dbefa266e9d3dd46200c8f3edf3344230e70c5cedfdc497df2299dc654b870199e4783b8520e0df3747f9ce62f725628a6159d0c746b5a6eb7dbb
6
+ metadata.gz: 4474ce6a1de2aaecfc981d344cafe6ebe794d0d4f2dfd9ead19a9d970caeb1e4dd5f18045d2211d0d40b8f5c0e89eaedb06ba978bd5453c13fb54f4ca3b8a86a
7
+ data.tar.gz: 55d173af4aed9f1cef47583c9b63def698741f3b173b28fd99fb6ba21f1b57fb98603da7e23b1aa7f0fc99c2c7f32c6e1c21eada54673ead26d831462eb4b013
data/lib/cabbage_doc.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module CabbageDoc
2
2
  MARKER = ':cabbagedoc:'.freeze
3
- VISIBILITY = %i(public private internal).freeze
3
+ VISIBILITY = %i(public private internal beta).freeze
4
4
  VISIBILITY_REGEXP = VISIBILITY.map(&:to_s).map(&:capitalize).join('|').freeze
5
5
 
6
6
  autoload :Path, 'cabbage_doc/path'
@@ -54,10 +54,8 @@ module CabbageDoc
54
54
  case type
55
55
  when :basic
56
56
  username && password
57
- when :token
58
- !token.nil?
59
57
  else
60
- false
58
+ !token.nil?
61
59
  end
62
60
  end
63
61
 
@@ -2,6 +2,34 @@ module CabbageDoc
2
2
  class Configuration
3
3
  include Singleton
4
4
 
5
+ class << self
6
+ def format_example(example, action, auth)
7
+ cmd = ["$", "curl"]
8
+
9
+ if auth.type == :basic
10
+ cmd << "-u \"user:pass\""
11
+ elsif auth.token
12
+ cmd << "-H \"Authorization: #{auth.type.to_s.capitalize} token\""
13
+ end
14
+
15
+ if action.method == "GET"
16
+ path = [action.path, example.to_query].join("?")
17
+ else
18
+ cmd << "-X #{action.method}"
19
+
20
+ example.params.each do |k, v|
21
+ cmd << "-d \"#{k}=#{v}\""
22
+ end
23
+
24
+ path = action.path
25
+ end
26
+
27
+ cmd << "\"#{[auth.uri, path].join}\""
28
+
29
+ cmd.join(' ')
30
+ end
31
+ end
32
+
5
33
  DEFAULTS = {
6
34
  path: 'api/v1',
7
35
  title: 'Cabbage Doc',
@@ -11,13 +39,15 @@ module CabbageDoc
11
39
  visibility: [VISIBILITY.first],
12
40
  cache: Cache.new,
13
41
  request: proc { |request| request.perform },
14
- theme: 'github'
42
+ theme: 'github',
43
+ examples: false,
44
+ format_example: method(:format_example)
15
45
  }.freeze
16
46
 
17
- OPTIONAL_ATTRIBUTES = %i(welcome path scheme title verbose authentication dev request cache theme visibility).freeze
47
+ OPTIONAL_ATTRIBUTES = %i(welcome path scheme title verbose authentication dev request cache theme visibility examples format_example).freeze
18
48
  REQUIRED_ATTRIBUTES = %i(domain controllers root).freeze
19
49
  ATTRIBUTES = (OPTIONAL_ATTRIBUTES + REQUIRED_ATTRIBUTES).freeze
20
- CALLABLE_ATTRIBUTES = %i(controllers authentication request).freeze
50
+ CALLABLE_ATTRIBUTES = %i(controllers authentication request format_example).freeze
21
51
 
22
52
  attr_accessor *ATTRIBUTES
23
53
 
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module CabbageDoc
2
4
  class Example
3
5
  include Parser
@@ -18,6 +20,10 @@ module CabbageDoc
18
20
  valid?
19
21
  end
20
22
 
23
+ def to_query
24
+ params.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join("&")
25
+ end
26
+
21
27
  def valid?
22
28
  !@label.nil?
23
29
  end
@@ -1,3 +1,3 @@
1
1
  module CabbageDoc
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
@@ -5,6 +5,8 @@ require 'json'
5
5
  require 'cgi'
6
6
 
7
7
  module CabbageDoc
8
+ module Helpers; end
9
+
8
10
  class Web < Sinatra::Base
9
11
  ROOT = File.expand_path("../../../web", __FILE__).freeze
10
12
 
@@ -21,6 +23,15 @@ module CabbageDoc
21
23
 
22
24
  helpers WebHelper
23
25
 
26
+ Dir.glob("#{root}/**/*.rb").sort.each do |helper|
27
+ require helper
28
+ end
29
+
30
+ CabbageDoc::Helpers.constants.each do |c|
31
+ mod = CabbageDoc::Helpers.const_get(c)
32
+ helpers mod if mod.is_a?(Module)
33
+ end
34
+
24
35
  get '/' do
25
36
  haml :index
26
37
  end
@@ -0,0 +1,7 @@
1
+ module CabbageDoc
2
+ module Helpers
3
+ module Helper
4
+ # nop
5
+ end
6
+ end
7
+ end
@@ -205,5 +205,13 @@ a:hover
205
205
 
206
206
  .action .description
207
207
  {
208
- margin-bottom: 20px;
208
+ margin-bottom: 10px;
209
+ }
210
+
211
+ .warning
212
+ {
213
+ border: 2px solid #FFC40F;
214
+ background-color: #FFF8E1;
215
+ padding: 10px;
216
+ margin-bottom: 10px;
209
217
  }
@@ -8,9 +8,15 @@
8
8
  .clear
9
9
  %form.hidden{ action: action.path, method: action.method }
10
10
  - if action.description
11
- .description= action.description
11
+ .description= markdown.render(action.description)
12
+ - if action.visibility == :beta
13
+ .warning= 'This API is still under development and will continue to evolve.'
14
+ - if config.examples && action.examples.any?
15
+ .examples
16
+ - action.examples.each do |example|
17
+ = haml :example, locals: { action: action, example: example }
12
18
  - if action.parameters.any?
13
- %table
19
+ %table.parameters
14
20
  %tr
15
21
  %th='Parameter'
16
22
  %th='Value'
@@ -0,0 +1,5 @@
1
+ .example
2
+ .label="#{example.label}:"
3
+ %pre
4
+ %code.bash
5
+ = config.format_example.call(example, action, auth)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cabbage_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihail Szabolcs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -153,6 +153,7 @@ files:
153
153
  - lib/cabbage_doc/web.rb
154
154
  - lib/cabbage_doc/web_helper.rb
155
155
  - lib/cabbage_doc/worker.rb
156
+ - web/helpers/helper.rb
156
157
  - web/public/css/application.css
157
158
  - web/public/css/highlight/agate.css
158
159
  - web/public/css/highlight/androidstudio.css
@@ -198,6 +199,7 @@ files:
198
199
  - web/views/controller.haml
199
200
  - web/views/documentation.haml
200
201
  - web/views/enumeration.haml
202
+ - web/views/example.haml
201
203
  - web/views/index.haml
202
204
  - web/views/layout.haml
203
205
  - web/views/parameter.haml