apipony 0.0.4 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ ##
2
+ # A class used to describe an attribute in a response.
3
+ class Apipony::ResponseAttribute
4
+ @type_definitions = {}
5
+ ##
6
+ # Allow a common subobject definition for code reuse.
7
+ # Probably use the `subtype` method in the `subtype` method of the DSL
8
+ # `define` DSL instead.
9
+ def self.define_type(name, type)
10
+ @type_definitions[name] = type
11
+ end
12
+
13
+ ##
14
+ # Get a list of predefined subtypes.
15
+ # Probably use the `
16
+ def self.defined_subtypes
17
+ @type_definitions
18
+ end
19
+ ##
20
+ # Get a subtype with the given name.
21
+ def self.get_defined(name)
22
+ @type_definitions[name]
23
+ end
24
+
25
+ attr_accessor :name, :type, :description, :attributes, :choices
26
+ def initialize(name,
27
+ type: :string,
28
+ description: "",
29
+ array: false,
30
+ example: nil,
31
+ &block)
32
+ @name = name
33
+ @description = description
34
+ @type = type
35
+ @array = array
36
+ @example = example
37
+ if block_given?
38
+ instance_eval(&block)
39
+ ## This attribute is of a predefined subtype
40
+ elsif (subtype = self.class.get_defined(@type))
41
+ @attributes = subtype.attributes
42
+ # If the subtype is an array, this is also an array
43
+ @array = subtype.is_array? unless @array
44
+ @is_subtype = true
45
+ end
46
+ end
47
+
48
+ ##
49
+ # Build an example from this object
50
+ def example
51
+ sub = nil
52
+ if is_object? || is_subtype?
53
+ sub = Hash[@attributes.select(&:example).map{|a| [a.name, a.example]}]
54
+ elsif is_enum?
55
+ sub = choices.first.name
56
+ else
57
+ sub = @example
58
+ end
59
+ ##
60
+ # If we have an example an are an array
61
+ if sub and is_array?
62
+ [sub]
63
+ else
64
+ sub
65
+ end
66
+ end
67
+ ##
68
+ # Is this attribute an array?
69
+ # Note that marking an attribute as an array does not over-ride the top-level
70
+ # type. For example, a definition like:
71
+ # attribute :aliases, type: :string, array: true
72
+ # denotates an array of strings. Also note that subattributes are not
73
+ # over-ridden. This lets you make an array of objects.
74
+ # attribute :users, type: :object, array: true do
75
+ # attribute :id, type: :integer
76
+ # attribute :name, type: :integer
77
+ # end
78
+ #
79
+ def is_array?
80
+ !! @array
81
+ end
82
+
83
+ ##
84
+ # See if this attribute is a reference to a predefined subtype.
85
+ def is_subtype?
86
+ !! @is_subtype
87
+ end
88
+
89
+ def use_defined(type)
90
+ a = self.class.get_defined(name)
91
+ raise "Tried to use an undefined subtype" unless a
92
+ ##
93
+ # Shallow clone so we can alias the name
94
+ a = a.clone
95
+ a.name = as
96
+ add_subattribute a
97
+ end
98
+
99
+ def attribute(name, **params, &block)
100
+ add_subattribute self.class.new(name, **params, &block)
101
+ end
102
+
103
+ def is_object?
104
+ @type == :object
105
+ end
106
+
107
+ def is_enum?
108
+ @type == :enum
109
+ end
110
+
111
+ def choice(name, **params)
112
+ @choices ||= []
113
+ @type = :enum
114
+ @choices << EnumChoice.new(name, **params)
115
+ end
116
+
117
+ class EnumChoice
118
+ attr_accessor :name, :description
119
+ def initialize(name, description: "")
120
+ @name = name
121
+ @description = description
122
+ end
123
+ end
124
+ private
125
+ def add_subattribute atr
126
+ @attributes ||= []
127
+ @type = :object
128
+ @attributes << atr
129
+ end
130
+ end
@@ -1,6 +1,15 @@
1
+ ##
2
+ # A section is a way to logically separate your endpoints. All endpoints in
3
+ # a section should be related in some way.
1
4
  class Apipony::Section
2
- attr_accessor :title, :endpoints
3
-
5
+ ##
6
+ # What to call this endpoint. This will show up on the generated page.
7
+ attr_accessor :title
8
+ ##
9
+ # :nodoc:
10
+ # This contains an array of endpoints added with the `endpoint` method of the
11
+ # DSL
12
+ attr_accessor :endpoints
4
13
  def initialize(title, &block)
5
14
  @title = title
6
15
  @endpoints = []
@@ -1,3 +1,5 @@
1
1
  module Apipony
