rails_api_documentation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +41 -0
  3. data/app/assets/config/rails_api_doc_manifest.js +2 -0
  4. data/app/assets/javascripts/api_doc.js +5 -0
  5. data/app/assets/javascripts/components.js +1 -0
  6. data/app/assets/javascripts/rails_api_doc/application.js +3 -0
  7. data/app/assets/javascripts/table.js.coffee +8 -0
  8. data/app/assets/stylesheets/rails_api_doc/application.css +15 -0
  9. data/app/assets/stylesheets/rails_api_doc/table.sass +105 -0
  10. data/app/controllers/rails_api_doc/api_docs_controller.rb +51 -0
  11. data/app/controllers/rails_api_doc/application_controller.rb +5 -0
  12. data/app/helpers/rails_api_doc/application_helper.rb +4 -0
  13. data/app/models/rails_api_doc/application_record.rb +5 -0
  14. data/app/views/layouts/rails_api_doc/application.slim +20 -0
  15. data/app/views/rails_api_doc/api_docs/_edit_field.slim +9 -0
  16. data/app/views/rails_api_doc/api_docs/_request_api_table.slim +43 -0
  17. data/app/views/rails_api_doc/api_docs/_response_api_table.slim +7 -0
  18. data/app/views/rails_api_doc/api_docs/_side_menu.slim +10 -0
  19. data/app/views/rails_api_doc/api_docs/_title.slim +4 -0
  20. data/app/views/rails_api_doc/api_docs/edit.js.erb +0 -0
  21. data/app/views/rails_api_doc/api_docs/example.html.erb +32 -0
  22. data/app/views/rails_api_doc/api_docs/index.slim +23 -0
  23. data/app/views/rails_api_doc/api_docs/new.js.erb +0 -0
  24. data/app/views/shared/_response_table.slim +14 -0
  25. data/app/views/shared/_table.slim +20 -0
  26. data/config/routes.rb +10 -0
  27. data/lib/rails_api_doc/config/validator.rb +14 -0
  28. data/lib/rails_api_doc/configuration.rb +9 -0
  29. data/lib/rails_api_doc/controller/attribute_parser.rb +56 -0
  30. data/lib/rails_api_doc/controller/parameter/repository/param.rb +51 -0
  31. data/lib/rails_api_doc/controller/parameter/repository.rb +33 -0
  32. data/lib/rails_api_doc/controller/parameter.rb +57 -0
  33. data/lib/rails_api_doc/controller/response/rabl.rb +58 -0
  34. data/lib/rails_api_doc/controller/response/rabl_compiler.rb +236 -0
  35. data/lib/rails_api_doc/controller/response_factory.rb +19 -0
  36. data/lib/rails_api_doc/controller/strong_params.rb +46 -0
  37. data/lib/rails_api_doc/controller.rb +6 -0
  38. data/lib/rails_api_doc/engine.rb +40 -0
  39. data/lib/rails_api_doc/types.rb +7 -0
  40. data/lib/rails_api_doc/version.rb +5 -0
  41. data/lib/rails_api_doc.rb +26 -0
  42. data/lib/tasks/rails_api_doc_tasks.rake +4 -0
  43. metadata +197 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a03ef70ed0477183acaaa7ba574df74783258e7f
