betterdocs 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -3
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/betterdocs.gemspec +12 -9
- data/lib/betterdocs.rb +2 -0
- data/lib/betterdocs/dsl/controller/action.rb +7 -6
- data/lib/betterdocs/dsl/json_params/param.rb +5 -1
- data/lib/betterdocs/dsl/result/property.rb +4 -1
- data/lib/betterdocs/global.rb +83 -28
- data/lib/betterdocs/json_time_with_zone.rb +7 -0
- data/lib/betterdocs/railtie.rb +7 -0
- data/lib/betterdocs/version.rb +1 -1
- data/spec/assets/app/controllers/api/foos_controller.rb +4 -0
- data/spec/assets/config/betterdocs.yml +16 -0
- data/spec/global_spec.rb +189 -0
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db95985948a6ea7f7ef6fedb7057c9403c51629
|
4
|
+
data.tar.gz: 6a6bb0a36b82481e1e7451e533423ab00d765d95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6515adc1cf8a4faeb58e15acc26dc7129f5658b990cd2bf42506f1fb6508df219dbf87645772cbbd7cb2373c0272d35ba1ba05830a8246f7f9b9ac050f3c7243
|
7
|
+
data.tar.gz: 7914bad33f84a4a36aff48cb2173ab89d47b8d1c64dcb72143ee68bc4c776d200590eb9635265232dfc249b566a2930227760bd1b0c7a8b8f60b36d75b56ee59
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -11,13 +11,15 @@ GemHadar do
|
|
11
11
|
description "This library provides tools to generate API documention for a web site's REST-ful JSON API."
|
12
12
|
test_dir 'spec'
|
13
13
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
14
|
-
'.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc',
|
14
|
+
'.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc',
|
15
|
+
'.bundle', '.byebug_history', 'errors.lst'
|
15
16
|
readme 'README.md'
|
16
17
|
title "#{name.camelize} -- "
|
17
18
|
|
18
19
|
dependency 'tins', '~>1.3', '>=1.3.5'
|
19
20
|
dependency 'rails', '>=3', '<5'
|
20
21
|
dependency 'term-ansicolor', '~>1.3'
|
22
|
+
dependency 'complex_config', '~>0.5'
|
21
23
|
development_dependency 'simplecov'
|
22
24
|
development_dependency 'rspec'
|
23
25
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/betterdocs.gemspec
CHANGED
@@ -1,48 +1,51 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterdocs 0.
|
2
|
+
# stub: betterdocs 0.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "betterdocs"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.3.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["betterplace Developers"]
|
11
|
-
s.date = "2016-
|
11
|
+
s.date = "2016-06-13"
|
12
12
|
s.description = "This library provides tools to generate API documention for a web site's REST-ful JSON API."
|
13
13
|
s.email = "developers@betterplace.org"
|
14
|
-
s.extra_rdoc_files = ["README.md", "lib/betterdocs.rb", "lib/betterdocs/controller_collector.rb", "lib/betterdocs/dsl.rb", "lib/betterdocs/dsl/common.rb", "lib/betterdocs/dsl/controller.rb", "lib/betterdocs/dsl/controller/action.rb", "lib/betterdocs/dsl/controller/action/param.rb", "lib/betterdocs/dsl/controller/action/response.rb", "lib/betterdocs/dsl/controller/controller.rb", "lib/betterdocs/dsl/controller/controller_base.rb", "lib/betterdocs/dsl/json_params.rb", "lib/betterdocs/dsl/json_params/param.rb", "lib/betterdocs/dsl/json_type_mapper.rb", "lib/betterdocs/dsl/naming.rb", "lib/betterdocs/dsl/representer.rb", "lib/betterdocs/dsl/result.rb", "lib/betterdocs/dsl/result/collection_property.rb", "lib/betterdocs/dsl/result/link.rb", "lib/betterdocs/dsl/result/property.rb", "lib/betterdocs/generator/config_shortcuts.rb", "lib/betterdocs/generator/markdown.rb", "lib/betterdocs/global.rb", "lib/betterdocs/json_params_representer.rb", "lib/betterdocs/json_params_representer_collector.rb", "lib/betterdocs/mix_into_controller.rb", "lib/betterdocs/rake_tasks.rb", "lib/betterdocs/representer.rb", "lib/betterdocs/result_representer.rb", "lib/betterdocs/result_representer_collector.rb", "lib/betterdocs/section.rb", "lib/betterdocs/version.rb"]
|
15
|
-
s.files = [".codeclimate.yml", ".gitignore", ".rspec", ".travis.yml", "COPYING", "Gemfile", "LICENSE", "README.md", "Rakefile", "VERSION", "betterdocs.gemspec", "lib/betterdocs.rb", "lib/betterdocs/controller_collector.rb", "lib/betterdocs/dsl.rb", "lib/betterdocs/dsl/common.rb", "lib/betterdocs/dsl/controller.rb", "lib/betterdocs/dsl/controller/action.rb", "lib/betterdocs/dsl/controller/action/param.rb", "lib/betterdocs/dsl/controller/action/response.rb", "lib/betterdocs/dsl/controller/controller.rb", "lib/betterdocs/dsl/controller/controller_base.rb", "lib/betterdocs/dsl/json_params.rb", "lib/betterdocs/dsl/json_params/param.rb", "lib/betterdocs/dsl/json_type_mapper.rb", "lib/betterdocs/dsl/naming.rb", "lib/betterdocs/dsl/representer.rb", "lib/betterdocs/dsl/result.rb", "lib/betterdocs/dsl/result/collection_property.rb", "lib/betterdocs/dsl/result/link.rb", "lib/betterdocs/dsl/result/property.rb", "lib/betterdocs/generator/config_shortcuts.rb", "lib/betterdocs/generator/markdown.rb", "lib/betterdocs/generator/markdown/templates/README.md.erb", "lib/betterdocs/generator/markdown/templates/section.md.erb", "lib/betterdocs/global.rb", "lib/betterdocs/json_params_representer.rb", "lib/betterdocs/json_params_representer_collector.rb", "lib/betterdocs/mix_into_controller.rb", "lib/betterdocs/rake_tasks.rb", "lib/betterdocs/representer.rb", "lib/betterdocs/result_representer.rb", "lib/betterdocs/result_representer_collector.rb", "lib/betterdocs/section.rb", "lib/betterdocs/tasks/doc.rake", "lib/betterdocs/version.rb", "spec/controller_dsl_spec.rb", "spec/generator/markdown_spec.rb", "spec/json_params_representer_spec.rb", "spec/json_type_mapper_spec.rb", "spec/result_representer_dsl_spec.rb", "spec/result_representer_spec.rb", "spec/spec_helper.rb"]
|
14
|
+
s.extra_rdoc_files = ["README.md", "lib/betterdocs.rb", "lib/betterdocs/controller_collector.rb", "lib/betterdocs/dsl.rb", "lib/betterdocs/dsl/common.rb", "lib/betterdocs/dsl/controller.rb", "lib/betterdocs/dsl/controller/action.rb", "lib/betterdocs/dsl/controller/action/param.rb", "lib/betterdocs/dsl/controller/action/response.rb", "lib/betterdocs/dsl/controller/controller.rb", "lib/betterdocs/dsl/controller/controller_base.rb", "lib/betterdocs/dsl/json_params.rb", "lib/betterdocs/dsl/json_params/param.rb", "lib/betterdocs/dsl/json_type_mapper.rb", "lib/betterdocs/dsl/naming.rb", "lib/betterdocs/dsl/representer.rb", "lib/betterdocs/dsl/result.rb", "lib/betterdocs/dsl/result/collection_property.rb", "lib/betterdocs/dsl/result/link.rb", "lib/betterdocs/dsl/result/property.rb", "lib/betterdocs/generator/config_shortcuts.rb", "lib/betterdocs/generator/markdown.rb", "lib/betterdocs/global.rb", "lib/betterdocs/json_params_representer.rb", "lib/betterdocs/json_params_representer_collector.rb", "lib/betterdocs/json_time_with_zone.rb", "lib/betterdocs/mix_into_controller.rb", "lib/betterdocs/railtie.rb", "lib/betterdocs/rake_tasks.rb", "lib/betterdocs/representer.rb", "lib/betterdocs/result_representer.rb", "lib/betterdocs/result_representer_collector.rb", "lib/betterdocs/section.rb", "lib/betterdocs/version.rb"]
|
15
|
+
s.files = [".codeclimate.yml", ".gitignore", ".rspec", ".travis.yml", "COPYING", "Gemfile", "LICENSE", "README.md", "Rakefile", "VERSION", "betterdocs.gemspec", "lib/betterdocs.rb", "lib/betterdocs/controller_collector.rb", "lib/betterdocs/dsl.rb", "lib/betterdocs/dsl/common.rb", "lib/betterdocs/dsl/controller.rb", "lib/betterdocs/dsl/controller/action.rb", "lib/betterdocs/dsl/controller/action/param.rb", "lib/betterdocs/dsl/controller/action/response.rb", "lib/betterdocs/dsl/controller/controller.rb", "lib/betterdocs/dsl/controller/controller_base.rb", "lib/betterdocs/dsl/json_params.rb", "lib/betterdocs/dsl/json_params/param.rb", "lib/betterdocs/dsl/json_type_mapper.rb", "lib/betterdocs/dsl/naming.rb", "lib/betterdocs/dsl/representer.rb", "lib/betterdocs/dsl/result.rb", "lib/betterdocs/dsl/result/collection_property.rb", "lib/betterdocs/dsl/result/link.rb", "lib/betterdocs/dsl/result/property.rb", "lib/betterdocs/generator/config_shortcuts.rb", "lib/betterdocs/generator/markdown.rb", "lib/betterdocs/generator/markdown/templates/README.md.erb", "lib/betterdocs/generator/markdown/templates/section.md.erb", "lib/betterdocs/global.rb", "lib/betterdocs/json_params_representer.rb", "lib/betterdocs/json_params_representer_collector.rb", "lib/betterdocs/json_time_with_zone.rb", "lib/betterdocs/mix_into_controller.rb", "lib/betterdocs/railtie.rb", "lib/betterdocs/rake_tasks.rb", "lib/betterdocs/representer.rb", "lib/betterdocs/result_representer.rb", "lib/betterdocs/result_representer_collector.rb", "lib/betterdocs/section.rb", "lib/betterdocs/tasks/doc.rake", "lib/betterdocs/version.rb", "spec/assets/app/controllers/api/foos_controller.rb", "spec/assets/config/betterdocs.yml", "spec/controller_dsl_spec.rb", "spec/generator/markdown_spec.rb", "spec/global_spec.rb", "spec/json_params_representer_spec.rb", "spec/json_type_mapper_spec.rb", "spec/result_representer_dsl_spec.rb", "spec/result_representer_spec.rb", "spec/spec_helper.rb"]
|
16
16
|
s.homepage = "http://github.com/betterplace/betterdocs"
|
17
17
|
s.rdoc_options = ["--title", "Betterdocs -- ", "--main", "README.md"]
|
18
18
|
s.rubygems_version = "2.5.1"
|
19
19
|
s.summary = "Betterplace API documentation library"
|
20
|
-
s.test_files = ["spec/controller_dsl_spec.rb", "spec/generator/markdown_spec.rb", "spec/json_params_representer_spec.rb", "spec/json_type_mapper_spec.rb", "spec/result_representer_dsl_spec.rb", "spec/result_representer_spec.rb", "spec/spec_helper.rb"]
|
20
|
+
s.test_files = ["spec/assets/app/controllers/api/foos_controller.rb", "spec/controller_dsl_spec.rb", "spec/generator/markdown_spec.rb", "spec/global_spec.rb", "spec/json_params_representer_spec.rb", "spec/json_type_mapper_spec.rb", "spec/result_representer_dsl_spec.rb", "spec/result_representer_spec.rb", "spec/spec_helper.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 4
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<gem_hadar>, ["~> 1.
|
26
|
+
s.add_development_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
27
27
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
29
29
|
s.add_runtime_dependency(%q<tins>, [">= 1.3.5", "~> 1.3"])
|
30
30
|
s.add_runtime_dependency(%q<rails>, ["< 5", ">= 3"])
|
31
31
|
s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.3"])
|
32
|
+
s.add_runtime_dependency(%q<complex_config>, ["~> 0.5"])
|
32
33
|
else
|
33
|
-
s.add_dependency(%q<gem_hadar>, ["~> 1.
|
34
|
+
s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
34
35
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
35
36
|
s.add_dependency(%q<rspec>, [">= 0"])
|
36
37
|
s.add_dependency(%q<tins>, [">= 1.3.5", "~> 1.3"])
|
37
38
|
s.add_dependency(%q<rails>, ["< 5", ">= 3"])
|
38
39
|
s.add_dependency(%q<term-ansicolor>, ["~> 1.3"])
|
40
|
+
s.add_dependency(%q<complex_config>, ["~> 0.5"])
|
39
41
|
end
|
40
42
|
else
|
41
|
-
s.add_dependency(%q<gem_hadar>, ["~> 1.
|
43
|
+
s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
|
42
44
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
43
45
|
s.add_dependency(%q<rspec>, [">= 0"])
|
44
46
|
s.add_dependency(%q<tins>, [">= 1.3.5", "~> 1.3"])
|
45
47
|
s.add_dependency(%q<rails>, ["< 5", ">= 3"])
|
46
48
|
s.add_dependency(%q<term-ansicolor>, ["~> 1.3"])
|
49
|
+
s.add_dependency(%q<complex_config>, ["~> 0.5"])
|
47
50
|
end
|
48
51
|
end
|
data/lib/betterdocs.rb
CHANGED
@@ -94,12 +94,13 @@ class Betterdocs::Dsl::Controller::Action < Betterdocs::Dsl::Controller::Control
|
|
94
94
|
|
95
95
|
def url
|
96
96
|
url_params = params.select { |_, param| param.use_in_url? }
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
url_params = {
|
98
|
+
controller: controller.name.underscore.sub(/_controller\z/, ''),
|
99
|
+
action: action,
|
100
|
+
} | url_params | Betterdocs::Global.config.api_url_options
|
101
|
+
Betterdocs.rails.application.routes.url_for(url_params)
|
102
|
+
rescue ActionController::UrlGenerationError => e
|
103
|
+
raise e, "Could not generate URL for parameters #{url_params}. Check your param definitions!"
|
103
104
|
end
|
104
105
|
|
105
106
|
def request
|
@@ -22,7 +22,11 @@ class Betterdocs::Dsl::JsonParams::Param < Betterdocs::Dsl::Representer
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def compute_value(object)
|
25
|
-
object.__send__(name)
|
25
|
+
value = object.__send__(name)
|
26
|
+
if ActiveSupport::TimeWithZone === value
|
27
|
+
value.extend Betterdocs::JsonTimeWithZone
|
28
|
+
end
|
29
|
+
value
|
26
30
|
end
|
27
31
|
|
28
32
|
def add_to_collector(collector)
|
@@ -40,8 +40,11 @@ class Betterdocs::Dsl::Result::Property < Betterdocs::Dsl::Representer
|
|
40
40
|
|
41
41
|
def compute_value(object)
|
42
42
|
value = object.__send__(name)
|
43
|
-
|
43
|
+
value.nil? and return
|
44
|
+
if represent_with
|
44
45
|
represent_with.hashify(value)
|
46
|
+
elsif ActiveSupport::TimeWithZone === value
|
47
|
+
value.extend Betterdocs::JsonTimeWithZone
|
45
48
|
else
|
46
49
|
value
|
47
50
|
end
|
data/lib/betterdocs/global.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'complex_config/rude'
|
2
|
+
|
1
3
|
module Betterdocs
|
2
4
|
module Global
|
3
5
|
class << self
|
@@ -7,8 +9,29 @@ module Betterdocs
|
|
7
9
|
|
8
10
|
dsl_accessor :api_prefix, 'api' # Prefix that denotes the api namespace in URLs
|
9
11
|
|
12
|
+
dsl_accessor :controllers_dir do
|
13
|
+
Betterdocs.rails.root.join('app/controllers')
|
14
|
+
end
|
15
|
+
|
10
16
|
dsl_accessor :api_controllers do
|
11
|
-
Dir[
|
17
|
+
Dir[controllers_dir + "#{api_prefix}/**/*_controller.rb"]
|
18
|
+
end
|
19
|
+
|
20
|
+
private def handle_url(prefix, url)
|
21
|
+
if url
|
22
|
+
uri = URI.parse(url)
|
23
|
+
__send__("#{prefix}_protocol", uri.scheme || 'http')
|
24
|
+
host = uri.host || 'localhost'
|
25
|
+
port = uri.port and host = "#{host}:#{port}"
|
26
|
+
platform_host host
|
27
|
+
__send__("#{prefix}_host", host)
|
28
|
+
else
|
29
|
+
[ __send__("#{prefix}_protocol"), __send__("#{prefix}_host") ] * '://'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def platform_url(url = nil)
|
34
|
+
handle_url(:platform, url)
|
12
35
|
end
|
13
36
|
|
14
37
|
dsl_accessor :platform_protocol, 'http' # Not used atm
|
@@ -19,17 +42,25 @@ module Betterdocs
|
|
19
42
|
|
20
43
|
dsl_accessor :api_host do platform_host end # Hostname of the API (eventuallly with port number)
|
21
44
|
|
45
|
+
def api_url(url = nil)
|
46
|
+
handle_url(:api, url)
|
47
|
+
end
|
48
|
+
|
22
49
|
dsl_accessor :asset_protocol do platform_protocol end # Reserved
|
23
50
|
|
24
51
|
dsl_accessor :asset_host do platform_host end # Rails asset host
|
25
52
|
|
53
|
+
def asset_url(url = nil)
|
54
|
+
handle_url(:asset, url)
|
55
|
+
end
|
56
|
+
|
26
57
|
dsl_accessor :api_default_format, 'json'
|
27
58
|
|
28
59
|
def api_base_url
|
29
60
|
"#{api_protocol}://#{api_host}/#{api_prefix}"
|
30
61
|
end
|
31
62
|
|
32
|
-
|
63
|
+
def api_url_options
|
33
64
|
{ protocol: api_protocol, host: api_host, format: api_default_format }
|
34
65
|
end
|
35
66
|
|
@@ -41,20 +72,31 @@ module Betterdocs
|
|
41
72
|
|
42
73
|
dsl_accessor :ignore do [] end # All lines of the .gitignore file as an array
|
43
74
|
|
44
|
-
def assets
|
75
|
+
def assets=(hash)
|
76
|
+
@assets&.clear
|
77
|
+
assets(hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
def assets(hash = nil)
|
45
81
|
@assets ||= {}
|
82
|
+
if hash
|
83
|
+
hash.each do |path, to|
|
84
|
+
asset path, to: to
|
85
|
+
end
|
86
|
+
end
|
87
|
+
@assets
|
46
88
|
end
|
47
|
-
private :assets
|
48
89
|
|
49
90
|
# Defines an asset for the file at +path+. If +to+ was given it will be
|
50
91
|
# copied to this path (it includes the basename) below
|
51
92
|
# +templates_directory+ in the output, otherwise it will be copied
|
52
93
|
# directly to +templates_directory+.
|
53
94
|
def asset(path, to: :root)
|
95
|
+
@assets ||= {}
|
54
96
|
if destination = to.ask_and_send(:to_str)
|
55
|
-
assets[path.to_s] = destination
|
97
|
+
@assets[path.to_s] = destination
|
56
98
|
elsif to == :root
|
57
|
-
assets[path.to_s] = to
|
99
|
+
@assets[path.to_s] = to
|
58
100
|
else
|
59
101
|
raise ArgumentError, "keyword argument to needs to be a string or :root"
|
60
102
|
end
|
@@ -63,20 +105,31 @@ module Betterdocs
|
|
63
105
|
# Maps the assets original source path to its destination path in the
|
64
106
|
# output by yielding to every asset's source/destination pair.
|
65
107
|
def each_asset
|
66
|
-
for path in assets
|
108
|
+
for (path, destination) in assets
|
67
109
|
path = path.to_s
|
68
|
-
if destination
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
yield path, File.join(output_directory.to_s, destination.to_str)
|
73
|
-
end
|
110
|
+
if destination == :root
|
111
|
+
yield path, File.join(output_directory.to_s, File.basename(path))
|
112
|
+
else
|
113
|
+
yield path, File.join(output_directory.to_s, destination.to_str)
|
74
114
|
end
|
75
115
|
end
|
76
116
|
end
|
77
117
|
|
78
|
-
def
|
79
|
-
|
118
|
+
def configuration_file
|
119
|
+
complex_config.betterdocs
|
120
|
+
rescue ComplexConfig::ConfigurationFileMissing
|
121
|
+
end
|
122
|
+
|
123
|
+
def configure_via_yaml(config)
|
124
|
+
config.each do |name, value|
|
125
|
+
__send__(name, value.dup)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def configure(config = configuration_file, &block)
|
130
|
+
Betterdocs.rails.env.development? or return
|
131
|
+
config and configure_via_yaml(config)
|
132
|
+
block and instance_eval(&block)
|
80
133
|
self
|
81
134
|
end
|
82
135
|
|
@@ -89,19 +142,21 @@ module Betterdocs
|
|
89
142
|
end
|
90
143
|
|
91
144
|
def all_docs
|
92
|
-
Dir
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
145
|
+
Dir.chdir controllers_dir do
|
146
|
+
Dir["#{api_prefix}/**/*_controller.rb"].each_with_object([]) do |cf, all|
|
147
|
+
controller_name = cf.sub(/\.rb$/, '').camelcase
|
148
|
+
controller =
|
149
|
+
begin
|
150
|
+
controller_name.constantize
|
151
|
+
rescue NameError => e
|
152
|
+
STDERR.puts "Skipping #{cf.inspect}, #{e.class}: #{e}"
|
153
|
+
next
|
154
|
+
end
|
155
|
+
if docs = controller.ask_and_send(:docs)
|
156
|
+
all << docs
|
157
|
+
else
|
158
|
+
STDERR.puts "Skipping #{cf.inspect}, #{controller_name.inspect} doesn't respond to :docs method"
|
100
159
|
end
|
101
|
-
if docs = controller.ask_and_send(:docs)
|
102
|
-
all << docs
|
103
|
-
else
|
104
|
-
STDERR.puts "Skipping #{cf.inspect}, #{controller_name.inspect} doesn't respond to :docs method"
|
105
160
|
end
|
106
161
|
end
|
107
162
|
end
|
@@ -112,7 +167,7 @@ module Betterdocs
|
|
112
167
|
|
113
168
|
def sections
|
114
169
|
@sections and return @sections
|
115
|
-
Dir.chdir
|
170
|
+
Dir.chdir controllers_dir do
|
116
171
|
actions.each_with_object(@sections = {}) do |action, sections|
|
117
172
|
sections[action.section] ||= Section.new(action.section)
|
118
173
|
sections[action.section] << action
|
data/lib/betterdocs/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
project_name: My Example Project
|
3
|
+
api_host: api.example.com:3000
|
4
|
+
api_protocol: https
|
5
|
+
platform_host: site.example.com
|
6
|
+
platform_protocol: http
|
7
|
+
asset_host: "https://assets.example.com"
|
8
|
+
api_prefix: api
|
9
|
+
templates_directory: documentation/templates
|
10
|
+
output_directory: api_docs
|
11
|
+
assets:
|
12
|
+
'app/views/api_v4/documentation/assets/CHANGELOG.md': :root
|
13
|
+
'app/assets/images/logos/logo.png': images/logo.png
|
14
|
+
ignore:
|
15
|
+
- .DS_Store
|
16
|
+
publish_git: 'git@github.com:foo/bar.git'
|
data/spec/global_spec.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
RSpec.describe Betterdocs::Global do
|
5
|
+
let :rails do
|
6
|
+
double(
|
7
|
+
root: Pathname.pwd + 'spec/assets',
|
8
|
+
env: double(development?: true)
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(Betterdocs).to receive(:rails).and_return rails
|
14
|
+
ComplexConfig::Provider.config_dir = 'spec/assets/config'
|
15
|
+
Betterdocs::Global.configure
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has a project name' do
|
19
|
+
expect(Betterdocs::Global.project_name).to eq 'My Example Project'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'uses an api prefix' do
|
23
|
+
expect(Betterdocs::Global.api_prefix).to eq 'api'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns all api controllers via wild matching' do
|
27
|
+
expect(Betterdocs::Global.api_controllers.size).to eq 1
|
28
|
+
expect(Betterdocs::Global.api_controllers.last).to end_with\
|
29
|
+
'spec/assets/app/controllers/api/foos_controller.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'platform url' do
|
33
|
+
before do
|
34
|
+
Betterdocs::Global.platform_protocol 'http'
|
35
|
+
Betterdocs::Global.platform_host 'localhost:3000'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'has default platform_url' do
|
39
|
+
expect(Betterdocs::Global.platform_url).to eq 'http://localhost:3000'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can parse platform_url' do
|
43
|
+
Betterdocs::Global.platform_url 'https://foo.bar:1234'
|
44
|
+
expect(Betterdocs::Global.platform_url).to eq 'https://foo.bar:1234'
|
45
|
+
Betterdocs::Global.platform_url 'https://foo.bar'
|
46
|
+
expect(Betterdocs::Global.platform_url).to eq 'https://foo.bar:443'
|
47
|
+
Betterdocs::Global.platform_url 'http://foo.bar'
|
48
|
+
expect(Betterdocs::Global.platform_url).to eq 'http://foo.bar:80'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'has platform_protocol' do
|
52
|
+
expect(Betterdocs::Global.platform_protocol).to eq 'http'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'has platform_host' do
|
56
|
+
expect(Betterdocs::Global.platform_host).to eq 'localhost:3000'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'api url' do
|
61
|
+
before do
|
62
|
+
Betterdocs::Global.api_protocol 'http'
|
63
|
+
Betterdocs::Global.api_host 'localhost:3000'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'has default api_url' do
|
67
|
+
expect(Betterdocs::Global.api_url).to eq 'http://localhost:3000'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'can parse api_url' do
|
71
|
+
Betterdocs::Global.api_url 'https://foo.bar:1234'
|
72
|
+
expect(Betterdocs::Global.api_url).to eq 'https://foo.bar:1234'
|
73
|
+
Betterdocs::Global.api_url 'https://foo.bar'
|
74
|
+
expect(Betterdocs::Global.api_url).to eq 'https://foo.bar:443'
|
75
|
+
Betterdocs::Global.api_url 'http://foo.bar'
|
76
|
+
expect(Betterdocs::Global.api_url).to eq 'http://foo.bar:80'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'has api_protocol' do
|
80
|
+
expect(Betterdocs::Global.api_protocol).to eq 'http'
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'has api_host' do
|
84
|
+
expect(Betterdocs::Global.api_host).to eq 'localhost:3000'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can return api_base_url' do
|
88
|
+
Betterdocs::Global.api_url 'https://foo.bar:1234'
|
89
|
+
expect(Betterdocs::Global.api_base_url).to eq 'https://foo.bar:1234/api'
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'asset url' do
|
95
|
+
before do
|
96
|
+
Betterdocs::Global.asset_protocol 'http'
|
97
|
+
Betterdocs::Global.asset_host 'localhost:3000'
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'has default asset_url' do
|
101
|
+
expect(Betterdocs::Global.asset_url).to eq 'http://localhost:3000'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'can parse asset_url' do
|
105
|
+
Betterdocs::Global.asset_url 'https://foo.bar:1234'
|
106
|
+
expect(Betterdocs::Global.asset_url).to eq 'https://foo.bar:1234'
|
107
|
+
Betterdocs::Global.asset_url 'https://foo.bar'
|
108
|
+
expect(Betterdocs::Global.asset_url).to eq 'https://foo.bar:443'
|
109
|
+
Betterdocs::Global.asset_url 'http://foo.bar'
|
110
|
+
expect(Betterdocs::Global.asset_url).to eq 'http://foo.bar:80'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'has asset_protocol' do
|
114
|
+
expect(Betterdocs::Global.asset_protocol).to eq 'http'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'has asset_host' do
|
118
|
+
expect(Betterdocs::Global.asset_host).to eq 'localhost:3000'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'has api_default_format' do
|
123
|
+
expect(Betterdocs::Global.api_default_format).to eq 'json'
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'can return api_url_options' do
|
127
|
+
expect(Betterdocs::Global.api_url_options).to eq(
|
128
|
+
protocol: "https",
|
129
|
+
host: "api.example.com:3000",
|
130
|
+
format: "json"
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'has templates_directory' do
|
135
|
+
expect(Betterdocs::Global.templates_directory).to\
|
136
|
+
eq 'documentation/templates'
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'has output_directory' do
|
140
|
+
expect(Betterdocs::Global.output_directory).to eq 'api_docs'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'has publish_git' do
|
144
|
+
expect(Betterdocs::Global.publish_git).to eq 'git@github.com:foo/bar.git'
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'can ignore in the git repo' do
|
148
|
+
expect(Betterdocs::Global.ignore).to eq %w[ .DS_Store ]
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'assets' do
|
152
|
+
it 'can have assets' do
|
153
|
+
expect(Betterdocs::Global.assets).to be_a Hash
|
154
|
+
expect(Betterdocs::Global.assets).not_to be_empty
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'can set assets' do
|
158
|
+
begin
|
159
|
+
Betterdocs::Global.assets = { foo: 'bar' }
|
160
|
+
expect(Betterdocs::Global.assets).to eq({ 'foo' => 'bar' })
|
161
|
+
Betterdocs::Global.asset :bar, to: 'baz'
|
162
|
+
expect(Betterdocs::Global.assets).to eq({ 'foo' => 'bar', 'bar' => 'baz' })
|
163
|
+
Betterdocs::Global.asset 'quux'
|
164
|
+
expect(Betterdocs::Global.assets).to eq({ 'foo' => 'bar', 'bar' => 'baz', 'quux' => :root })
|
165
|
+
ensure
|
166
|
+
Betterdocs::Global.assets.clear
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'can iterate over assets' do
|
171
|
+
expect { |b| Betterdocs::Global.each_asset(&b) }.to\
|
172
|
+
yield_successive_args(
|
173
|
+
["app/views/api_v4/documentation/assets/CHANGELOG.md", "api_docs/CHANGELOG.md"],
|
174
|
+
["app/assets/images/logos/logo.png", "api_docs/images/logo.png"]
|
175
|
+
)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'has a default configuration_file' do
|
180
|
+
expect(Betterdocs::Global.configuration_file).to\
|
181
|
+
be_a ComplexConfig::Settings
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'all_docs' do
|
185
|
+
load 'spec/assets/app/controllers/api/foos_controller.rb'
|
186
|
+
expect(Api::FoosController).to receive(:docs).and_return :foo
|
187
|
+
expect(Betterdocs::Global.all_docs).to eq [ :foo ]
|
188
|
+
end
|
189
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.7.1
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.7.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,20 @@ dependencies:
|
|
106
106
|
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '1.3'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: complex_config
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0.5'
|
116
|
+
type: :runtime
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0.5'
|
109
123
|
description: This library provides tools to generate API documention for a web site's
|
110
124
|
REST-ful JSON API.
|
111
125
|
email: developers@betterplace.org
|
@@ -137,7 +151,9 @@ extra_rdoc_files:
|
|
137
151
|
- lib/betterdocs/global.rb
|
138
152
|
- lib/betterdocs/json_params_representer.rb
|
139
153
|
- lib/betterdocs/json_params_representer_collector.rb
|
154
|
+
- lib/betterdocs/json_time_with_zone.rb
|
140
155
|
- lib/betterdocs/mix_into_controller.rb
|
156
|
+
- lib/betterdocs/railtie.rb
|
141
157
|
- lib/betterdocs/rake_tasks.rb
|
142
158
|
- lib/betterdocs/representer.rb
|
143
159
|
- lib/betterdocs/result_representer.rb
|
@@ -182,7 +198,9 @@ files:
|
|
182
198
|
- lib/betterdocs/global.rb
|
183
199
|
- lib/betterdocs/json_params_representer.rb
|
184
200
|
- lib/betterdocs/json_params_representer_collector.rb
|
201
|
+
- lib/betterdocs/json_time_with_zone.rb
|
185
202
|
- lib/betterdocs/mix_into_controller.rb
|
203
|
+
- lib/betterdocs/railtie.rb
|
186
204
|
- lib/betterdocs/rake_tasks.rb
|
187
205
|
- lib/betterdocs/representer.rb
|
188
206
|
- lib/betterdocs/result_representer.rb
|
@@ -190,8 +208,11 @@ files:
|
|
190
208
|
- lib/betterdocs/section.rb
|
191
209
|
- lib/betterdocs/tasks/doc.rake
|
192
210
|
- lib/betterdocs/version.rb
|
211
|
+
- spec/assets/app/controllers/api/foos_controller.rb
|
212
|
+
- spec/assets/config/betterdocs.yml
|
193
213
|
- spec/controller_dsl_spec.rb
|
194
214
|
- spec/generator/markdown_spec.rb
|
215
|
+
- spec/global_spec.rb
|
195
216
|
- spec/json_params_representer_spec.rb
|
196
217
|
- spec/json_type_mapper_spec.rb
|
197
218
|
- spec/result_representer_dsl_spec.rb
|
@@ -225,8 +246,10 @@ signing_key:
|
|
225
246
|
specification_version: 4
|
226
247
|
summary: Betterplace API documentation library
|
227
248
|
test_files:
|
249
|
+
- spec/assets/app/controllers/api/foos_controller.rb
|
228
250
|
- spec/controller_dsl_spec.rb
|
229
251
|
- spec/generator/markdown_spec.rb
|
252
|
+
- spec/global_spec.rb
|
230
253
|
- spec/json_params_representer_spec.rb
|
231
254
|
- spec/json_type_mapper_spec.rb
|
232
255
|
- spec/result_representer_dsl_spec.rb
|