dox 0.0.3 → 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/README.md +1 -1
- data/dox.gemspec +3 -0
- data/lib/dox.rb +24 -20
- data/lib/dox/config.rb +9 -4
- data/lib/dox/dsl/action.rb +11 -16
- data/lib/dox/dsl/documentation.rb +6 -9
- data/lib/dox/dsl/resource.rb +17 -13
- data/lib/dox/dsl/resource_group.rb +10 -8
- data/lib/dox/dsl/syntax.rb +16 -18
- data/lib/dox/entities/action.rb +19 -5
- data/lib/dox/entities/example.rb +1 -10
- data/lib/dox/entities/resource.rb +2 -1
- data/lib/dox/errors/file_not_found_error.rb +6 -0
- data/lib/dox/errors/folder_not_found_error.rb +6 -0
- data/lib/dox/errors/invalid_action_error.rb +6 -0
- data/lib/dox/errors/invalid_resource_error.rb +6 -0
- data/lib/dox/errors/invalid_resource_group_error.rb +6 -0
- data/lib/dox/formatter.rb +1 -1
- data/lib/dox/printers/action_printer.rb +1 -1
- data/lib/dox/printers/base_printer.rb +11 -7
- data/lib/dox/printers/document_printer.rb +1 -1
- data/lib/dox/printers/resource_printer.rb +1 -5
- data/lib/dox/version.rb +1 -1
- metadata +51 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9535d1b95849fc4c0dddff91c5ed6a35879d6505
|
4
|
+
data.tar.gz: c84f5af01e5de1524b533175a6141d67b995bee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7ee68d768d9fbbf34708e1cbb901fee9dd532d09807cbd9ffa0abb60d08d80c08114014280390f8532788b68e517d29dc70ebdb6ab678057e0dbfc51566ad3d
|
7
|
+
data.tar.gz: 900ec7205240057d71ae6f8c1753aabe9d03d66375dbf167336b7444f2d5840969b1ed510cf25011963807c382c051976a7fb6189178ebe1335ed96370fab653
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -94,7 +94,7 @@ Descriptions folder is a fullpath of a folder that contains markdown files with
|
|
94
94
|
|
95
95
|
``` ruby
|
96
96
|
Dox.configure do |config|
|
97
|
-
config.
|
97
|
+
config.header_file_path = 'api.md'
|
98
98
|
config.desc_folder_path = Rails.root.join('spec/support/api_doc/v1/markdown_descriptions')
|
99
99
|
end
|
100
100
|
```
|
data/dox.gemspec
CHANGED
@@ -29,4 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.11"
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_runtime_dependency "rspec-core"
|
34
|
+
spec.add_runtime_dependency "rails", ">= 4.0"
|
32
35
|
end
|
data/lib/dox.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
1
|
+
require 'dox/config'
|
2
|
+
require 'dox/dsl/attr_proxy'
|
3
|
+
require 'dox/dsl/action'
|
4
|
+
require 'dox/dsl/documentation'
|
5
|
+
require 'dox/dsl/resource_group'
|
6
|
+
require 'dox/dsl/resource'
|
7
|
+
require 'dox/dsl/syntax'
|
8
|
+
require 'dox/entities/action'
|
9
|
+
require 'dox/entities/example'
|
10
|
+
require 'dox/entities/resource_group'
|
11
|
+
require 'dox/entities/resource'
|
12
|
+
require 'dox/errors/file_not_found_error'
|
13
|
+
require 'dox/errors/folder_not_found_error'
|
14
|
+
require 'dox/errors/invalid_action_error'
|
15
|
+
require 'dox/errors/invalid_resource_error'
|
16
|
+
require 'dox/errors/invalid_resource_group_error'
|
17
|
+
require 'dox/formatter'
|
18
|
+
require 'dox/printers/base_printer'
|
19
|
+
require 'dox/printers/action_printer'
|
20
|
+
require 'dox/printers/document_printer'
|
21
|
+
require 'dox/printers/example_printer'
|
22
|
+
require 'dox/printers/resource_group_printer'
|
23
|
+
require 'dox/printers/resource_printer'
|
24
|
+
require 'dox/version'
|
21
25
|
|
22
26
|
|
23
27
|
module Dox
|
data/lib/dox/config.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
module Dox
|
2
2
|
class Config
|
3
3
|
|
4
|
-
|
4
|
+
attr_reader :header_file_path, :desc_folder_path
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
@
|
6
|
+
def header_file_path=(file_path)
|
7
|
+
raise(Errors::FileNotFoundError, file_path) unless File.exists?(file_path)
|
8
|
+
@header_file_path = file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def desc_folder_path=(folder_path)
|
12
|
+
raise(Errors::FolderNotFoundError, folder_path) unless Dir.exists?(folder_path)
|
13
|
+
@desc_folder_path = folder_path
|
9
14
|
end
|
10
15
|
|
11
16
|
end
|
data/lib/dox/dsl/action.rb
CHANGED
@@ -9,26 +9,21 @@ module Dox
|
|
9
9
|
attr_writer :desc
|
10
10
|
attr_writer :params
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
self.name =
|
14
|
-
|
15
|
-
self.path = opts.fetch(:path, nil)
|
16
|
-
self.desc = opts.fetch(:desc, nil)
|
17
|
-
self.params = opts.fetch(:params, nil)
|
18
|
-
end
|
12
|
+
def initialize(name, &block)
|
13
|
+
self.name = name
|
14
|
+
instance_eval(&block) if block_given?
|
19
15
|
|
20
|
-
|
21
|
-
params << signature
|
16
|
+
raise(Dox::Errors::InvalidActionError, 'Action name is required!') if @name.blank?
|
22
17
|
end
|
23
18
|
|
24
19
|
def config
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
{
|
21
|
+
action_name: @name.presence,
|
22
|
+
action_verb: @verb.presence,
|
23
|
+
action_path: @path.presence,
|
24
|
+
action_desc: @desc.presence,
|
25
|
+
action_params: @params.presence
|
26
|
+
}
|
32
27
|
end
|
33
28
|
end
|
34
29
|
end
|
@@ -10,19 +10,16 @@ module Dox
|
|
10
10
|
self.subject = opts.fetch :subject
|
11
11
|
end
|
12
12
|
|
13
|
-
def resource(name
|
14
|
-
self._resource = Resource.new(name
|
15
|
-
_resource.instance_eval(&block)
|
13
|
+
def resource(name, &block)
|
14
|
+
self._resource = Resource.new(name, &block)
|
16
15
|
end
|
17
16
|
|
18
|
-
def action(name
|
19
|
-
self._action = Action.new(name
|
20
|
-
_action.instance_eval(&block)
|
17
|
+
def action(name, &block)
|
18
|
+
self._action = Action.new(name, &block)
|
21
19
|
end
|
22
20
|
|
23
|
-
def group(name
|
24
|
-
self._group = ResourceGroup.new(name: name)
|
25
|
-
_group.instance_eval(&block)
|
21
|
+
def group(name, &block)
|
22
|
+
self._group = ResourceGroup.new(name: name, &block)
|
26
23
|
end
|
27
24
|
|
28
25
|
def config
|
data/lib/dox/dsl/resource.rb
CHANGED
@@ -5,24 +5,28 @@ module Dox
|
|
5
5
|
|
6
6
|
attr_writer :name
|
7
7
|
attr_writer :group
|
8
|
-
attr_writer :desc
|
9
8
|
attr_writer :endpoint
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
self.
|
15
|
-
|
10
|
+
attr_writer :desc
|
11
|
+
|
12
|
+
def initialize(name, &block)
|
13
|
+
self.name = name
|
14
|
+
|
15
|
+
instance_eval(&block)
|
16
|
+
|
17
|
+
raise(Dox::Errors::InvalidResourceError, 'Resource name is required!') if @name.blank?
|
18
|
+
raise(Dox::Errors::InvalidResourceError, 'Resource group is required!') if @group.blank?
|
19
|
+
raise(Dox::Errors::InvalidResourceError, 'Resource endpoint is required!') if @endpoint.blank?
|
16
20
|
end
|
17
21
|
|
18
22
|
def config
|
19
|
-
{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
{
|
24
|
+
resource_name: @name.presence,
|
25
|
+
resource_desc: @desc.presence,
|
26
|
+
resource_group_name: @group.presence,
|
27
|
+
resource_endpoint: @endpoint.presence,
|
28
|
+
apidoc: true
|
29
|
+
}
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -6,17 +6,19 @@ module Dox
|
|
6
6
|
attr_writer :name
|
7
7
|
attr_writer :desc
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
self.name =
|
11
|
-
|
9
|
+
def initialize(name, &block)
|
10
|
+
self.name = name
|
11
|
+
instance_eval(&block) if block_given?
|
12
|
+
|
13
|
+
raise(Dox::Errors::InvalidResourceGroupError, 'Resource group name is required!') if @name.blank?
|
12
14
|
end
|
13
15
|
|
14
16
|
def config
|
15
|
-
{
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
{
|
18
|
+
resource_group_name: @name.presence,
|
19
|
+
resource_group_desc: @desc.presence,
|
20
|
+
apidoc: true
|
21
|
+
}
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/dox/dsl/syntax.rb
CHANGED
@@ -3,30 +3,28 @@ module Dox
|
|
3
3
|
module Syntax
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
6
|
+
def document(subject, &block)
|
7
|
+
documentation = _subjects[subject] = Documentation.new(subject: subject)
|
8
|
+
documentation.instance_eval(&block)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def const_missing(name)
|
12
|
+
documentation = _subjects[infer_subject(name)]
|
13
|
+
return super unless documentation
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
Module.new do
|
16
|
+
define_singleton_method :included do |base|
|
17
|
+
base.metadata.merge! documentation.config
|
20
18
|
end
|
21
19
|
end
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def infer_subject(name)
|
23
|
+
name.to_s.underscore.to_sym
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def _subjects
|
27
|
+
@_subjects ||= {}
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
data/lib/dox/entities/action.rb
CHANGED
@@ -1,18 +1,32 @@
|
|
1
1
|
module Dox
|
2
2
|
module Entities
|
3
3
|
class Action
|
4
|
+
attr_reader :name, :desc, :verb, :path, :uri_params
|
5
|
+
attr_accessor :examples
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(name, details)
|
7
|
+
def initialize(name, details, request)
|
8
|
+
@request = request
|
8
9
|
@name = name
|
9
10
|
@desc = details[:action_desc]
|
10
|
-
@verb = details[:action_verb]
|
11
|
-
@path = details[:action_path]
|
11
|
+
@verb = details[:action_verb] || request.method
|
12
|
+
@path = details[:action_path] || template_path
|
12
13
|
@uri_params = details[:action_params]
|
13
14
|
@examples = []
|
14
15
|
end
|
15
16
|
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :request
|
20
|
+
|
21
|
+
def template_path
|
22
|
+
path_params = request.path_parameters.symbolize_keys.except(:action, :controller)
|
23
|
+
path = request.path.dup
|
24
|
+
path_params.each do |key, value|
|
25
|
+
# /pokemons/1 => pokemons/{id}
|
26
|
+
path.sub!(/\/#{value}(\/|$)/, "/{#{key}}\\1")
|
27
|
+
end
|
28
|
+
path
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
data/lib/dox/entities/example.rb
CHANGED
@@ -19,7 +19,7 @@ module Dox
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def request_identifier
|
22
|
-
|
22
|
+
@desc
|
23
23
|
end
|
24
24
|
|
25
25
|
def response_status
|
@@ -34,15 +34,6 @@ module Dox
|
|
34
34
|
response.body
|
35
35
|
end
|
36
36
|
|
37
|
-
private
|
38
|
-
|
39
|
-
def fullpath
|
40
|
-
if request.query_parameters.present?
|
41
|
-
"#{request.path}?#{request.query_parameters.to_query}"
|
42
|
-
else
|
43
|
-
request.path
|
44
|
-
end
|
45
|
-
end
|
46
37
|
end
|
47
38
|
end
|
48
39
|
end
|
data/lib/dox/formatter.rb
CHANGED
@@ -49,7 +49,7 @@ module Dox
|
|
49
49
|
|
50
50
|
def load_or_save_action_to_resource(resource)
|
51
51
|
action_name = @current_example_data[:action_name]
|
52
|
-
resource.actions[action_name] ||= Entities::Action.new(action_name, @current_example_data)
|
52
|
+
resource.actions[action_name] ||= Entities::Action.new(action_name, @current_example_data, request)
|
53
53
|
end
|
54
54
|
|
55
55
|
def move_example_to_passed
|
@@ -3,7 +3,7 @@ module Dox
|
|
3
3
|
class ActionPrinter < BasePrinter
|
4
4
|
|
5
5
|
def print(action)
|
6
|
-
@output.puts "### #{action.name}\n\n#{print_desc(action.desc)}\n\n"
|
6
|
+
@output.puts "### #{action.name} [#{action.verb} #{action.path}]\n\n#{print_desc(action.desc)}\n\n"
|
7
7
|
|
8
8
|
if action.uri_params.present?
|
9
9
|
@output.puts("+ Parameters\n#{formatted_params(action.uri_params)}")
|
@@ -2,11 +2,8 @@ module Dox
|
|
2
2
|
module Printers
|
3
3
|
class BasePrinter
|
4
4
|
|
5
|
-
attr_reader :descriptions_folder_path
|
6
|
-
|
7
5
|
def initialize(output)
|
8
6
|
@output = output
|
9
|
-
@descriptions_folder_path = Dox.config.desc_folder_path
|
10
7
|
end
|
11
8
|
|
12
9
|
def print
|
@@ -15,17 +12,24 @@ module Dox
|
|
15
12
|
|
16
13
|
private
|
17
14
|
|
18
|
-
def
|
19
|
-
|
15
|
+
def descriptions_folder_path
|
16
|
+
Dox.config.desc_folder_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def print_desc(desc, fullpath = false)
|
20
|
+
return if desc.blank?
|
20
21
|
|
21
22
|
if desc.to_s =~ /.*\.md$/
|
22
|
-
|
23
|
+
if fullpath
|
24
|
+
path = desc
|
25
|
+
else
|
26
|
+
path = descriptions_folder_path.join(desc).to_s
|
27
|
+
end
|
23
28
|
"<!-- include(#{path}) -->"
|
24
29
|
else
|
25
30
|
desc
|
26
31
|
end
|
27
32
|
end
|
28
|
-
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -3,11 +3,7 @@ module Dox
|
|
3
3
|
class ResourcePrinter < BasePrinter
|
4
4
|
|
5
5
|
def print(resource)
|
6
|
-
|
7
|
-
@output.puts "\n## #{resource.name} [#{resource.endpoint}]\n\n#{print_desc(resource.desc)}\n"
|
8
|
-
else
|
9
|
-
@output.puts "## #{resource.name}"
|
10
|
-
end
|
6
|
+
@output.puts "\n## #{resource.name} [#{resource.endpoint}]\n\n#{print_desc(resource.desc)}\n"
|
11
7
|
|
12
8
|
resource.actions.each do |_, action|
|
13
9
|
action_printer.print(action)
|
data/lib/dox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 1.0.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Melita Kokot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-core
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
55
97
|
description:
|
56
98
|
email:
|
57
99
|
- melita.kokot@gmail.com
|
@@ -82,6 +124,11 @@ files:
|
|
82
124
|
- lib/dox/entities/example.rb
|
83
125
|
- lib/dox/entities/resource.rb
|
84
126
|
- lib/dox/entities/resource_group.rb
|
127
|
+
- lib/dox/errors/file_not_found_error.rb
|
128
|
+
- lib/dox/errors/folder_not_found_error.rb
|
129
|
+
- lib/dox/errors/invalid_action_error.rb
|
130
|
+
- lib/dox/errors/invalid_resource_error.rb
|
131
|
+
- lib/dox/errors/invalid_resource_group_error.rb
|
85
132
|
- lib/dox/formatter.rb
|
86
133
|
- lib/dox/printers/action_printer.rb
|
87
134
|
- lib/dox/printers/base_printer.rb
|
@@ -106,9 +153,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
153
|
version: '0'
|
107
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
155
|
requirements:
|
109
|
-
- - "
|
156
|
+
- - ">"
|
110
157
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
158
|
+
version: 1.3.1
|
112
159
|
requirements: []
|
113
160
|
rubyforge_project:
|
114
161
|
rubygems_version: 2.5.1
|