4
+ data.tar.gz: fb710dfc8b09f833424d6f67e4991392306ad4f7
5
+ SHA512:
6
+ metadata.gz: 2339ff9ff62a7b9afbc2ae4456f76ef672e20bea3a6cdb8fb65ab2757f03ea7de9d186f41c3faa16a80dc2688ea20f7365eafcc7d234639152aab50dc3414389
7
+ data.tar.gz: dcc0448c98eabb01d15b10b0213895af983a3f23b2efb84a1488a0f0692e7ea6571b8d2675aaa7cb9f65f426efe9b9349a838dc32066c58706a7dcbc7f9a5da9
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # RailsApiDoc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_api_doc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails_api_doc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_api_doc
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_api_doc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/rails_api_doc .js
2
+ //= link_directory ../stylesheets/rails_api_doc .css
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require table
4
+ //
5
+ //
@@ -0,0 +1 @@
1
+ //= require_tree ./components
@@ -0,0 +1,3 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require_tree .
@@ -0,0 +1,8 @@
1
+ $ ->
2
+ $('.next-is-nested').on 'click', (e) ->
3
+ self = $(this)
4
+ self.closest('.row').next().toggle()
5
+
6
+ $('.request-action-title').on 'click', (e) ->
7
+ self = $(this)
8
+ self.next().toggle()
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,105 @@
1
+ \:root
2
+ --row-count: 5
3
+
4
+ .flex-table
5
+ // display: inline-flex
6
+ // justify-content: center
7
+ // width: 80%
8
+ // margin: 0 auto
9
+ // display: inline-block
10
+ padding: 5px
11
+ box-sizing: border-box
12
+ background: lightblue
13
+
14
+ // border: 1px solid black
15
+
16
+ & &
17
+ display: none
18
+ width: 100%
19
+ background: gray
20
+ padding: 20px
21
+ box-sizing: border-box
22
+
23
+ & .flex-table
24
+ padding-right: 0
25
+
26
+ //
27
+ // &.flex-table
28
+ // width: 100%
29
+ // background: gray
30
+ // padding: 20px
31
+ // box-sizing: border-box
32
+ //
33
+ // &.flex-table
34
+ // padding-right: 0
35
+
36
+ .flex-line
37
+
38
+ padding: 0
39
+ margin: auto
40
+ list-style: none // ??
41
+ border-bottom: 1px solid black
42
+
43
+ &:first-child
44
+ border-top: 1px solid black
45
+
46
+ background: lightgreen
47
+
48
+ // Зачем это ?
49
+ // display: -webkit-box
50
+ // display: -moz-box
51
+ // display: -ms-flexbox
52
+ // display: -webkit-flex
53
+ //
54
+
55
+ &.row
56
+ display: flex
57
+ // flex-flow: row wrap
58
+ // justify-content: space-between
59
+
60
+ // ничего не сделало
61
+ // flex-direction: row
62
+ // ничего не сделало
63
+ // flex-wrap: nowrap
64
+
65
+ // -webkit-flex-flow: row wrap
66
+
67
+ &.column
68
+ flex: 1
69
+ flex-flow: column wrap
70
+ align-content: flex-start
71
+ // align-items: stretch
72
+
73
+ .flex-item
74
+ border-right: 1px solid black
75
+ &:first-child
76
+ border-left: 1px solid black
77
+ // border-bottom: 1px solid black
78
+ background: tomato
79
+ padding: 5px
80
+
81
+ // margin: auto
82
+ text-align: center
83
+
84
+ .row &
85
+ width: calc(100%/var(--row-count))
86
+ min-height: 20px
87
+ // Что я сделал ?? - оно почемуто заработало было flex-grow: 1
88
+ // В статье написано что это тоже самое, а на практике - не так ?
89
+ // flex: 1
90
+ // TODO: need function that will count % from num childs?
91
+ // магические отступы ))
92
+ // width: 23%
93
+
94
+ // line-height: 150px
95
+ // color: white
96
+ // font-weight: bold
97
+ // font-size: 3em
98
+ // text-align: center
99
+
100
+ .column &
101
+ width: 100%
102
+
103
+ .request-action-title
104
+ text-align: center
105
+ background-color: lightblue
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ # author: Vadim Shaveiko <@vshaveyko>
3
+ # :nodoc:
4
+ class RailsApiDoc::ApiDocsController < RailsApiDoc::ApplicationController
5
+
6
+ class NewRecord < ActiveRecord::Base
7
+ end
8
+
9
+ def index
10
+ # preload controllers for parameters to apply
11
+ Dir.glob("#{Rails.root}/app/controllers/**/*.rb").each { |file| require_dependency file }
12
+
13
+ @static_data = {
14
+ types: RailsApiDoc::Controller::Parameter::Repository::Param::ACCEPTED_TYPES.map(&:to_s)
15
+ }
16
+
17
+ @request_repository = RailsApiDoc::Controller::Parameter::Repository
18
+
19
+ @response_repository = RailsApiDoc::Controller::Response.repo
20
+ end
21
+
22
+ def create
23
+ attributes = RailsApiDoc::Controller::AttributeParser.parse_attributes(permitted_params)
24
+ end
25
+
26
+ def destroy
27
+ pry binding
28
+ end
29
+
30
+ def edit
31
+ @api_record = NewRecord.new
32
+
33
+ pry binding
34
+ end
35
+
36
+ def new
37
+ @api_record = NewRecord.new
38
+ pry binding
39
+ end
40
+
41
+ def update
42
+ pry binding
43
+ end
44
+
45
+ private
46
+
47
+ def permitted_params
48
+ params.permit!(:name, :type, :enum)
49
+ end
50
+
51
+ end
@@ -0,0 +1,5 @@
1
+ module RailsApiDoc
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module RailsApiDoc
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module RailsApiDoc
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ doctype html
2
+ html lang="en"
3
+ head
4
+ meta charset="utf-8" /
5
+ meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" /
6
+ meta content="" name="description" /
7
+ meta content="width=device-width" name="viewport" /
8
+ title RailsApidDoc
9
+ == stylesheet_link_tag "rails_api_doc/application", :media => "all"
10
+ == javascript_include_tag "api_doc"
11
+ == csrf_meta_tags
12
+ body
13
+ #main.container
14
+ == yield
15
+ footer#footer
16
+ .container
17
+ p
18
+ | Powered by
19
+ a href="http://github.com/vshaveyko/rails_api_doc" RailsApiDoc
20
+ == RailsApiDoc::VERSION
@@ -0,0 +1,9 @@
1
+ .row
2
+ = form_tag(api_doc_path, method: 'post', remote: true, class: 'form-horizontal') do
3
+ - ([:name] + headers).each do |field_name|
4
+ div.field(class="col-md-#{col_num - 1}")
5
+ / Add parameter name second argument
6
+ = text_field_tag field_name, nil, placeholder: field_name, class: 'form-control'
7
+
8
+ div.actions(class="col-md-#{col_num - 1}")
9
+ = button_tag 'Add table parameter', class: 'btn btn-primary'
@@ -0,0 +1,43 @@
1
+ - @request_headers = { enum: 'Values(if type is enum)' }
2
+
3
+ div[href=(locals[:model].to_s + '.request') style="--row-count: #{@request_headers.length}"]
4
+ = render 'shared/table', locals: { model: locals[:model], rows: locals[:params] }
5
+
6
+ / .row
7
+ / = form_tag(api_doc_path, method: 'post', remote: true, class: 'form-horizontal') do
8
+
9
+ / - ([:name] + headers).each do |field_name|
10
+ / div.field(class="col-md-#{col_num - 1}")
11
+ / / Add parameter name second argument
12
+ / = text_field_tag field_name, nil, placeholder: field_name, class: 'form-control'
13
+ /
14
+ / div.actions(class="col-md-#{col_num - 1}")
15
+ / = button_tag 'Add table parameter', class: 'btn btn-primary'
16
+ / = render 'edit_field'
17
+
18
+ / .table
19
+ / div.nopadding[class="col-md-#{col_num}"]
20
+ / = link_to new_api_doc_path, class: 'btn btn-primary btn-xs' do
21
+ / span.glyphicon.glyphicon-plus
22
+ / | Parameter
23
+ /
24
+ / - headers.each do |param_header|
25
+ / div.nopadding[class="col-md-#{col_num}"] = param_header
26
+ /
27
+ / - locals[:params].each do |param_key, param_values|
28
+ / .row.blue
29
+ / div.nopadding[class="col-md-#{col_num}" style="white-space: nowrap;"]
30
+ / - unless param_values.nested?
31
+ / = link_to edit_api_doc_path, class: 'btn btn-primary btn-xs' do
32
+ / span.glyphicon.glyphicon-pencil
33
+ / = link_to api_doc_path(param_key: param_key, nesting: locals[:nesting]), class: 'btn btn-primary btn-xs', method: :delete do
34
+ / span.glyphicon.glyphicon-minus
35
+ / | #{param_key}#{'*' if param_values.required?}
36
+ /
37
+ / - if param_values.nested?
38
+ / .table-column[class="col-md-#{12 - col_num}"]
39
+ / - nested_params = locals[:nesting].to_a.push(locals[:model])
40
+ / = render 'request_api_table', locals: { model: param_values[:model] || param_key, params: param_values[:nested], nesting: nested_params }
41
+ / - else
42
+ / - headers.each do |param_header|
43
+ / .table-column[class="col-md-#{col_num}"] = param_values[param_header]
@@ -0,0 +1,7 @@
1
+ div[href=(model.to_s + '.response') style="--row-count: 3"]
2
+ - repo.map[model][:actions].each do |action|
3
+ // TODO: Nest table in this div for easier jq toggling
4
+ // add borders to this div
5
+ div.request-action-title #{repo.action_route(model, action)}
6
+ - if data = repo.load_template(model, action)
7
+ = render 'shared/response_table', locals: { model: model, rows: data }
@@ -0,0 +1,10 @@
1
+ nav.bs-docs-sidebar.hidden-print.hidden-sm.hidden-xs(data-spy="affix" data-offset-top="60")
2
+ ul.nav.bs-docs-sidenav
3
+ - locals[:models].each do |model|
4
+ li
5
+ a[href=('#' + model.to_s)] = model.to_s
6
+ ul.nav
7
+ li
8
+ a[href=('#' + model.to_s + '.request')] request
9
+ li
10
+ a[href=('#' + model.to_s + '.response')] response
@@ -0,0 +1,4 @@
1
+ .bs-docs-section
2
+ h1#grid.page-header
3
+ a.anchorjs-link[href="#grid" aria-label="Anchor link for: grid" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: inherit; position: absolute; margin-left: -1em; padding-right: 0.5em;"]
4
+ | Api documentation
File without changes
@@ -0,0 +1,32 @@
1
+ <table class="table table-condensed">
2
+ <thead class="thead-default">
3
+ <tr>
4
+ <th>#</th>
5
+ <th>First Name</th>
6
+ <th>Last Name</th>
7
+ <th>Username</th>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <tr class="success">
12
+ <th scope="row">1</th>
13
+ <td>Mark</td>
14
+ <td>Otto</td>
15
+ <td>@mdo</td>
16
+ </tr>
17
+ <tr class="active">
18
+ <th scope="row">2</th>
19
+ <td>Jacob</td>
20
+ <td>Thornton</td>
21
+ <td>@fat</td>
22
+ </tr>
23
+ <tr>
24
+ <th scope="row" class="warning">3</th>
25
+ <td>Larry</td>
26
+ <td>the Bird</td>
27
+ <td>@twitter</td>
28
+ </tr>
29
+ </tbody>
30
+ </table>
31
+
32
+
@@ -0,0 +1,23 @@
1
+ .container.bs-docs-container
2
+ .row
3
+ = render 'title'
4
+ .row
5
+ .col-md-9[role="main"]
6
+
7
+ - @request_repository.each do |model, params|
8
+ .bs-docs-section
9
+ h2[id=(model.to_s)] = model.to_s
10
+ p
11
+ | Scopes
12
+ | #{model.scopes_configuration.keys.map { |key| ":#{key}"}.join(', ')}
13
+
14
+ p
15
+ | Request
16
+ = render 'request_api_table', locals: { model: model, params: params }
17
+
18
+ p
19
+ | Response
20
+ = render 'response_api_table', model: model, repo: @response_repository
21
+
22
+ .col-md-3[role="complementary"]
23
+ = render 'side_menu', locals: { models: @request_repository.keys }
File without changes