2
- VERSION = '0.0.4'
2
+ ##
3
+ #:nodoc:
4
+ VERSION = '0.0.7'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Novikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.4
27
- - !ruby/object:Gem::Dependency
28
- name: haml-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.9.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.9.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sass
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +66,34 @@ dependencies:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
68
  version: 1.3.11
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
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: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: faker
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -175,18 +189,26 @@ files:
175
189
  - app/assets/stylesheets/apipony/application.css
176
190
  - app/assets/stylesheets/apipony/styles.scss
177
191
  - app/controllers/apipony/application_controller.rb
178
- - app/views/apipony/application/index.html.haml
179
- - app/views/layouts/apipony/application.html.haml
180
- - config/initializers/haml.rb
192
+ - app/views/apipony/application/_attribute.html.erb
193
+ - app/views/apipony/application/_footer.html.erb
194
+ - app/views/apipony/application/_header.html.erb
195
+ - app/views/apipony/application/_method.html.erb
196
+ - app/views/apipony/application/_request.html.erb
197
+ - app/views/apipony/application/_response.html.erb
198
+ - app/views/apipony/application/_sidebar.html.erb
199
+ - app/views/apipony/application/index.html.erb
200
+ - app/views/layouts/apipony/application.html.erb
181
201
  - config/routes.rb
182
202
  - lib/apipony.rb
183
203
  - lib/apipony/base.rb
184
204
  - lib/apipony/documentation.rb
185
205
  - lib/apipony/endpoint.rb
186
206
  - lib/apipony/engine.rb
207
+ - lib/apipony/example_response.rb
187
208
  - lib/apipony/parameter.rb
188
209
  - lib/apipony/request.rb
189
210
  - lib/apipony/response.rb
211
+ - lib/apipony/response_attribute.rb
190
212
  - lib/apipony/section.rb
191
213
  - lib/apipony/version.rb
192
214
  - lib/generators/apipony/install/templates/initializer.rb
@@ -216,3 +238,4 @@ signing_key:
216
238
  specification_version: 4
217
239
  summary: Easy Rails API documentation.
218
240
  test_files: []
241
+ has_rdoc:
@@ -1,74 +0,0 @@
1
- %header
2
- .container
3
- = link_to @documentation.title, root_path, class: 'title'
4
- - if main_app.root_path
5
- = link_to 'Back to site', main_app.root_path, class: 'back'
6
- %main
7
- .container
8
- .row
9
- .col-3
10
- - @documentation.sections.each do |section|
11
- %h4= section.title
12
- %ul
13
- - section.endpoints.each do |endpoint|
14
- %li
15
- %h5
16
- = link_to root_path(:anchor => endpoint.id) do
17
- %span.method{ :class => endpoint.method }<
18
- = endpoint.method
19
- = endpoint.url
20
- .col-9
21
- - @documentation.sections.each do |section|
22
- .section
23
- %h2= section.title
24
- - section.endpoints.each do |endpoint|
25
- .endpoint{ :id => endpoint.id }
26
- %h3
27
- %span.method{ :class => endpoint.method }<
28
- = endpoint.method
29
- = endpoint.url
30
- - if endpoint.description
31
- .description= endpoint.description
32
- - if endpoint.request || endpoint.response
33
- - if endpoint.request
34
- .request
35
- %h4 Request:
36
- - if endpoint.request.params
37
- .panel
38
- .title Parameters
39
- %table.table
40
- - endpoint.request.params.each do |param|
41
- %tr.param
42
- %td.name
43
- = param.name
44
- %td.type
45
- = param.type
46
- %td.required
47
- - if param.required
48
- %i.fa.fa-check-square-o{ :title => 'Required' }
49
- - else
50
- %i.fa.fa-square-o{ :title => 'Optional' }
51
- %td.example
52
- = param.example
53
- - if endpoint.request.headers
54
- .panel
55
- .title Headers
56
- %pre.code= JSON.pretty_generate(endpoint.request.headers)
57
- - if endpoint.response
58
- .response
59
- %h4
60
- Response:
61
- = endpoint.response.status
62
- - if endpoint.response.body
63
- .panel
64
- .title Body
65
- %pre.code= JSON.pretty_generate(endpoint.response.body)
66
- - if endpoint.response.headers
67
- .panel
68
- .title Headers
69
- %pre.code= JSON.pretty_generate(endpoint.response.headers)
70
- %footer
71
- .container
72
- = link_to 'https://github.com/droptheplot/apipony' do
73
- %i.fa.fa-github
74
- Apipony
@@ -1,12 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title Apipony
5
- %link{ :href => '//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/github.min.css', :rel => 'stylesheet' }/
6
- %link{ :href => 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', :rel => 'stylesheet' }/
7
- = stylesheet_link_tag 'apipony/application', media: 'all'
8
- %script{ :src => '//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js' }
9
- = javascript_include_tag 'apipony/application'
10
- = csrf_meta_tags
11
- %body
12
- = yield
@@ -1 +0,0 @@
1
- require 'haml-rails'