apitome 0.0.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/MIT.LICENSE +2 -2
  3. data/README.md +99 -40
  4. data/app/assets/javascripts/apitome/application.js +16 -0
  5. data/app/assets/stylesheets/apitome/application.css +10 -0
  6. data/app/controllers/apitome/docs_controller.rb +83 -45
  7. data/app/helpers/apitome/docs_helper.rb +19 -0
  8. data/app/views/apitome/docs/_all_examples.html.erb +6 -2
  9. data/app/views/apitome/docs/_body.html.erb +1 -1
  10. data/app/views/apitome/docs/_curl.html.erb +1 -1
  11. data/app/views/apitome/docs/_endpoint.html.erb +4 -0
  12. data/app/views/apitome/docs/_example.html.erb +10 -6
  13. data/app/views/apitome/docs/_explanation.html.erb +3 -3
  14. data/app/views/apitome/docs/_headers.html.erb +6 -4
  15. data/app/views/apitome/docs/_navigation.html.erb +14 -10
  16. data/app/views/apitome/docs/_params.html.erb +4 -4
  17. data/app/views/apitome/docs/_query.html.erb +1 -1
  18. data/app/views/apitome/docs/_resource_explanation.html.erb +3 -0
  19. data/app/views/apitome/docs/_response_fields.html.erb +1 -1
  20. data/app/views/apitome/docs/_route.html.erb +1 -1
  21. data/app/views/apitome/docs/_status.html.erb +1 -1
  22. data/app/views/apitome/docs/index.html.erb +11 -6
  23. data/app/views/apitome/docs/show.html.erb +2 -1
  24. data/app/views/layouts/apitome/application.html.erb +4 -4
  25. data/config/locales/en.yml +14 -11
  26. data/config/locales/es.yml +14 -10
  27. data/lib/apitome.rb +5 -5
  28. data/lib/apitome/configuration.rb +36 -15
  29. data/lib/apitome/engine.rb +13 -7
  30. data/lib/apitome/exceptions.rb +5 -1
  31. data/lib/apitome/version.rb +1 -1
  32. data/lib/generators/apitome/install/POST_INSTALL +1 -1
  33. data/lib/generators/apitome/install/install_generator.rb +7 -8
  34. data/lib/generators/apitome/install/templates/initializer.rb +35 -13
  35. data/vendor/assets/javascripts/apitome/highlight.min.js +2 -1
  36. data/vendor/assets/stylesheets/apitome/highlight_themes/agate.css +108 -0
  37. data/vendor/assets/stylesheets/apitome/highlight_themes/androidstudio.css +66 -0
  38. data/vendor/assets/stylesheets/apitome/highlight_themes/arduino-light.css +88 -0
  39. data/vendor/assets/stylesheets/apitome/highlight_themes/arta.css +41 -126
  40. data/vendor/assets/stylesheets/apitome/highlight_themes/ascetic.css +31 -36
  41. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-cave-dark.css +83 -0
  42. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-cave-light.css +85 -0
  43. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-dune-dark.css +69 -0
  44. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-dune-light.css +69 -0
  45. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-estuary-dark.css +84 -0
  46. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-estuary-light.css +84 -0
  47. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-forest-dark.css +69 -0
  48. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-forest-light.css +69 -0
  49. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-heath-dark.css +69 -0
  50. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-heath-light.css +69 -0
  51. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-lakeside-dark.css +69 -0
  52. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-lakeside-light.css +69 -0
  53. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-plateau-dark.css +84 -0
  54. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-plateau-light.css +84 -0
  55. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-savanna-dark.css +84 -0
  56. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-savanna-light.css +84 -0
  57. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-seaside-dark.css +69 -0
  58. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-seaside-light.css +69 -0
  59. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-sulphurpool-dark.css +69 -0
  60. data/vendor/assets/stylesheets/apitome/highlight_themes/atelier-sulphurpool-light.css +69 -0
  61. data/vendor/assets/stylesheets/apitome/highlight_themes/brown-paper.css +64 -0
  62. data/vendor/assets/stylesheets/apitome/highlight_themes/{brown_papersq.png → brown-papersq.png} +0 -0
  63. data/vendor/assets/stylesheets/apitome/highlight_themes/codepen-embed.css +60 -0
  64. data/vendor/assets/stylesheets/apitome/highlight_themes/color-brewer.css +71 -0
  65. data/vendor/assets/stylesheets/apitome/highlight_themes/dark.css +41 -81
  66. data/vendor/assets/stylesheets/apitome/highlight_themes/darkula.css +74 -0
  67. data/vendor/assets/stylesheets/apitome/highlight_themes/default.css +74 -110
  68. data/vendor/assets/stylesheets/apitome/highlight_themes/docco.css +97 -0
  69. data/vendor/assets/stylesheets/apitome/highlight_themes/dracula.css +76 -0
  70. data/vendor/assets/stylesheets/apitome/highlight_themes/far.css +46 -86
  71. data/vendor/assets/stylesheets/apitome/highlight_themes/foundation.css +88 -0
  72. data/vendor/assets/stylesheets/apitome/highlight_themes/github-gist.css +71 -0
  73. data/vendor/assets/stylesheets/apitome/highlight_themes/github.css +53 -81
  74. data/vendor/assets/stylesheets/apitome/highlight_themes/googlecode.css +48 -103
  75. data/vendor/assets/stylesheets/apitome/highlight_themes/grayscale.css +101 -0
  76. data/vendor/assets/stylesheets/apitome/highlight_themes/gruvbox-dark.css +108 -0
  77. data/vendor/assets/stylesheets/apitome/highlight_themes/gruvbox-light.css +108 -0
  78. data/vendor/assets/stylesheets/apitome/highlight_themes/hopscotch.css +83 -0
  79. data/vendor/assets/stylesheets/apitome/highlight_themes/hybrid.css +102 -0
  80. data/vendor/assets/stylesheets/apitome/highlight_themes/idea.css +40 -64
  81. data/vendor/assets/stylesheets/apitome/highlight_themes/ir-black.css +73 -0
  82. data/vendor/assets/stylesheets/apitome/highlight_themes/kimbie.dark.css +74 -0
  83. data/vendor/assets/stylesheets/apitome/highlight_themes/kimbie.light.css +74 -0
  84. data/vendor/assets/stylesheets/apitome/highlight_themes/magula.css +36 -87
  85. data/vendor/assets/stylesheets/apitome/highlight_themes/mono-blue.css +59 -0
  86. data/vendor/assets/stylesheets/apitome/highlight_themes/monokai-sublime.css +83 -0
  87. data/vendor/assets/stylesheets/apitome/highlight_themes/monokai.css +50 -94
  88. data/vendor/assets/stylesheets/apitome/highlight_themes/obsidian.css +88 -0
  89. data/vendor/assets/stylesheets/apitome/highlight_themes/paraiso-dark.css +72 -0
  90. data/vendor/assets/stylesheets/apitome/highlight_themes/paraiso-light.css +72 -0
  91. data/vendor/assets/stylesheets/apitome/highlight_themes/pojoaque.css +45 -66
  92. data/vendor/assets/stylesheets/apitome/highlight_themes/purebasic.css +96 -0
  93. data/vendor/assets/stylesheets/apitome/highlight_themes/qtcreator_dark.css +83 -0
  94. data/vendor/assets/stylesheets/apitome/highlight_themes/qtcreator_light.css +83 -0
  95. data/vendor/assets/stylesheets/apitome/highlight_themes/railscasts.css +106 -0
  96. data/vendor/assets/stylesheets/apitome/highlight_themes/rainbow.css +48 -77
  97. data/vendor/assets/stylesheets/apitome/highlight_themes/school-book.css +72 -0
  98. data/vendor/assets/stylesheets/apitome/highlight_themes/{school_book.png → school-book.png} +0 -0
  99. data/vendor/assets/stylesheets/apitome/highlight_themes/solarized-dark.css +84 -0
  100. data/vendor/assets/stylesheets/apitome/highlight_themes/solarized-light.css +84 -0
  101. data/vendor/assets/stylesheets/apitome/highlight_themes/sunburst.css +55 -111
  102. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow-night-blue.css +75 -0
  103. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow-night-bright.css +74 -0
  104. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow-night-eighties.css +74 -0
  105. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow-night.css +75 -0
  106. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow.css +43 -20
  107. data/vendor/assets/stylesheets/apitome/highlight_themes/vs.css +50 -68
  108. data/vendor/assets/stylesheets/apitome/highlight_themes/xcode.css +55 -116
  109. data/vendor/assets/stylesheets/apitome/highlight_themes/xt256.css +92 -0
  110. data/vendor/assets/stylesheets/apitome/highlight_themes/zenburn.css +49 -84
  111. metadata +80 -65
  112. data/config/routes.rb +0 -4
  113. data/spec/apitome/configuration_spec.rb +0 -0
  114. data/spec/apitome/engine_spec.rb +0 -0
  115. data/spec/dummy/Rakefile +0 -7
  116. data/spec/dummy/config.ru +0 -15
  117. data/spec/dummy/config/application.rb +0 -16
  118. data/spec/dummy/config/boot.rb +0 -7
  119. data/spec/dummy/config/environment.rb +0 -5
  120. data/spec/dummy/config/environments/development.rb +0 -27
  121. data/spec/dummy/config/environments/test.rb +0 -29
  122. data/spec/dummy/config/initializers/apitome.rb +0 -44
  123. data/spec/dummy/config/routes.rb +0 -2
  124. data/spec/dummy/doc/api.md +0 -20
  125. data/spec/dummy/public/favicon.ico +0 -0
  126. data/spec/dummy/script/rails +0 -6
  127. data/vendor/assets/stylesheets/apitome/highlight_themes/brown_paper.css +0 -104
  128. data/vendor/assets/stylesheets/apitome/highlight_themes/ir_black.css +0 -104
  129. data/vendor/assets/stylesheets/apitome/highlight_themes/school_book.css +0 -111
  130. data/vendor/assets/stylesheets/apitome/highlight_themes/solarized_dark.css +0 -88
  131. data/vendor/assets/stylesheets/apitome/highlight_themes/solarized_light.css +0 -88
  132. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow_night.css +0 -52
  133. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow_night_blue.css +0 -52
  134. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow_night_bright.css +0 -51
  135. data/vendor/assets/stylesheets/apitome/highlight_themes/tomorrow_night_eighties.css +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a1e1b44d0fcdb63bafd524f03297c31f51c4b523
