yard-api 0.3.1 → 0.3.2

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: 57a2787c3ce762f1d68efe7aba2d1407443a7fb0
4
- data.tar.gz: 9abaebf7932f1dffbaa3f84fe8c43cce1cf7c266
3
+ metadata.gz: da18e5c099f63291990732b6b8641f9b3d6588a4
4
+ data.tar.gz: 697447ab5b213e1322e37888fd4ef9bc49c89fef
5
5
  SHA512:
6
- metadata.gz: b41c9b4518e06b4a772b846004c9f8b849526091604e6d3051d855d14caaf6ebc5ec34b557e83c4b1edd3e9b60242c670d4e345204a18a42b80a397a0930c17a
7
- data.tar.gz: ec814f8e0e70e29a2ec528f08a1f434def22383fc41f159e25cd31eda57cd67496b1b0f8e4565c424c59125a9a75b2d6296ae33235b19a2f0ca827e027b5c98c
6
+ metadata.gz: 2912e45619e1199eebb28422298e380155795978e62966c168af494e3ce98e058ef6f748495df012359692033573c213be34d7e2da5589837d5090d46bee5f91
7
+ data.tar.gz: a721d465aa53ab6e817bbb7485c9f75dff2ce6c193c3a8a1746115393b963bd97d132c05cdcd9bdc1bb38aab1af54a429333689d665d9a5b1a31069399743b19
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module APIPlugin
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -23,6 +23,8 @@ module YARD::APIPlugin
23
23
  config['debug'] ||= ENV['DEBUG']
24
24
  config['verbose'] ||= ENV['VERBOSE']
25
25
 
26
+ config['output'].sub!('$format', config['format'])
27
+
26
28
  set_option('template', 'api')
27
29
  set_option('no-yardopts')
28
30
  set_option('no-document')
@@ -5,6 +5,7 @@ include YARD::Templates::Helpers::FilterHelper
5
5
  include YARD::Templates::Helpers::HtmlHelper
6
6
 
7
7
  RouteHelper = YARD::Templates::Helpers::RouteHelper
8
+ ArgumentTag = YARD::APIPlugin::Tags::ArgumentTag
8
9
 
9
10
  def init
10
11
  resources = options[:objects]
@@ -15,17 +16,17 @@ end
15
16
 
16
17
  def serialize_resource(resource, controllers)
17
18
  Templates::Engine.with_serializer("#{topicize resource}.json", options[:serializer]) do
18
- JSON.pretty_generate({
19
- object: resource,
20
- api_objects: controllers.map do |controller|
21
- dump_api_objects(controller)
22
- end.flatten,
23
- methods: method_details_list(controllers)
24
- })
19
+ {
20
+ id: topicize(resource),
21
+ title: resource,
22
+ text: controllers.map { |c| c.docstring }.join("\n\n"),
23
+ objects: controllers.map { |c| dump_controller_objects(c) }.flatten,
24
+ endpoints: dump_resource_endpoints(controllers)
25
+ }.to_json
25
26
  end
26
27
  end
27
28
 
28
- def method_details_list(controllers)
29
+ def dump_resource_endpoints(controllers)
29
30
  meths = controllers.map do |controller|
30
31
  controller.meths(:inherited => false, :included => false)
31
32
  end.flatten
@@ -33,40 +34,58 @@ def method_details_list(controllers)
33
34
  meths = run_verifier(meths)
34
35
 
35
36
  meths.map do |object, i|
36
- dump_object(object).tap do |object_info|
37
+ dump_endpoint(object).tap do |object_info|
37
38
  object_info[:tags] = dump_object_tags(object)
38
39
  end
39
40
  end
40
41
  end
41
42
 
42
- def dump_api_objects(controller)
43
+ def dump_controller_objects(controller)
43
44
  (controller.tags(:object) + controller.tags(:model)).map do |obj|
44
- name, schema = obj.text.split(%r{\n+}, 2).map(&:strip)
45
+ dump_object(obj)
46
+ end
47
+ end
45
48
 
46
- {
47
- controller: controller.name,
48
- name: name,
49
- schema: schema
50
- }
49
+ def dump_object(obj)
50
+ title, spec = obj.text.split(%r{\n+}, 2).map(&:strip)
51
+ spec = JSON.parse(spec)
52
+ schema = spec.has_key?('properties') ? spec['properties'] : spec
53
+
54
+ schema_tags = schema.map do |(prop_name, prop)|
55
+ is_required = prop.has_key?('required') ? prop['required'] : false
56
+ is_required_str = is_required ? 'Required' : 'Optional'
57
+
58
+ ArgumentTag.new(nil, "[#{is_required_str}, #{prop['type']}] #{prop_name}\n #{prop['description']}")
51
59
  end
60
+
61
+ {
62
+ id: topicize("#{obj.object.path}::#{title}"),
63
+ scoped_id: topicize(title),
64
+ title: title,
65
+ text: spec['description'] || '',
66
+ controller: obj.object.path,
67
+ schema: schema_tags.as_json.map { |e| e.delete('tag_name'); e }
68
+ }
52
69
  end
53
70
 
54
- def dump_object(object)
71
+ def dump_endpoint(endpoint)
72
+ title = endpoint.tag(:API).text
73
+
55
74
  {
56
- name: object.name,
57
- route: get_route(object),
58
- title: object.title,
59
- type: object.type,
60
- path: object.path,
61
- namespace: object.namespace.path,
62
- source: object.source,
63
- source_type: object.source_type,
64
- signature: object.signature,
65
- files: object.files,
66
- docstring: object.base_docstring,
67
- dynamic: object.dynamic,
68
- group: object.group,
69
- visibility: object.visibility
75
+ id: topicize(endpoint.path),
76
+ scoped_id: topicize(title),
77
+ title: title,
78
+ text: endpoint.base_docstring,
79
+ controller: endpoint.namespace.path,
80
+ route: get_route(endpoint),
81
+ type: endpoint.type,
82
+ source: endpoint.source,
83
+ source_type: endpoint.source_type,
84
+ signature: endpoint.signature,
85
+ files: endpoint.files,
86
+ dynamic: endpoint.dynamic,
87
+ group: endpoint.group,
88
+ visibility: endpoint.visibility
70
89
  }
71
90
  end
72
91
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard