avocado-docs 3.0.10 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -13
  2. data/app/assets/javascripts/avocado/app.coffee +1 -0
  3. data/app/assets/javascripts/avocado/application.js.coffee +1 -18
  4. data/app/assets/javascripts/avocado/avocado-ctrl.coffee +50 -0
  5. data/app/assets/javascripts/avocado/{services/request.js.coffee → factories/request.coffee} +5 -3
  6. data/app/assets/javascripts/avocado/factories/resource.coffee +6 -0
  7. data/app/assets/javascripts/avocado/factories/response.coffee +11 -0
  8. data/app/assets/javascripts/avocado/factories/spec.coffee +27 -0
  9. data/app/assets/javascripts/avocado/filters/request-method-filter.coffee +15 -0
  10. data/app/assets/javascripts/avocado/filters/response-status-filter.coffee +15 -0
  11. data/app/controllers/avocado/specs_controller.rb +32 -2
  12. data/app/views/avocado/specs/index.html.erb +51 -0
  13. data/app/views/layouts/avocado.html.erb +20 -0
  14. data/config/routes.rb +1 -1
  15. data/lib/avocado-docs.rb +33 -15
  16. data/lib/avocado/adapters/base_adapter.rb +36 -0
  17. data/lib/avocado/adapters/cucumber_adapter.rb +15 -0
  18. data/lib/avocado/adapters/minitest_adapter.rb +10 -0
  19. data/lib/avocado/adapters/rspec_adapter.rb +13 -0
  20. data/lib/avocado/controller_patch.rb +24 -0
  21. data/lib/avocado/controller_response.rb +22 -0
  22. data/lib/avocado/cucumber.rb +14 -0
  23. data/lib/avocado/logger.rb +13 -0
  24. data/lib/avocado/minitest.rb +10 -23
  25. data/lib/avocado/rspec.rb +9 -18
  26. data/lib/avocado/serializers/request_serializer.rb +43 -0
  27. data/lib/avocado/serializers/resource_serializer.rb +20 -0
  28. data/lib/avocado/serializers/response_serializer.rb +16 -0
  29. data/lib/avocado/{request_store.rb → storage.rb} +6 -9
  30. data/lib/avocado/uploader.rb +41 -31
  31. data/lib/avocado/version.rb +1 -1
  32. metadata +59 -55
  33. data/app/assets/javascripts/avocado/angular-route.min.js +0 -14
  34. data/app/assets/javascripts/avocado/angular.min.js +0 -235
  35. data/app/assets/javascripts/avocado/app.js.coffee +0 -4
  36. data/app/assets/javascripts/avocado/controllers/avocado_ctrl.js.coffee +0 -93
  37. data/app/assets/javascripts/avocado/md5.js +0 -19
  38. data/app/assets/javascripts/avocado/services/endpoint.js.coffee +0 -23
  39. data/app/assets/javascripts/avocado/services/resource.js.coffee +0 -5
  40. data/app/assets/javascripts/avocado/services/response.js.coffee +0 -9
  41. data/app/assets/javascripts/avocado/ui-utils.min.js +0 -7
  42. data/app/controllers/avocado/avocado_controller.rb +0 -20
  43. data/app/models/avocado/endpoint.rb +0 -13
  44. data/app/models/avocado/parser.rb +0 -56
  45. data/app/models/avocado/request.rb +0 -37
  46. data/app/models/avocado/resource.rb +0 -17
  47. data/app/views/layouts/avocado/avocado.html.erb +0 -15
  48. data/app/views/template.html.erb +0 -46
  49. data/lib/avocado/config.rb +0 -36
  50. data/lib/avocado/controller.rb +0 -26
  51. data/lib/avocado/middleware.rb +0 -37
  52. data/lib/avocado/middleware/defaults.rb +0 -17
  53. data/lib/avocado/middleware/document_if_configuration.rb +0 -12
  54. data/lib/avocado/middleware/document_metadata.rb +0 -14
  55. data/lib/avocado/middleware/example_serialization.rb +0 -10
  56. data/lib/avocado/middleware/ignore_xhr_requests.rb +0 -10
  57. data/lib/avocado/middleware/request_serialization.rb +0 -48
  58. data/lib/avocado/middleware/resource_serialization.rb +0 -20
  59. data/lib/avocado/middleware/response_serialization.rb +0 -20
  60. data/lib/avocado/packages/minitest_package.rb +0 -15
  61. data/lib/avocado/packages/package.rb +0 -23
  62. data/lib/avocado/packages/rspec_package.rb +0 -15
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWNhYWQ1YzY5NzQ5MmE2N2IwZWRkOWZhMjEwNmExOTI5MjBlMDZiZg==
5
- data.tar.gz: !binary |-
6
- NTMzMWY2MTU3YjA3YzA3MjMwOGUxNjE2NWQzZDdlZDVmYzk5ODFhYQ==
2
+ SHA1:
3
+ metadata.gz: d41e3b7113ec16d2179bd7a53a11df303a21abe0
4
+ data.tar.gz: cadc27ef5996be8a1a349e5a2cefa0a0955d7126
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjA4Y2YyODA4MGViOTg3NWYyNzlkNTQzMmI4NTMyYjJkYWRhZDc0ZTFlNjJl
10
- N2IzNjY1Mjg0YTBiNTQ2NjIwMWViNTY0MmM2OGQyNDM4ZWRmNjk0NTZlYTE3
11
- ZmMwODNjMjAwMmMxMTg2MmNkOTZlNmVkZWU1ZmZmMmJkMTNkYmU=
12
- data.tar.gz: !binary |-
13
- YTU2MzM5M2NiZjhjODVmYzQ5MGZjNTc3YWZmMzQ0MmZjYjNmYjVkYjdhYTg4
14
- NWZmMmQzYjg3MGNjZDI3M2Q4NjExNTZjYTI5ODFlYWE5MDY2NDliZjVlMzdi
15
- MDRiY2Q1YWY1ZWE2NmI1ZmMzNjVlNjQ5YjM0ZDk3MGViOWYwZjA=
6
+ metadata.gz: 3a299f666560f1bcf1c6f966cec5d34188bd54e250252a5fe9ccc85f32dd48fba534b97d778adc8a5c56ee7ca12ea5aa32e62602a3e93d69c763b79e8478ca04
7
+ data.tar.gz: cf28d6e25966fd6a8fbea3b3c53b5561afeaba60e24ba9401a61e827bf7d93aad5a4c35b06a0b3e42ff3e59b68cc1e87cd31de8f50314c25ee8750554229b716
@@ -0,0 +1 @@
1
+ app = angular.module 'avocado', ['angular.filter']
@@ -1,22 +1,5 @@
1
- # This is a manifest file that'll be compiled into application.js, which will include all the files
2
- # listed below.
3
- #
4
- # Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- # or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- #
7
- # It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- # compiled file.
9
- #
10
- # Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- # about supported directives.
12
- #
13
1
  #= require jquery