4
- data.tar.gz: f7ed3657e3e285f7aaae171fcf0337e3052108a2
2
+ SHA256:
3
+ metadata.gz: 03db784396e463e2e3117c3876221da9501bdf370b2b31d64af0aeb20832f6a7
4
+ data.tar.gz: 2c44ee118c18033c0ff752156b34501bc915afa2f1ff14db11bdd48cb63ad899
5
5
  SHA512:
6
- metadata.gz: f57528a4c1e0488e6a9b546f1cd99212fd889f082642cd6eb2a7744cad4c8526536d2f9a5d2325cbafbc840058f351845eaa1a6ce316527b33e561ea81e0e3d5
7
- data.tar.gz: 3fe1abfa64a4fc598312173ff16702b8d2adbbab1959458322a754cf20fee6fd3462d8165bb33b285881e319659abe6787ce7a70bb037231183a091c6c18fd40
6
+ metadata.gz: 2ad3ae73aac6bc4fda71089236cc5b1387ace99b0289777249da6cd0c5e44efb3e99d07d2107006a23149b902dc5890835b18fd9034c34759054436a1dd0731e
7
+ data.tar.gz: c565e5d1a99fc2157d7892bdd7bed7d8bf353c6472c234c8ac7468d0fc8eb50dc8511ee96a115b071343ddb61cf93bd71284644b2da72e5a26c872489f63ec83
data/MIT.LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- Copyright 2013 Jeremy Jackson / ModeSet
1
+ Copyright 2019 Jeremy Jackson / ModeSet
2
2
 
