useless-doc 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/useless/doc/{rack → proxy}/css.rb +2 -2
- data/lib/useless/doc/{rack → proxy}/html.rb +2 -2
- data/lib/useless/doc/{rack → proxy}/subject.rb +2 -2
- data/lib/useless/doc/{rack → proxy}/ui.rb +2 -2
- data/lib/useless/doc/{rack → proxy}/url.rb +2 -2
- data/lib/useless/doc/{rack.rb → proxy.rb} +11 -11
- data/lib/useless/doc/server/sinatra.rb +85 -0
- data/lib/useless/doc/version.rb +1 -1
- data/spec/config.ru +2 -2
- data/spec/useless/doc/client_spec.rb +3 -3
- data/spec/useless/doc/{rack → proxy}/css_spec.rb +3 -3
- data/spec/useless/doc/{rack → proxy}/html_spec.rb +3 -3
- data/spec/useless/doc/{rack → proxy}/subject_spec.rb +3 -3
- data/spec/useless/doc/{rack → proxy}/ui_spec.rb +3 -3
- data/spec/useless/doc/{rack → proxy}/url_spec.rb +3 -3
- data/spec/useless/doc/{rack_spec.rb → proxy_spec.rb} +4 -4
- data/spec/useless/doc/serialization/load_spec.rb +2 -2
- data/spec/useless/doc/{sinatra_spec.rb → server/sinatra_spec.rb} +4 -4
- data/spec/useless/doc/ui/godel_spec.rb +1 -1
- metadata +25 -25
- data/lib/useless/doc/sinatra.rb +0 -83
- /data/spec/documents/{twonk.json → resource.json} +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
module Useless
|
2
2
|
module Doc
|
3
|
-
class
|
3
|
+
class Proxy
|
4
4
|
|
5
|
-
# +Doc::
|
5
|
+
# +Doc::Proxy::CSS+ serves the stylesheet for the current +Doc::UI+
|
6
6
|
# iff the request path is '/doc.css'. Otherwise, it passes the request
|
7
7
|
# down the stack.
|
8
8
|
#
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Useless
|
2
2
|
module Doc
|
3
|
-
class
|
3
|
+
class Proxy
|
4
4
|
|
5
|
-
# +Doc::
|
5
|
+
# +Doc::Proxy::HTML+ is the base application for +Useless::Doc::Proxy+.
|
6
6
|
# It expects a +Doc::UI+ instance to be set as 'useless.doc.ui', and a
|
7
7
|
# +Doc::Core+ entity to be set as 'useless.doc.subject', and then simply
|
8
8
|
# passes the latter to the former's +#html+ method.
|
@@ -2,9 +2,9 @@ require 'useless/doc/client'
|
|
2
2
|
|
3
3
|
module Useless
|
4
4
|
module Doc
|
5
|
-
class
|
5
|
+
class Proxy
|
6
6
|
|
7
|
-
# +Doc::
|
7
|
+
# +Doc::Proxy::Subject+ retrieves a +Doc::Core+ entity based upon
|
8
8
|
# 'useless.doc.url', from a environment-appropriate +Doc::Client+,
|
9
9
|
# and sets it to 'useless.doc.subject'.
|
10
10
|
#
|
@@ -3,9 +3,9 @@ require 'useless/doc/ui/godel'
|
|
3
3
|
|
4
4
|
module Useless
|
5
5
|
module Doc
|
6
|
-
class
|
6
|
+
class Proxy
|
7
7
|
|
8
|
-
# +Doc::
|
8
|
+
# +Doc::Proxy::UI+ chooses which UI should be used to render the
|
9
9
|
# documentation and sets it to 'useless.doc.ui'.
|
10
10
|
#
|
11
11
|
# It could theoretically be chosen via the 'ui' parameter,
|
@@ -2,9 +2,9 @@ require 'rack/request'
|
|
2
2
|
|
3
3
|
module Useless
|
4
4
|
module Doc
|
5
|
-
class
|
5
|
+
class Proxy
|
6
6
|
|
7
|
-
# +Doc::
|
7
|
+
# +Doc::Proxy::URL+ translates the request URL into the corresponding
|
8
8
|
# API URL using the specified 'useless.doc.router'.
|
9
9
|
#
|
10
10
|
class URL
|
@@ -6,15 +6,15 @@ require 'low/rack/log_level'
|
|
6
6
|
require 'low/rack/request_logger'
|
7
7
|
|
8
8
|
require 'useless/doc/router'
|
9
|
-
require 'useless/doc/
|
10
|
-
require 'useless/doc/
|
11
|
-
require 'useless/doc/
|
12
|
-
require 'useless/doc/
|
13
|
-
require 'useless/doc/
|
9
|
+
require 'useless/doc/proxy/ui'
|
10
|
+
require 'useless/doc/proxy/css'
|
11
|
+
require 'useless/doc/proxy/url'
|
12
|
+
require 'useless/doc/proxy/subject'
|
13
|
+
require 'useless/doc/proxy/html'
|
14
14
|
|
15
15
|
module Useless
|
16
16
|
module Doc
|
17
|
-
class
|
17
|
+
class Proxy
|
18
18
|
def initialize(router = nil)
|
19
19
|
@router = router || Useless::Doc::Router.default
|
20
20
|
end
|
@@ -35,11 +35,11 @@ module Useless
|
|
35
35
|
use Low::Rack::RequestLogger, key: 'useless.doc.logger'
|
36
36
|
use ::Rack::CommonLogger
|
37
37
|
|
38
|
-
use
|
39
|
-
use
|
40
|
-
use
|
41
|
-
use
|
42
|
-
run
|
38
|
+
use UI
|
39
|
+
use CSS
|
40
|
+
use URL
|
41
|
+
use Subject
|
42
|
+
run HTML
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
require 'useless/doc/dsl'
|
4
|
+
require 'useless/doc/serialization/dump'
|
5
|
+
|
6
|
+
module Useless
|
7
|
+
module Doc
|
8
|
+
module Server
|
9
|
+
|
10
|
+
# Provides access to the +Doc::DSL+ via the +.doc+ method. The JSON of the
|
11
|
+
# API doc that is built will be served via an OPTIONS request to the root.
|
12
|
+
# Resource documentation is similarly served via an OPTIONS request to the
|
13
|
+
# corresponding path.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# class ResourceApp < Sinatra::Base
|
17
|
+
# register Useless::Doc::Sinatra
|
18
|
+
#
|
19
|
+
# doc 'Resouces API' do
|
20
|
+
# url 'resources.useless.io'
|
21
|
+
# description 'A place with resources'
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# doc.get '/some-resources' do
|
25
|
+
# description 'Get all of these resources'
|
26
|
+
#
|
27
|
+
# request do
|
28
|
+
# parameter 'page', 'The page of resources to return.'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# response do
|
32
|
+
# body do
|
33
|
+
# attribute 'name', 'The name of the resource.'
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# ...
|
39
|
+
#
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
module Sinatra
|
43
|
+
def doc=(doc)
|
44
|
+
@doc = doc
|
45
|
+
end
|
46
|
+
|
47
|
+
def doc(name = nil, &block)
|
48
|
+
@dsl ||= Useless::Doc::DSL::API.new(name: name)
|
49
|
+
@dsl.instance_eval(&block) if block_given?
|
50
|
+
@dsl
|
51
|
+
end
|
52
|
+
|
53
|
+
def generated_doc
|
54
|
+
@doc ||= @dsl.generate if @dsl
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.registered(app)
|
58
|
+
app.options '/' do
|
59
|
+
if api = self.class.generated_doc
|
60
|
+
last_modified api.timestamp
|
61
|
+
Useless::Doc::Serialization::Dump.api(api)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
app.options '/*' do
|
66
|
+
if api = self.class.generated_doc
|
67
|
+
resource = api.resources.find do |resource|
|
68
|
+
resource.path == "/#{params[:splat].first}"
|
69
|
+
end
|
70
|
+
|
71
|
+
if resource
|
72
|
+
last_modified api.timestamp
|
73
|
+
return Useless::Doc::Serialization::Dump.resource(resource)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
pass
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Sinatra.register Useless::Doc::Server::Sinatra
|
data/lib/useless/doc/version.rb
CHANGED
data/spec/config.ru
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
require 'uri'
|
5
5
|
require 'useless/doc/router'
|
6
|
-
require 'useless/doc/
|
6
|
+
require 'useless/doc/proxy'
|
7
7
|
|
8
8
|
class TestRouter
|
9
9
|
include Useless::Doc::Router
|
@@ -16,4 +16,4 @@ class TestRouter
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
run Useless::Doc::
|
19
|
+
run Useless::Doc::Proxy.new(TestRouter.new)
|
@@ -11,7 +11,7 @@ describe Useless::Doc::Client::Standard do
|
|
11
11
|
it 'should make a normal request if the cache is empty.' do
|
12
12
|
Typhoeus.should_receive(:options).
|
13
13
|
with('http://some-api.granmal.com/some/resource', headers: { 'Accept' => 'application/json' }).
|
14
|
-
and_return(mock(:response, response_code: 200, response_body: load_document('
|
14
|
+
and_return(mock(:response, response_code: 200, response_body: load_document('resource.json').read))
|
15
15
|
|
16
16
|
resource = @client.get('http://some-api.granmal.com/some/resource')
|
17
17
|
resource.path.should == '/twonks/:id'
|
@@ -32,7 +32,7 @@ describe Useless::Doc::Client::Standard do
|
|
32
32
|
|
33
33
|
Typhoeus.should_receive(:options).once.
|
34
34
|
with('http://some-api.granmal.com/some/resource', headers: { 'Accept' => 'application/json' }).
|
35
|
-
and_return(mock(:response, response_code: 200, response_body: load_document('
|
35
|
+
and_return(mock(:response, response_code: 200, response_body: load_document('resource.json').read))
|
36
36
|
|
37
37
|
Typhoeus.should_receive(:options).once.
|
38
38
|
with('http://some-api.granmal.com/some/resource', headers: { 'Accept' => 'application/json', 'If-Modified-Since' => now.httpdate}).
|
@@ -47,7 +47,7 @@ end
|
|
47
47
|
describe Useless::Doc::Client::Stub do
|
48
48
|
it 'should serve files from the spec/documents directory' do
|
49
49
|
client = Useless::Doc::Client.stub
|
50
|
-
resource = client.get('http://anything.useless.io/
|
50
|
+
resource = client.get('http://anything.useless.io/resource')
|
51
51
|
resource.path.should == '/twonks/:id'
|
52
52
|
end
|
53
53
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
|
-
require 'useless/doc/
|
4
|
+
require 'useless/doc/proxy/css'
|
5
5
|
require 'useless/doc/ui/godel'
|
6
6
|
|
7
|
-
describe Useless::Doc::
|
7
|
+
describe Useless::Doc::Proxy::CSS do
|
8
8
|
include Rack::Test::Methods
|
9
9
|
|
10
10
|
def base_app
|
@@ -16,7 +16,7 @@ describe Useless::Doc::Rack::CSS do
|
|
16
16
|
def app
|
17
17
|
@app ||= lambda do |env|
|
18
18
|
env['useless.doc.ui'] = Useless::Doc::UI::Godel
|
19
|
-
Useless::Doc::
|
19
|
+
Useless::Doc::Proxy::CSS.new(base_app).call(env)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
3
3
|
require 'rack/test'
|
4
4
|
require 'useless/doc/ui/godel'
|
5
5
|
require 'useless/doc/core/api'
|
6
|
-
require 'useless/doc/
|
6
|
+
require 'useless/doc/proxy/html'
|
7
7
|
|
8
|
-
describe Useless::Doc::
|
8
|
+
describe Useless::Doc::Proxy::HTML do
|
9
9
|
include Rack::Test::Methods
|
10
10
|
|
11
11
|
before(:all) do
|
@@ -18,7 +18,7 @@ describe Useless::Doc::Rack::HTML do
|
|
18
18
|
env['useless.doc.ui'] = @ui
|
19
19
|
env['useless.doc.subject'] = @subject
|
20
20
|
|
21
|
-
Useless::Doc::
|
21
|
+
Useless::Doc::Proxy::HTML.call(env)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
|
-
require 'useless/doc/
|
4
|
+
require 'useless/doc/proxy/subject'
|
5
5
|
|
6
|
-
describe Useless::Doc::
|
6
|
+
describe Useless::Doc::Proxy::Subject do
|
7
7
|
include Rack::Test::Methods
|
8
8
|
|
9
9
|
def app
|
@@ -13,7 +13,7 @@ describe Useless::Doc::Rack::Subject do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
env['useless.doc.url'] = 'some.api.com'
|
16
|
-
Useless::Doc::
|
16
|
+
Useless::Doc::Proxy::Subject.new(base_app).call(env)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
|
-
require 'useless/doc/
|
4
|
+
require 'useless/doc/proxy/ui'
|
5
5
|
|
6
|
-
describe Useless::Doc::
|
6
|
+
describe Useless::Doc::Proxy::UI do
|
7
7
|
include Rack::Test::Methods
|
8
8
|
|
9
9
|
def app
|
@@ -12,7 +12,7 @@ describe Useless::Doc::Rack::UI do
|
|
12
12
|
[200, {'Content-Type' => 'text/plain'}, [env['useless.doc.ui'].class.name]]
|
13
13
|
end
|
14
14
|
|
15
|
-
Useless::Doc::
|
15
|
+
Useless::Doc::Proxy::UI.new(base_app)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
4
|
require 'useless/doc/router'
|
5
|
-
require 'useless/doc/
|
5
|
+
require 'useless/doc/proxy/url'
|
6
6
|
|
7
|
-
describe Useless::Doc::
|
7
|
+
describe Useless::Doc::Proxy::URL do
|
8
8
|
include Rack::Test::Methods
|
9
9
|
|
10
10
|
def app
|
@@ -14,7 +14,7 @@ describe Useless::Doc::Rack::URL do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
env['useless.doc.router'] = Useless::Doc::Router.default
|
17
|
-
Useless::Doc::
|
17
|
+
Useless::Doc::Proxy::URL.new(base_app).call(env)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
4
|
require 'useless/doc'
|
5
|
-
require 'useless/doc/
|
5
|
+
require 'useless/doc/proxy'
|
6
6
|
require 'useless/doc/client'
|
7
7
|
|
8
|
-
describe Useless::Doc::
|
8
|
+
describe Useless::Doc::Proxy do
|
9
9
|
include Rack::Test::Methods
|
10
10
|
|
11
11
|
def app
|
12
|
-
Useless::Doc::
|
12
|
+
Useless::Doc::Proxy.new
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return a 404 if the JSON cannot be retrieved' do
|
@@ -49,7 +49,7 @@ describe Useless::Doc::Rack do
|
|
49
49
|
it 'should return resource HTML if proper JSON is retrieved' do
|
50
50
|
Useless::Doc::Client.stub.should_receive(:get).
|
51
51
|
with('http://some-api.useless.io/some/resource').
|
52
|
-
and_return(Useless::Doc.load.resource(load_document('
|
52
|
+
and_return(Useless::Doc.load.resource(load_document('resource.json').read))
|
53
53
|
|
54
54
|
get 'http://some-api.doc.useless.io/some/resource'
|
55
55
|
last_response.should be_ok
|
@@ -33,7 +33,7 @@ describe Useless::Doc::Serialization::Load do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should return a Resource instance if resource JSON is provided' do
|
36
|
-
document = load_document('
|
36
|
+
document = load_document('resource.json')
|
37
37
|
resource = Useless::Doc::Serialization::Load.load document.read
|
38
38
|
resource.should be_an_instance_of(Useless::Doc::Core::Resource)
|
39
39
|
end
|
@@ -68,7 +68,7 @@ describe Useless::Doc::Serialization::Load do
|
|
68
68
|
|
69
69
|
describe '.resource' do
|
70
70
|
it 'should parse the specified JSON into a model hierarchy' do
|
71
|
-
document = load_document('
|
71
|
+
document = load_document('resource.json')
|
72
72
|
resource = Useless::Doc::Serialization::Load.resource document.read
|
73
73
|
|
74
74
|
resource.should be_a Useless::Doc::Core::Resource
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
2
|
|
3
3
|
require 'rack/test'
|
4
4
|
require 'sinatra/base'
|
5
|
-
require 'useless/doc/sinatra'
|
5
|
+
require 'useless/doc/server/sinatra'
|
6
6
|
require 'useless/doc/serialization/load'
|
7
7
|
|
8
|
-
describe Useless::Doc::Sinatra do
|
8
|
+
describe Useless::Doc::Server::Sinatra do
|
9
9
|
class DocApp < Sinatra::Base
|
10
|
-
register Useless::Doc::Sinatra
|
10
|
+
register Useless::Doc::Server::Sinatra
|
11
11
|
|
12
12
|
doc 'Resoruce API' do
|
13
13
|
url 'resource.useless.io'
|
@@ -118,7 +118,7 @@ describe Useless::Doc::UI::Godel do
|
|
118
118
|
|
119
119
|
context 'for a Core::Resource instance' do
|
120
120
|
before(:each) do
|
121
|
-
json = load_document('
|
121
|
+
json = load_document('resource.json').read
|
122
122
|
router = Useless::Doc::Router.default
|
123
123
|
resource = Useless::Doc.load.resource json
|
124
124
|
result = Useless::Doc::UI::Godel.new(router).html(resource)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: useless-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oj
|
@@ -193,16 +193,16 @@ files:
|
|
193
193
|
- lib/useless/doc/core/resource.rb
|
194
194
|
- lib/useless/doc/core/response.rb
|
195
195
|
- lib/useless/doc/dsl.rb
|
196
|
-
- lib/useless/doc/
|
197
|
-
- lib/useless/doc/
|
198
|
-
- lib/useless/doc/
|
199
|
-
- lib/useless/doc/
|
200
|
-
- lib/useless/doc/
|
201
|
-
- lib/useless/doc/
|
196
|
+
- lib/useless/doc/proxy.rb
|
197
|
+
- lib/useless/doc/proxy/css.rb
|
198
|
+
- lib/useless/doc/proxy/html.rb
|
199
|
+
- lib/useless/doc/proxy/subject.rb
|
200
|
+
- lib/useless/doc/proxy/ui.rb
|
201
|
+
- lib/useless/doc/proxy/url.rb
|
202
202
|
- lib/useless/doc/router.rb
|
203
203
|
- lib/useless/doc/serialization/dump.rb
|
204
204
|
- lib/useless/doc/serialization/load.rb
|
205
|
-
- lib/useless/doc/sinatra.rb
|
205
|
+
- lib/useless/doc/server/sinatra.rb
|
206
206
|
- lib/useless/doc/ui.rb
|
207
207
|
- lib/useless/doc/ui/godel.rb
|
208
208
|
- lib/useless/doc/ui/godel/api.mustache
|
@@ -213,20 +213,20 @@ files:
|
|
213
213
|
- spec/config.ru
|
214
214
|
- spec/documents/api.json
|
215
215
|
- spec/documents/domain.json
|
216
|
-
- spec/documents/
|
216
|
+
- spec/documents/resource.json
|
217
217
|
- spec/spec_helper.rb
|
218
218
|
- spec/useless/doc/client_spec.rb
|
219
219
|
- spec/useless/doc/dsl_spec.rb
|
220
|
-
- spec/useless/doc/
|
221
|
-
- spec/useless/doc/
|
222
|
-
- spec/useless/doc/
|
223
|
-
- spec/useless/doc/
|
224
|
-
- spec/useless/doc/
|
225
|
-
- spec/useless/doc/
|
220
|
+
- spec/useless/doc/proxy/css_spec.rb
|
221
|
+
- spec/useless/doc/proxy/html_spec.rb
|
222
|
+
- spec/useless/doc/proxy/subject_spec.rb
|
223
|
+
- spec/useless/doc/proxy/ui_spec.rb
|
224
|
+
- spec/useless/doc/proxy/url_spec.rb
|
225
|
+
- spec/useless/doc/proxy_spec.rb
|
226
226
|
- spec/useless/doc/router_spec.rb
|
227
227
|
- spec/useless/doc/serialization/dump_spec.rb
|
228
228
|
- spec/useless/doc/serialization/load_spec.rb
|
229
|
-
- spec/useless/doc/sinatra_spec.rb
|
229
|
+
- spec/useless/doc/server/sinatra_spec.rb
|
230
230
|
- spec/useless/doc/ui/godel_spec.rb
|
231
231
|
- useless-doc.gemspec
|
232
232
|
homepage:
|
@@ -257,18 +257,18 @@ test_files:
|
|
257
257
|
- spec/config.ru
|
258
258
|
- spec/documents/api.json
|
259
259
|
- spec/documents/domain.json
|
260
|
-
- spec/documents/
|
260
|
+
- spec/documents/resource.json
|
261
261
|
- spec/spec_helper.rb
|
262
262
|
- spec/useless/doc/client_spec.rb
|
263
263
|
- spec/useless/doc/dsl_spec.rb
|
264
|
-
- spec/useless/doc/
|
265
|
-
- spec/useless/doc/
|
266
|
-
- spec/useless/doc/
|
267
|
-
- spec/useless/doc/
|
268
|
-
- spec/useless/doc/
|
269
|
-
- spec/useless/doc/
|
264
|
+
- spec/useless/doc/proxy/css_spec.rb
|
265
|
+
- spec/useless/doc/proxy/html_spec.rb
|
266
|
+
- spec/useless/doc/proxy/subject_spec.rb
|
267
|
+
- spec/useless/doc/proxy/ui_spec.rb
|
268
|
+
- spec/useless/doc/proxy/url_spec.rb
|
269
|
+
- spec/useless/doc/proxy_spec.rb
|
270
270
|
- spec/useless/doc/router_spec.rb
|
271
271
|
- spec/useless/doc/serialization/dump_spec.rb
|
272
272
|
- spec/useless/doc/serialization/load_spec.rb
|
273
|
-
- spec/useless/doc/sinatra_spec.rb
|
273
|
+
- spec/useless/doc/server/sinatra_spec.rb
|
274
274
|
- spec/useless/doc/ui/godel_spec.rb
|
data/lib/useless/doc/sinatra.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
|
3
|
-
require 'useless/doc/dsl'
|
4
|
-
require 'useless/doc/serialization/dump'
|
5
|
-
|
6
|
-
module Useless
|
7
|
-
module Doc
|
8
|
-
|
9
|
-
# Provides access to the +Doc::DSL+ via the +.doc+ method. The JSON of the
|
10
|
-
# API doc that is built will be served via an OPTIONS request to the root.
|
11
|
-
# Resource documentation is similarly served via an OPTIONS request to the
|
12
|
-
# corresponding path.
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# class ResourceApp < Sinatra::Base
|
16
|
-
# register Useless::Doc::Sinatra
|
17
|
-
#
|
18
|
-
# doc 'Resouces API' do
|
19
|
-
# url 'resources.useless.io'
|
20
|
-
# description 'A place with resources'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# doc.get '/some-resources' do
|
24
|
-
# description 'Get all of these resources'
|
25
|
-
#
|
26
|
-
# request do
|
27
|
-
# parameter 'page', 'The page of resources to return.'
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# response do
|
31
|
-
# body do
|
32
|
-
# attribute 'name', 'The name of the resource.'
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# ...
|
38
|
-
#
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
module Sinatra
|
42
|
-
def doc=(doc)
|
43
|
-
@doc = doc
|
44
|
-
end
|
45
|
-
|
46
|
-
def doc(name = nil, &block)
|
47
|
-
@dsl ||= Useless::Doc::DSL::API.new(name: name)
|
48
|
-
@dsl.instance_eval(&block) if block_given?
|
49
|
-
@dsl
|
50
|
-
end
|
51
|
-
|
52
|
-
def generated_doc
|
53
|
-
@doc ||= @dsl.generate if @dsl
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.registered(app)
|
57
|
-
app.options '/' do
|
58
|
-
if api = self.class.generated_doc
|
59
|
-
last_modified api.timestamp
|
60
|
-
Useless::Doc::Serialization::Dump.api(api)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
app.options '/*' do
|
65
|
-
if api = self.class.generated_doc
|
66
|
-
resource = api.resources.find do |resource|
|
67
|
-
resource.path == "/#{params[:splat].first}"
|
68
|
-
end
|
69
|
-
|
70
|
-
if resource
|
71
|
-
last_modified api.timestamp
|
72
|
-
return Useless::Doc::Serialization::Dump.resource(resource)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
pass
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
Sinatra.register Useless::Doc::Sinatra
|
File without changes
|