14
2
  #= require jquery_ujs
15
- #= require avocado/angular.min
16
- #= require avocado/angular-route.min
17
- #= require avocado/ui-utils.min
18
- #= require avocado/app
19
- #= require avocado/md5
20
3
  #= require_tree .
21
4
 
22
5
  $ ->
@@ -27,4 +10,4 @@ $ ->
27
10
  $('.left-side, .right-side').mouseup (e) ->
28
11
  container = $('.filters')
29
12
  if !(container.is(e.target)) && (container.has(e.target).length is 0)
30
- container.hide()
13
+ container.hide()
@@ -0,0 +1,50 @@
1
+ angular.module('avocado')
2
+
3
+ .controller 'AvocadoCtrl', ['$scope', '$location', 'Spec', 'ResponseStatusFilter', 'RequestMethodFilter', ($scope, $location, Spec, ResponseStatusFilter, RequestMethodFilter) ->
4
+ new class AvocadoCtrl
5
+ constructor: ->
6
+ @allSpecs = Spec.all()
7
+ @specs = Spec.all()
8
+ @query = undefined
9
+ @activeSpec = @_findActiveSpec() if @_specUUIDGiven()
10
+ @activeResource = 'All'
11
+
12
+ @filters = [
13
+ new ResponseStatusFilter(200, 299, true)
14
+ new RequestMethodFilter('GET')
15
+ new RequestMethodFilter('POST')
16
+ new RequestMethodFilter('PATCH', 'PUT')
17
+ new RequestMethodFilter('DELETE')
18
+ ]
19
+
20
+ chooseSpec: (spec) ->
21
+ @activeSpec = spec
22
+ $location.path spec.uuid
23
+
24
+ chooseResource: ->
25
+ resourceName = @activeResource.replace /\s+/g, ''
26
+ @specs = if resourceName is 'All' then @allSpecs else Spec.forResource(resourceName)
27
+
28
+ getFilteredSpecs: ->
29
+ specs = @specs
30
+ activeFilters = @filters.filter (f) -> f.active
31
+ strictFilters = activeFilters.filter (f) -> f.strict
32
+ relaxedFilters = activeFilters.filter (f) -> !f.strict
33
+
34
+ specs.filter (spec) ->
35
+ result = strictFilters.every((f) -> f.apply(spec))
36
+ result &&= relaxedFilters.some((f) -> f.apply(spec)) if relaxedFilters.length > 0
37
+ result
38
+
39
+ search: (spec) =>
40
+ return true if !@query
41
+ [spec.request.path, spec.description].some (term) =>
42
+ term.toLowerCase().indexOf(@query.toLowerCase()) != -1
43
+
44
+ _findActiveSpec: ->
45
+ specUUID = $location.path().substr 1
46
+ @activeSpec = @allSpecs.find (spec) -> spec.uuid == specUUID
47
+
48
+ _specUUIDGiven: ->
49
+ $location.path().length > 0
50
+ ]
@@ -1,12 +1,14 @@
1
- angular.module('avocado.services').factory 'Request', ->
1
+ angular.module('avocado')
2
2
 