3
- https://github.com/modeset/teaspoon
3
+ https://github.com/jejacks0n/apitome
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,16 +1,22 @@
1
1
  Apitome
2
2
  =======
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/apitome.png)](http://badge.fury.io/rb/apitome)
5
- [![Code Climate](https://codeclimate.com/github/modeset/apitome.png)](https://codeclimate.com/github/modeset/apitome)
4
+ [![Gem Version](https://img.shields.io/gem/v/apitome.svg)](https://rubygems.org/gems/apitome)
5
+ [![Build Status](https://img.shields.io/travis/jejacks0n/apitome.svg)](https://travis-ci.org/jejacks0n/apitome)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/eb8dd1c22f1da11b6c02/maintainability)](https://codeclimate.com/github/jejacks0n/apitome/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/eb8dd1c22f1da11b6c02/test_coverage)](https://codeclimate.com/github/jejacks0n/apitome/test_coverage)
8
+ [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
6
9
 
7
- Apitome is a documentation tool for Rails that enhances [rspec_api_documentation](https://github.com/zipmark/rspec_api_documentation) (RAD). It's designed to display the documentation generated by RAD in either a single page (with scrollspy), or on individual pages, and uses Bootstrap3 for most of the basic styling and [highlight.js](https://github.com/isagalaev/highlight.js) for code highlighting.
8
-
9
- You can provide a markdown file that will be displayed as the README page, and by taking advantage of its modular view structure you can override any number of views and partials to customize the output. You can also specify custom css and javascript if you want to do fancier things or change how it looks.
10
+ Apitome is a API documentation tool for Rails built on top of the great RSpec DSL included in
11
+ [rspec_api_documentation](https://github.com/zipmark/rspec_api_documentation) (RAD). It's designed to display the
12
+ documentation generated by RAD in either a single page, or on individual pages, and uses Bootstrap for most of the basic
13
+ styling and [highlight.js](https://github.com/isagalaev/highlight.js) for code highlighting.
10
14
 
15
+ You can provide a markdown file that will be displayed as the README page, and by taking advantage of its modular view
16
+ structure you can override any number of views and partials to customize the output. You can also specify custom css and
17
+ javascript if you want to do fancier things or change how it looks.
11
18
 
12
19
  ## Installation
13
-
14
20
  Add it to your Gemfile.
15
21
 
16
22
  ```ruby
@@ -23,7 +29,10 @@ Optionally run the install generator to get the initializer and an initial readm
23
29
  rails generate apitome:install
24
30
  ```
25
31
 
26
- Update your `spec_helper.rb` to adjust how RAD outputs its results -- Apitome reads these JSON files to generate the documentation.
32
+ You can get the assets installed using the generator by providing a `--assets` flag.
33
+
34
+ Update your `spec_helper.rb` to adjust how RAD outputs its results -- Apitome reads these JSON files to generate the
35
+ documentation.
27
36
 
28
37
  ```ruby
29
38
  RspecApiDocumentation.configure do |config|
@@ -31,92 +40,142 @@ RspecApiDocumentation.configure do |config|
31
40
  end
32
41
  ```
33
42
 
34
-
35
43
  ## Usage
36
-
37
44
  You can view your documentation at the default `api/docs` route.
38
45
 
39
-
40
46
  ## Configuration
41
-
42
- After installation, your app will have an apitome initializer (app/config/initializers/apitome.rb). You will find the following parameters that can be used to customize apitome. Note: Restart rails after changing any of these parameters.
47
+ After installation, your app will have an apitome initializer (app/config/initializers/apitome.rb). You will find the
48
+ following parameters that can be used to customize apitome. Note: Restart rails after changing any of these parameters.
43
49
 
44
50
  <dl>
45
-
46
51
  <dt> mount_at </dt><dd>
47
- This determines where the Apitome routes will be mounted. Changing this to "/api/documentation" for instance would allow you to browse to http://localhost:3000/api/documentation to see your api documentation. Set to nil and mount it yourself if you need to.<br/>
48
-
52
+ This determines where the Apitome routes will be mounted. Changing this to "/api/documentation" for instance would
53
+ allow you to browse to http://localhost:3000/api/documentation to see your api documentation. Set to nil and mount
54
+ it yourself if you need to.
55
+ <br/>
49
56
  <b>default:</b> <code>"/api/docs"</code>
50
57
  </dd>
51
58
 
52
59
  <dt> root </dt><dd>
53
- This defaults to Rails.root if left nil. If you're providing documentation for an engine using a dummy application it can be useful to set this to your engines root.. E.g. <code>Application::Engine.root</code><br/>
54
-
60
+ This defaults to Rails.root if left nil. If you're providing documentation for an engine using a dummy application
61
+ it can be useful to set this to your engines root. (E.g. <code>Application::Engine.root</code>)
62
+ <br/>
55
63
  <b>default:</b> <code>nil</code>
56
64
  </dd>
57
65
 
58
66
  <dt> doc_path </dt><dd>
59
- This is where rspec_api_documentation outputs the JSON files. This is configurable within RAD, and so is configurable here.<br/>
60
-
67
+ This is where rspec_api_documentation outputs the JSON files. This is configurable within RAD, and so is
68
+ configurable here.
69
+ <br/>
61
70
  <b>default:</b> <code>"doc/api"</code>
62
71
  </dd>
63
72
 
64
- <dt> title </dt><dd>
65
- The title of the documentation -- If your project has a name, you'll want to put it here.<br/>
73
+ <dt> parent_controller </dt><dd>
74
+ Set the parent controller that Apitome::DocsController will inherit from. Useful if you want to use a custom
75
+ <code>before_action</code> for instance.
76
+ <br/>
77
+ <b>default:</b> <code>"ActionController::Base"</code>
78
+ </dd>
66
79
 
80
+ <dt> title </dt><dd>
81
+ The title of the documentation -- If your project has a name, you'll want to put it here.
82
+ <br/>
67
83
  <b>default:</b> <code>"Apitome Documentation"</code>
68
84
  </dd>
69
85
 
70
86
  <dt> layout </dt><dd>
71
- The main layout view for all documentation pages. By default this is pretty basic, but you may want to use your own application layout.<br/>
72
-
87
+ The main layout view for all documentation pages. By default this is pretty basic, but you may want to use your own
88
+ application layout.
89
+ <br/>
73
90
  <b>default:</b> <code>"apitome/application"</code>
74
91
  </dd>
75
92
 
76
93
  <dt> code_theme </dt><dd>
77
- We're using [highlight.js](https://github.com/isagalaev/highlight.js) for code highlighting, and it comes with some great themes. You can check [here for themes](http://softwaremaniacs.org/media/soft/highlight/test.html), and enter the theme as lowercase/underscore.<br/>
78
-
94
+ We're using [highlight.js](https://github.com/isagalaev/highlight.js) for code highlighting, and it comes with some
95
+ great themes. You can check [here for themes](http://softwaremaniacs.org/media/soft/highlight/test.html), and enter
96
+ the theme as lowercase/underscore.
97
+ <br/>
79
98
  <b>default:</b> <code>"default"</code>
80
99
  </dd>
81
100
 
82
101
  <dt> css_override </dt><dd>
83
- This allows you to override the css manually. You typically want to require `apitome/application` within the override, but if you want to override it entirely you can do so.<br/>
84
-
102
+ This allows you to override the css manually. You typically want to require <code>apitome/application</code> within the
103
+ override, but if you want to override it entirely you can do so.
104
+ <br/>
85
105
  <b>default:</b> <code>nil</code>
86
106
  </dd>
87
107
 
88
108
  <dt> js_override </dt><dd>
89
- This allows you to override the javascript manually. You typically want to require `apitome/application` within the override, but if you want to override it entirely you can do so.<br/>
90
-
109
+ This allows you to override the javascript manually. You typically want to require <code>apitome/application</code> within the
110
+ override, but if you want to override it entirely you can do so.
111
+ <br/>
91
112
  <b>default:</b> <code>nil</code>
92
113
  </dd>
93
114
 
94
115
  <dt> readme </dt><dd>
95
- You can provide a "README" style markdown file for the documentation, which is a useful place to include general information. This path is relative to your doc_path configuration.<br/>
96
-
116
+ You can provide a "README" style markdown file for the documentation, which is a useful place to include general
117
+ information. This path is relative to your doc_path configuration.
118
+ <br/>
97
119
  <b>default:</b> <code>"../api.md"</code>
98
120
  </dd>
99
121
 
100
122
  <dt> single_page </dt><dd>
101
- Apitome can render the documentation into a single page that uses scrollspy, or it can render the documentation on individual pages on demand. This allows you to specify which one you want, as a single page may impact performance.<br/>
102
-
123
+ Apitome can render the documentation into a single page that uses scrollspy, or it can render the documentation on
124
+ individual pages on demand. This allows you to specify which one you want, as a single page may impact performance.
125
+ <br/>
103
126
  <b>default:</b> <code>true</code>
104
127
  </dd>
105
128
 
129
+ <dt> url_formatter </dt><dd>
130
+ You can specify how urls are formatted using a Proc or other callable object. Your proc will be called with a
131
+ resource name or link, giving you the opportunity to modify it as necessary for in the documentation url.
132
+ <br/>
133
+ <b>default:</b> <code>-> (str) { str.gsub(/\.json$/, '').underscore.gsub(/[^0-9a-z]+/i, '-') }</code>
134
+ </dd>
106
135
 
107
- ## Customization
136
+ <dt> remote_url </dt><dd>
137
+ You can setup the docs to be loaded from a remote URL if they are not available in the application environment. This
138
+ URL is used as the base location and should be set to where the readme is located. If left nil, local is assumed.
139
+ <br/>
140
+ <b>default:</b> <code>nil</code>
141
+ </dd>
142
+
143
+ <dt> http_basic_authentication </dt><dd>
144
+ If using remote urls you can fetch the remote docs using HTTP Basic Authentication by configuring this to be an
145
+ array of the user and password. (E.g. <code>['user', 'password']</code>)
146
+ <br/>
147
+ <b>default:</b> <code>nil</code>
148
+ </dd>
108
149
 
109
- You can put custom views and partials in your own `views/apitome/docs` -- check the repo here for [examples](https://github.com/modeset/apitome/tree/master/app/views/apitome/docs). You can put any partial in your own path and they will be overridden.
150
+ <dt> precompile_assets </dt><dd>
151
+ By default all assets that ship with this library are precompiled by the asset pipeline. If you would prefer to
152
+ control this yourself, you can disable it by changing this to false.
153
+ <br/>
154
+ <b>default:</b> <code>true</code>
155
+ </dd>
110
156
 
111
- Additional customization can come in the form of providing custom css and javascript. You can do this by creating the files you want (that often times require the default assets in the gem), and then configure Apitome to use those instead of the defaults.
157
+ <dt> simulated_response </dt><dd>
158
+ If <code>simulated_response</code> is disabled you can hide the "Simulated Response" links.
159
+ <br>
160
+ <b>default:</b> <code>true</code>
161
+ </dd>
112
162
 
163
+ When you install Apitime an initializer file (app/config/initializers/apitome.rb) is generated that contains good
164
+ documentation for each configuration directive. Otherwise you can get a refresher by checking the
165
+ [Apitome Configuration](https://github.com/modeset/apitome/wiki/Apitome-Configuration) article.
113
166
 
114
- ## License
167
+ ## Customization
168
+ You can put custom views and partials in your own `views/apitome/docs` -- check
169
+ [here for examples](tree/master/app/views/apitome/docs). You can put any partial in your own path and they will be
170
+ overridden.
115
171
 
116
- Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
172
+ Additional customization can come in the form of providing custom css and javascript. You can do this by creating the
173
+ files you want (that often times require the default assets in the gem), and then configure Apitome to use those instead
174
+ of the defaults.
117
175
 
118
- Copyright 2013 [Mode Set](https://github.com/modeset)
176
+ ## License
177
+ Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
119
178
 
179
+ Copyright 2016 [jejacks0n](https://github.com/jejacks0n)
120
180
 
121
181
  ## Make Code Not War
122
- ![crest](https://secure.gravatar.com/avatar/aa8ea677b07f626479fd280049b0e19f?s=75)
@@ -14,3 +14,19 @@ jQuery(function(){
14
14
  })
15
15
  });
16
16
 
17
+ $(document).ready(function() {
18
+ $(window).scroll(function(){
19
+ if ($(this).scrollTop() > 1500) {
20
+ $('#scroll-to-top').removeClass('hidden').affix({
21
+ offset: { top:100 }
22
+ });
23
+ } else {
24
+ $('#scroll-to-top').addClass('hidden')
25
+ }
26
+ });
27
+
28
+ $("#scroll-to-top").click(function(){
29
+ $('html, body').animate({scrollTop : 0},500);
30
+ return false;
31
+ });
32
+ });
@@ -135,3 +135,13 @@ body.single-page .docs-section > section.readme article {
135
135
  }
136
136
  }
137
137
 
138
+ .sidebar {
139
+ overflow: auto;
140
+ max-height: 550px;
141
+ }
142
+
143
+ #scroll-to-top.affix {
144
+ position: fixed; /* keeps it on the bottom once in view */
145
+ bottom: 18px;
146
+ right: 1px;
147
+ }
@@ -1,8 +1,19 @@
1
- class Apitome::DocsController < ActionController::Base
1
+ require "open-uri"
2
2
 
3
+ class Apitome::DocsController < Object.const_get(Apitome.configuration.parent_controller)
3
4
  layout Apitome.configuration.layout
4
5
 
5
- helper_method :resources, :example, :formatted_body, :param_headers, :param_extras, :formatted_readme, :set_example, :id_for
6
+ helper_method *[
7
+ :resources,
8
+ :example,
9
+ :formatted_body,
10
+ :param_headers,
11
+ :param_extras,
12
+ :formatted_readme,
13
+ :set_example,
14
+ :id_for,
15
+ :rendered_markdown
16
+ ]
6
17
 
7
18
  def index
8
19
  end
@@ -10,61 +21,88 @@ class Apitome::DocsController < ActionController::Base
10
21
  def show
11
22
  end
12
23
 
24
+ def simulate
25
+ request = example["requests"][0]
26
+ if request
27
+ request["response_headers"].delete("Content-Length")
28
+ request["response_headers"].each { |k, v| headers[k] = v }
29
+ render body: request["response_body"], status: request["response_status"]
30
+ else
31
+ render body: "No simulation for this endpoint", status: 404
32
+ end
33
+ end
34
+
13
35
  private
14
36
 
15
- def file_for(file)
16
- file = Apitome.configuration.root.join(Apitome.configuration.doc_path, file)
17
- raise Apitome::FileNotFound.new, "Unable to find #{file}" unless File.exists?(file)
18
- File.read(file)
19
- end
37
+ def file_for(file, readme: false)
38
+ if Apitome.configuration.remote_url
39
+ file = readme ? file : "#{Apitome.configuration.doc_path}/#{file}"
40
+ file = CGI.escape("#{Apitome.configuration.remote_url}/#{file}")
41
+ else
42
+ file = Apitome.configuration.root.join(Apitome.configuration.doc_path, file)
43
+ raise Apitome::FileNotFoundError.new("Unable to find #{file}") unless File.exist?(file)
44
+ end
20
45
 
21
- def resources
22
- @resources ||= JSON.parse(file_for('index.json'))['resources']
23
- end
46
+ open(file, file_opts).read
47
+ end
24
48
 
25
- def example
26
- @example ||= JSON.parse(file_for("#{params[:path]}.json"))
27
- end
49
+ def resources
50
+ @resources ||= JSON.parse(file_for("index.json"))["resources"]
51
+ end
28
52
 
29
- def set_example(resource)
30
- @example = JSON.parse(file_for("#{resource}.json"))
31
- end
53
+ def example
54
+ @example ||= JSON.parse(file_for("#{params[:path]}.json"))
55
+ end
32
56
 
33
- def formatted_readme
34
- file = Apitome.configuration.root.join(Apitome.configuration.doc_path, Apitome.configuration.readme)
35
- if defined?(GitHub::Markdown)
36
- GitHub::Markdown.render_gfm(file_for(file))
37
- else
38
- Kramdown::Document.new(file_for(file)).to_html
57
+ def set_example(resource)
58
+ @example = JSON.parse(file_for("#{resource}.json"))
39
59
  end
40
- end
41
60
 
42
- def formatted_body(body, type)
43
- if type =~ /json/ && body.present?
44
- JSON.pretty_generate(JSON.parse(body))
45
- else
46
- body
61
+ def file_opts
62
+ if Apitome.configuration.remote_url && Apitome.configuration.http_basic_authentication
63
+ { http_basic_authentication: Apitome.configuration.http_basic_authentication }
64
+ else
65
+ {}
66
+ end
47
67
  end
48
- rescue JSON::ParserError
49
- return body if body == " "
50
- raise JSON::ParserError
51
- end
52
68
 
53
- def param_headers(params)
54
- titles = %w{Name Description}
55
- titles += param_extras(params)
56
- end
69
+ def formatted_readme
70
+ return unless Apitome.configuration.readme
71
+ rendered_markdown(file_for(Apitome.configuration.readme, readme: true))
72
+ end
57
73
 
58
- def param_extras(params)
59
- extras = []
60
- for param in params
61
- extras += param.reject{ |k,v| %w{name description required scope}.include?(k) }.keys
74
+ def rendered_markdown(string)
75
+ if defined?(GitHub::Markdown)
76
+ GitHub::Markdown.render(string)
77
+ else
78
+ Kramdown::Document.new(string).to_html
79
+ end
62
80
  end
63
- extras.uniq
64
- end
65
81
 
66
- def id_for(str)
67
- str.gsub(/\.json$/, '').underscore.gsub(/[^0-9a-z]+/i, '-')
68
- end
82
+ def formatted_body(body, type)
83
+ if type =~ /json/ && body.present?
84
+ JSON.pretty_generate(JSON.parse(body))
85
+ else
86
+ body
87
+ end
88
+ rescue JSON::ParserError
89
+ return body if body == " "
90
+ raise JSON::ParserError
91
+ end
92
+
93
+ def param_headers(params)
94
+ titles = %w{Name Description}
95
+ titles += param_extras(params)
96
+ titles
97
+ end
69
98
 
99
+ def param_extras(params)
100
+ params.map do |param|
101
+ param.reject { |k, _v| %w{name description required scope}.include?(k) }.keys
102
+ end.flatten.uniq
103
+ end
104
+
105
+ def id_for(str)
106
+ Apitome.configuration.url_formatter.call(str)
107
+ end
70
108
  end
@@ -0,0 +1,19 @@
1
+ module Apitome::DocsHelper
2
+ def format_scope(scopes)
3
+ Array(scopes).each_with_index.map do |scope, index|
4
+ index == 0 ? scope : "[#{scope}]"
5
+ end.join
6
+ end
7
+
8
+ def resource_link(resource)
9
+ "#{Apitome.configuration.mount_at}/#{CGI.escape(resource['examples'].first['link'].gsub(/\.json$/, ''))}"
10
+ end
11
+
12
+ def example_link(example)
13
+ "#{Apitome.configuration.mount_at}/#{CGI.escape(example['link'].gsub(/\.json$/, ''))}"
14
+ end
15
+
16
+ def link_active?(link)
17
+ current_page?(url_for(link))
18
+ end
19
+ end