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 +4 -4
- data/lib/cabbage_doc.rb +1 -1
- data/lib/cabbage_doc/authentication.rb +1 -3
- data/lib/cabbage_doc/configuration.rb +33 -3
- data/lib/cabbage_doc/example.rb +6 -0
- data/lib/cabbage_doc/version.rb +1 -1
- data/lib/cabbage_doc/web.rb +11 -0
- data/web/helpers/helper.rb +7 -0
- data/web/public/css/application.css +9 -1
- data/web/views/action.haml +8 -2
- data/web/views/example.haml +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91e6336597672b91cdc338a24ad44aa2856e8cfa
|
4
|
+
data.tar.gz: 1ccc5abce46f5a6a37dae2665c9def1fcce02130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
@@ -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
|
|
data/lib/cabbage_doc/example.rb
CHANGED
@@ -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
|
data/lib/cabbage_doc/version.rb
CHANGED
data/lib/cabbage_doc/web.rb
CHANGED
@@ -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
|
data/web/views/action.haml
CHANGED
@@ -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'
|
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.
|
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-
|
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
|