3
+ .factory 'Request', ->
3
4
  class Request
4
5
  constructor: (json) ->
5
6
  @method = json.method
6
7
  @path = json.path
7
8
  @params = JSON.stringify(json.params, undefined, 2)
9
+ @headers = ''
8
10
 
9
- @headers = ""
10
- for name,value of json.headers
11
+ for name, value of json.headers
11
12
  @headers = "#{@headers}\n#{name}: #{value}"
13
+
12
14
  @headers = @headers.trim()
@@ -0,0 +1,6 @@
1
+ angular.module('avocado')
2
+
3
+ .factory 'Resource', ->
4
+ class Resource
5
+ constructor: (json) ->
6
+ @name = json.name
@@ -0,0 +1,11 @@
1
+ angular.module('avocado')
2
+
3
+ .factory 'Response', ->
4
+ class Response
5
+ constructor: (json) ->
6
+ @statusCode = json.status
7
+
8
+ try
9
+ @body = JSON.stringify JSON.parse(json.body), undefined, 2
10
+ catch e
11
+ @body = ''
@@ -0,0 +1,27 @@
1
+ angular.module('avocado')
2
+
3
+ .factory 'Spec', ['Request', 'Response', 'Resource', (Request, Response, Resource) ->
4
+
5
+ class Spec
6
+ constructor: (json) ->
7
+ @description = json.description
8
+ @request = new Request json.request
9
+ @response = new Response json.response
10
+ @resource = new Resource json.resource
11
+ @uuid = @generateMD5Hash @request, @response
12
+
13
+ @all: ->
14
+ specs = []
15
+ window.data.forEach (data) ->
16
+ angular.fromJson(data).forEach (data) ->
17
+ specs.push new Spec(data)
18
+ specs
19
+
20
+ @forResource: (resourceName) ->
21
+ @all().filter (spec) ->
22
+ spec.resource.name.replace(/\s+/g, '') == resourceName
23
+
24
+ generateMD5Hash: (request, response) ->
25
+ hashTarget = @description + request.method + request.path + request.params + request.headers
26
+ md5(hashTarget).toString().substr 0, 7
27
+ ]
@@ -0,0 +1,15 @@
1
+ angular.module('avocado')
2
+
3
+ .factory 'RequestMethodFilter', ->
4
+ class RequestMethodFilter
5
+ constructor: (methods...) ->
6
+ @methods = methods
7
+ @active = false
8
+ @strict = false
9
+
10
+ getName: ->
11
+ @methods[0]
12
+
13
+ apply: (item) ->
14
+ @methods.some (method) ->
15
+ item.request.method == method
@@ -0,0 +1,15 @@
1
+ angular.module('avocado')
2
+
3
+ .factory 'ResponseStatusFilter', ->
4
+ class ResponseStatusFilter
5
+ constructor: (minCode, maxCode, active = false) ->
6
+ @minCode = minCode
7
+ @maxCode = maxCode
8
+ @active = active
9
+ @strict = true
10
+
11
+ getName: ->
12
+ @minCode
13
+
14
+ apply: (item) ->
15
+ @minCode <= item.response.statusCode <= @maxCode
@@ -1,4 +1,34 @@
1
1
  module Avocado
2
- class SpecsController < AvocadoController
2
+ class SpecsController < ::ActionController::Base
3
+ layout 'avocado'
4
+
5
+ def index
6
+ @data = json_files.map { |filename| File.read filename }
7
+ end
8
+
9
+ def create
10
+ File.open(new_json_filename, 'w+') { |f| f.write params[:file].read }
11
+ File.delete(*json_files_from_past_uploads)
12
+ head :ok
13
+ end
14
+
15
+ private
16
+ def upload_id
17
+ params[:upload_id]
18
+ end
19
+
20
+ def new_json_filename
21
+ Avocado.json_path.join "avocado-#{Time.current.to_s(:nsec)}-#{Avocado.upload_id.call}.json"
22
+ end
23
+
24
+ def json_files
25
+ Dir.glob Avocado.json_path.join('avocado*.json')
26
+ end
27
+
28
+ def json_files_from_past_uploads
29
+ json_files.reject do |spec|
30
+ spec.end_with? "-#{upload_id}.json"
31
+ end
32
+ end
3
33
  end
4
- end
34
+ end
@@ -0,0 +1,51 @@
1
+ <div class="top-bar">
2
+ <a href="#" id="toggle-filter"><%= image_tag 'avocado/filter-icon.png'%></a>
3
+
4
+ <select ng-model="ctrl.activeResource" ng-change="ctrl.chooseResource()">
5
+ <option ng-selected="true">All</option>
6
+ <option ng-repeat="spec in ctrl.allSpecs | unique: 'resource.name' | orderBy: 'resource.name'"/>
7
+ {{ spec.resource.name }}
8
+ </option>
9
+ </select>
10
+
11
+ <input type="text" ng-model="ctrl.query" placeholder="Search..." />
12
+
13
+ <div class="filters">
14
+ <label ng-repeat="filter in ctrl.filters">
15
+ <input type="checkbox" ng-model="filter.active" value="{{ filter.getName() }}" />
16
+ {{ filter.getName() }}
17
+ </label>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="left-side">
22
+ <ul>
23
+ <li ng-repeat="spec in ctrl.getFilteredSpecs() | filter: ctrl.search" ng-click="ctrl.chooseSpec(spec)" ng-class="{ 'active': (spec == ctrl.activeSpec) }">
24
+ <span class="status-code">{{spec.response.statusCode}}</span>
25
+ <span class="url">{{spec.request.method}} {{spec.request.path}}</span>
26
+ <span class="description">{{spec.description}}</span>
27
+ </li>
28
+ </ul>
29
+ </div>
30
+
31
+ <div class="right-side">
32
+ <div ng-if="ctrl.activeSpec">
33
+ <span class="url">{{ctrl.activeSpec.request.method}} {{ctrl.activeSpec.request.path}}</span>
34
+ <desc>Request Parameters</desc>
35
+ <code class="request-params">
36
+ {{ctrl.activeSpec.request.params}}
37
+ </code>
38
+ <desc>Headers</desc>
39
+ <code class="headers">
40
+ {{ctrl.activeSpec.request.headers}}
41
+ </code>
42
+ <desc>Response Status</desc>
43
+ <code class="response-status">
44
+ {{ctrl.activeSpec.response.statusCode}}
45
+ </code>
46
+ <desc>Response Body</desc>
47
+ <code class="response-body">
48
+ {{ctrl.activeSpec.response.body}}
49
+ </code>
50
+ </div>
51
+ </div>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>API Docs</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
6
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.11/angular-filter.min.js"></script>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.4.0/js/md5.min.js"></script>
8
+
9
+ <%= stylesheet_link_tag "avocado/application", media: "all" %>
10
+ <%= javascript_include_tag "avocado/application" %>
11
+ <%= csrf_meta_tags %>
12
+
13
+ <script type="text/javascript">
14
+ var data = <%= @data.to_json.html_safe %>;
15
+ </script>
16
+ </head>
17
+ <body ng-app="avocado" ng-controller="AvocadoCtrl as ctrl">
18
+ <%= yield %>
19
+ </body>
20
+ </html>
@@ -1,4 +1,4 @@
1
1
  Avocado::Engine.routes.draw do
2
- root to: 'specs#index'
3
2
  resources :specs, only: [:create]
3
+ root to: 'specs#index'
4
4
  end
@@ -1,21 +1,39 @@
1
1
  require 'avocado/engine'
2
- require 'avocado/config'
2
+ require 'avocado/controller_patch'
3
+ require 'avocado/controller_response'
4
+ require 'avocado/logger'
5
+ require 'avocado/storage'
3
6
  require 'avocado/uploader'
4
- require 'avocado/controller'
5
- require 'avocado/request_store'
6
- require 'avocado/packages/package'
7
- require 'avocado/packages/minitest_package'
8
- require 'avocado/packages/rspec_package'
9
- require 'avocado/middleware'
10
- require 'avocado/middleware/defaults'
11
-
12
- require 'yaml'
13
- require 'net/http/post/multipart'
7
+ require 'avocado/adapters/base_adapter'
8
+ require 'avocado/adapters/minitest_adapter'
9
+ require 'avocado/adapters/rspec_adapter'
10
+ require 'avocado/adapters/cucumber_adapter'
11
+ require 'avocado/serializers/request_serializer'
12
+ require 'avocado/serializers/resource_serializer'
13
+ require 'avocado/serializers/response_serializer'
14
14
 
15
15
  module Avocado
16
- def self.reset!
17
- Avocado::Config.reset!
18
- Avocado::RequestStore.instance.reset!
19
- Avocado::Uploader.instance.payload = []
16
+ class << self
17
+ attr_accessor :url, :headers, :json_path, :upload_id, :document_if, :ignored_params, :storage, :uploader
18
+
19
+ def configure
20
+ yield self
21
+ end
22
+
23
+ def reset!
24
+ self.url = nil
25
+ self.headers = []
26
+ self.json_path = ::Rails.root
27
+ self.upload_id = proc { SecureRandom.uuid }
28
+ self.document_if = proc { true }
29
+ self.ignored_params = %w(controller action format)
30
+ self.storage = Avocado::Storage.instance
31
+ self.uploader = Avocado::Uploader.instance
32
+
33
+ storage.clear
34
+ uploader.reset
35
+ end
20
36
  end
21
37
  end
38
+
39
+ Avocado.reset!
@@ -0,0 +1,36 @@
1
+ module Avocado
2
+ module Adapters
3
+ class BaseAdapter
4
+ attr_accessor :spec, :request, :response
5
+
6
+ def initialize(spec, request, response)
7
+ @spec = spec
8
+ @request = request
9
+ @response = response
10
+ end
11
+
12
+ def upload?(&block)
13
+ block ||= proc { true }
14
+ request && response && !ajax? && document_if? && block.call
15
+ end
16
+
17
+ def to_h
18
+ {
19
+ description: spec.description,
20
+ resource: Avocado::Serializers::ResourceSerializer.new(request).to_h,
21
+ request: Avocado::Serializers::RequestSerializer.new(request).to_h,
22
+ response: Avocado::Serializers::ResponseSerializer.new(response).to_h
23
+ }
24
+ end
25
+
26
+ private
27
+ def ajax?
28
+ request.xhr?
29
+ end
30
+
31
+ def document_if?
32
+ Avocado.document_if.call request, response
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module Avocado
2
+ module Adapters
3
+ class CucumberAdapter < BaseAdapter
4
+ def description
5
+ spec.name
6
+ end
7
+
8
+ def upload?
9
+ super do
10
+ spec.tags.none? { |tag| tag.name == 'nodoc' }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Avocado
2
+ module Adapters
3
+ class MinitestAdapter < BaseAdapter
4
+ # In Minitest case, the spec object is just the name of the spec
5
+ def description
6
+ spec
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Avocado
2
+ module Adapters
3
+ class RSpecAdapter < BaseAdapter
4
+ def description
5
+ spec.description
6
+ end
7
+
8
+ def upload?
9
+ super { spec.metadata[:document] != false }
10
+ end
11
+ end
12
+ end
13
+ end