interpol 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -3
- data/{License → LICENSE} +0 -0
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/interpol/configuration.rb +18 -11
- data/lib/interpol/configuration_ruby_18_extensions.rb +27 -0
- data/lib/interpol/documentation.rb +24 -6
- data/lib/interpol/documentation_app.rb +14 -4
- data/lib/interpol/documentation_app/public/stylesheets/screen.css +1 -1
- data/lib/interpol/documentation_app/sass/screen.scss +1 -1
- data/lib/interpol/documentation_app/views/layout.erb +4 -4
- data/lib/interpol/stub_app.rb +2 -2
- data/lib/interpol/version.rb +1 -1
- metadata +22 -35
data/Gemfile
CHANGED
@@ -4,8 +4,12 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :extras do
|
7
|
-
gem 'debugger' if RUBY_ENGINE == 'ruby' && RUBY_VERSION == '1.9.3'
|
7
|
+
gem 'debugger' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '1.9.3'
|
8
8
|
end
|
9
9
|
|
10
|
-
gem 'json-jruby', platform
|
11
|
-
gem 'compass_twitter_bootstrap', git
|
10
|
+
gem 'json-jruby', :platform => 'jruby'
|
11
|
+
gem 'compass_twitter_bootstrap', :git => 'git://github.com/vwall/compass-twitter-bootstrap.git'
|
12
|
+
|
13
|
+
gem 'json', :platform => 'ruby_18'
|
14
|
+
|
15
|
+
gem 'sinatra', '>= 1.3.2', '< 2.0.0'
|
data/{License → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
7
7
|
t.ruby_opts = "-Ispec -rsimplecov_setup"
|
8
8
|
end
|
9
9
|
|
10
|
-
if RUBY_ENGINE == 'ruby' # MRI only
|
10
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' # MRI only
|
11
11
|
require 'cane/rake_task'
|
12
12
|
|
13
13
|
desc "Run cane to check quality metrics"
|
@@ -20,7 +20,7 @@ else
|
|
20
20
|
task(:quality) { } # no-op
|
21
21
|
end
|
22
22
|
|
23
|
-
task default
|
23
|
+
task :default => [:spec, :quality]
|
24
24
|
|
25
25
|
desc "Watch Documentation App Compass Files"
|
26
26
|
task :compass_watch do
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'interpol/endpoint'
|
2
2
|
require 'interpol/errors'
|
3
3
|
require 'yaml'
|
4
|
+
require 'interpol/configuration_ruby_18_extensions' if RUBY_VERSION.to_f < 1.9
|
4
5
|
|
5
6
|
module Interpol
|
6
7
|
module DefinitionFinder
|
@@ -88,15 +89,21 @@ module Interpol
|
|
88
89
|
|
89
90
|
private
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
92
|
+
# 1.9 version
|
93
|
+
include Module.new {
|
94
|
+
def deserialized_hash_from(file)
|
95
|
+
YAML.load(yaml_content_for file)
|
96
|
+
rescue TypeError => e
|
97
|
+
raise ConfigurationError.new \
|
98
|
+
"Received an error while loading YAML from #{file}: \"" +
|
99
|
+
"#{e.class}: #{e.message}\" If you are using YAML merge keys " +
|
100
|
+
"to declare shared types, you must configure endpoint_definition_merge_key_files " +
|
101
|
+
"before endpoint_definition_files.", e
|
102
|
+
end
|
103
|
+
}
|
104
|
+
|
105
|
+
# Needed to override deserialized_hash_from for Ruby 1.8
|
106
|
+
include Interpol::ConfigurationRuby18Extensions if RUBY_VERSION.to_f < 1.9
|
100
107
|
|
101
108
|
def yaml_content_for(file)
|
102
109
|
File.read(file).gsub(/\A---\n/, "---\n" + endpoint_merge_keys + "\n\n")
|
@@ -115,14 +122,14 @@ module Interpol
|
|
115
122
|
|
116
123
|
validate_if do |env, status, headers, body|
|
117
124
|
headers['Content-Type'].to_s.include?('json') &&
|
118
|
-
|
125
|
+
status >= 200 && status <= 299 && status != 204 # No Content
|
119
126
|
end
|
120
127
|
|
121
128
|
on_unavailable_request_version do |requested, available|
|
122
129
|
message = "The requested API version is invalid. " +
|
123
130
|
"Requested: #{requested}. " +
|
124
131
|
"Available: #{available}"
|
125
|
-
halt 406, JSON.dump(error
|
132
|
+
halt 406, JSON.dump(:error => message)
|
126
133
|
end
|
127
134
|
end
|
128
135
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Interpol
|
2
|
+
module ConfigurationRuby18Extensions
|
3
|
+
def deserialized_hash_from(file)
|
4
|
+
YAML.load(yaml_content_for file).tap do |yaml|
|
5
|
+
if bad_class = bad_deserialized_yaml(yaml)
|
6
|
+
raise ConfigurationError.new \
|
7
|
+
"Received an error while loading YAML from #{file}: \"" +
|
8
|
+
"Got object of type: #{bad_class}\"\n If you are using YAML merge keys " +
|
9
|
+
"to declare shared types, you must configure endpoint_definition_merge_key_files " +
|
10
|
+
"before endpoint_definition_files."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# returns nil if the YAML has been only partially deserialized by Syck
|
16
|
+
# and there are YAML::Syck objects.
|
17
|
+
def bad_deserialized_yaml(yaml)
|
18
|
+
if [Hash, Array].include? yaml.class
|
19
|
+
yaml.map { |elem| bad_deserialized_yaml(elem) }.compact.first
|
20
|
+
elsif yaml.class.name =~ /YAML::Syck::/
|
21
|
+
yaml.class.name # Bad!
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -32,20 +32,38 @@ module Interpol
|
|
32
32
|
|
33
33
|
def schema_description(doc, schema)
|
34
34
|
return unless schema.has_key?('description')
|
35
|
-
doc.h3(class
|
35
|
+
doc.h3(:class => "description") { doc.text(schema['description']) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_properties_and_items(doc, schema)
|
39
|
+
render_properties(doc, Array(schema['properties']))
|
40
|
+
render_items(doc, schema['items'])
|
36
41
|
end
|
37
42
|
|
38
43
|
def schema_definition(doc, schema)
|
39
|
-
doc.div(class
|
44
|
+
doc.div(:class => "schema-definition") do
|
40
45
|
schema_description(doc, schema)
|
41
|
-
|
46
|
+
render_properties_and_items(doc, schema)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
50
|
+
def render_items(doc, items)
|
51
|
+
# No support for tuple-typing, just basic array typing
|
52
|
+
return if items.nil?
|
53
|
+
doc.dl(:class => "items") do
|
54
|
+
doc.dt(:class => "name") { doc.text("(array contains #{items['type']}s)") }
|
55
|
+
if items.has_key?('description')
|
56
|
+
doc.dd { doc.text(items['description']) }
|
57
|
+
end
|
58
|
+
render_properties_and_items(doc, items)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
45
63
|
def render_properties(doc, properties)
|
46
64
|
return if properties.none?
|
47
65
|
|
48
|
-
doc.dl(class
|
66
|
+
doc.dl(:class => "properties") do
|
49
67
|
properties.each do |name, property|
|
50
68
|
property_definition(doc, name, property)
|
51
69
|
end
|
@@ -53,13 +71,13 @@ module Interpol
|
|
53
71
|
end
|
54
72
|
|
55
73
|
def property_definition(doc, name, property)
|
56
|
-
doc.dt(class
|
74
|
+
doc.dt(:class => "name") { doc.text(property_title name, property) } if name
|
57
75
|
|
58
76
|
if property.has_key?('description')
|
59
77
|
doc.dd { doc.text(property['description']) }
|
60
78
|
end
|
61
79
|
|
62
|
-
|
80
|
+
render_properties_and_items(doc, property)
|
63
81
|
end
|
64
82
|
|
65
83
|
def property_title(name, property)
|
@@ -15,7 +15,7 @@ module Interpol
|
|
15
15
|
def render_static_page(&block)
|
16
16
|
require 'rack/mock'
|
17
17
|
app = build(&block)
|
18
|
-
status, headers, body = app.call(Rack::MockRequest.env_for "/", method
|
18
|
+
status, headers, body = app.call(Rack::MockRequest.env_for "/", :method => "GET")
|
19
19
|
AssetInliner.new(body.join, app.public_folder).standalone_page
|
20
20
|
end
|
21
21
|
|
@@ -36,13 +36,13 @@ module Interpol
|
|
36
36
|
|
37
37
|
def inline_stylesheets
|
38
38
|
@doc.css("link[rel=stylesheet]").map do |link|
|
39
|
-
inline_asset link, "style", link['href'], type
|
39
|
+
inline_asset link, "style", link['href'], :type => "text/css"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def inline_javascript
|
44
44
|
@doc.css("script[src]").each do |script|
|
45
|
-
inline_asset script, "script", script['src'], type
|
45
|
+
inline_asset script, "script", script['src'], :type => "text/javascript"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -77,6 +77,15 @@ module Interpol
|
|
77
77
|
def title
|
78
78
|
interpol_config.documentation_title
|
79
79
|
end
|
80
|
+
|
81
|
+
def url_path(*path_parts)
|
82
|
+
[ path_prefix, path_parts ].join("/").squeeze('/')
|
83
|
+
end
|
84
|
+
alias_method :u, :url_path
|
85
|
+
|
86
|
+
def path_prefix
|
87
|
+
request.env['SCRIPT_NAME']
|
88
|
+
end
|
80
89
|
end
|
81
90
|
|
82
91
|
# Private: Builds a stub sinatra app for the given interpol
|
@@ -93,7 +102,8 @@ module Interpol
|
|
93
102
|
helpers Helpers
|
94
103
|
|
95
104
|
get('/') do
|
96
|
-
erb :layout, locals
|
105
|
+
erb :layout, :locals => { :endpoints => endpoints,
|
106
|
+
:current_endpoint => current_endpoint }
|
97
107
|
end
|
98
108
|
end
|
99
109
|
end
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<meta name="author" content="">
|
9
9
|
|
10
10
|
<!-- The styles -->
|
11
|
-
<link href="/stylesheets/screen.css" rel="stylesheet">
|
11
|
+
<link href="<%= u '/stylesheets/screen.css' %>" rel="stylesheet">
|
12
12
|
<style type="text/css">
|
13
13
|
body {
|
14
14
|
padding-top: 60px;
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</div><!--/span-->
|
57
57
|
|
58
58
|
<% endpoints.each do |endpoint| %>
|
59
|
-
<%= erb :endpoint, locals
|
59
|
+
<%= erb :endpoint, :locals => { :endpoint => endpoint, :visible => (endpoint == current_endpoint) } %>
|
60
60
|
<% end %>
|
61
61
|
</div><!--/row-->
|
62
62
|
<hr>
|
@@ -70,8 +70,8 @@
|
|
70
70
|
<!-- The javascript
|
71
71
|
================================================== -->
|
72
72
|
<!-- Placed at the end of the document so the pages load faster -->
|
73
|
-
<script src="/javascripts/jquery.1.7.2.min.js"></script>
|
74
|
-
<script src="/javascripts/interpol.js"></script>
|
73
|
+
<script src="<%= u '/javascripts/jquery.1.7.2.min.js' %>"></script>
|
74
|
+
<script src="<%= u '/javascripts/interpol.js' %>"></script>
|
75
75
|
</body>
|
76
76
|
</html>
|
77
77
|
|
data/lib/interpol/stub_app.rb
CHANGED
@@ -34,9 +34,9 @@ module Interpol
|
|
34
34
|
@app = Sinatra.new do
|
35
35
|
set :interpol_config, config
|
36
36
|
helpers Helpers
|
37
|
-
not_found { JSON.dump(error
|
37
|
+
not_found { JSON.dump(:error => "The requested resource could not be found") }
|
38
38
|
before { content_type "application/json;charset=utf-8" }
|
39
|
-
get('/__ping') { JSON.dump(message
|
39
|
+
get('/__ping') { JSON.dump(:message => "Interpol stub app running.") }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/lib/interpol/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interpol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,25 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: sinatra
|
16
|
-
requirement: &2152129140 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.3.2
|
22
|
-
- - <
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 2.0.0
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: *2152129140
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: json-schema
|
30
|
-
requirement: &
|
16
|
+
requirement: &2156420460 !ruby/object:Gem::Requirement
|
31
17
|
none: false
|
32
18
|
requirements:
|
33
19
|
- - ~>
|
@@ -35,10 +21,10 @@ dependencies:
|
|
35
21
|
version: 1.0.5
|
36
22
|
type: :runtime
|
37
23
|
prerelease: false
|
38
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156420460
|
39
25
|
- !ruby/object:Gem::Dependency
|
40
26
|
name: nokogiri
|
41
|
-
requirement: &
|
27
|
+
requirement: &2156419960 !ruby/object:Gem::Requirement
|
42
28
|
none: false
|
43
29
|
requirements:
|
44
30
|
- - ~>
|
@@ -46,10 +32,10 @@ dependencies:
|
|
46
32
|
version: '1.5'
|
47
33
|
type: :runtime
|
48
34
|
prerelease: false
|
49
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156419960
|
50
36
|
- !ruby/object:Gem::Dependency
|
51
37
|
name: rspec
|
52
|
-
requirement: &
|
38
|
+
requirement: &2156419120 !ruby/object:Gem::Requirement
|
53
39
|
none: false
|
54
40
|
requirements:
|
55
41
|
- - ~>
|
@@ -57,10 +43,10 @@ dependencies:
|
|
57
43
|
version: '2.9'
|
58
44
|
type: :development
|
59
45
|
prerelease: false
|
60
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156419120
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: rspec-fire
|
63
|
-
requirement: &
|
49
|
+
requirement: &2156418120 !ruby/object:Gem::Requirement
|
64
50
|
none: false
|
65
51
|
requirements:
|
66
52
|
- - ~>
|
@@ -68,10 +54,10 @@ dependencies:
|
|
68
54
|
version: '0.4'
|
69
55
|
type: :development
|
70
56
|
prerelease: false
|
71
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156418120
|
72
58
|
- !ruby/object:Gem::Dependency
|
73
59
|
name: simplecov
|
74
|
-
requirement: &
|
60
|
+
requirement: &2156417400 !ruby/object:Gem::Requirement
|
75
61
|
none: false
|
76
62
|
requirements:
|
77
63
|
- - ~>
|
@@ -79,10 +65,10 @@ dependencies:
|
|
79
65
|
version: '0.6'
|
80
66
|
type: :development
|
81
67
|
prerelease: false
|
82
|
-
version_requirements: *
|
68
|
+
version_requirements: *2156417400
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: cane
|
85
|
-
requirement: &
|
71
|
+
requirement: &2156416760 !ruby/object:Gem::Requirement
|
86
72
|
none: false
|
87
73
|
requirements:
|
88
74
|
- - ~>
|
@@ -90,10 +76,10 @@ dependencies:
|
|
90
76
|
version: '1.2'
|
91
77
|
type: :development
|
92
78
|
prerelease: false
|
93
|
-
version_requirements: *
|
79
|
+
version_requirements: *2156416760
|
94
80
|
- !ruby/object:Gem::Dependency
|
95
81
|
name: tailor
|
96
|
-
requirement: &
|
82
|
+
requirement: &2156415980 !ruby/object:Gem::Requirement
|
97
83
|
none: false
|
98
84
|
requirements:
|
99
85
|
- - ~>
|
@@ -101,10 +87,10 @@ dependencies:
|
|
101
87
|
version: '0'
|
102
88
|
type: :development
|
103
89
|
prerelease: false
|
104
|
-
version_requirements: *
|
90
|
+
version_requirements: *2156415980
|
105
91
|
- !ruby/object:Gem::Dependency
|
106
92
|
name: rake
|
107
|
-
requirement: &
|
93
|
+
requirement: &2156415020 !ruby/object:Gem::Requirement
|
108
94
|
none: false
|
109
95
|
requirements:
|
110
96
|
- - ~>
|
@@ -112,10 +98,10 @@ dependencies:
|
|
112
98
|
version: 0.9.2.2
|
113
99
|
type: :development
|
114
100
|
prerelease: false
|
115
|
-
version_requirements: *
|
101
|
+
version_requirements: *2156415020
|
116
102
|
- !ruby/object:Gem::Dependency
|
117
103
|
name: rack-test
|
118
|
-
requirement: &
|
104
|
+
requirement: &2156413800 !ruby/object:Gem::Requirement
|
119
105
|
none: false
|
120
106
|
requirements:
|
121
107
|
- - =
|
@@ -123,7 +109,7 @@ dependencies:
|
|
123
109
|
version: 0.6.1
|
124
110
|
type: :development
|
125
111
|
prerelease: false
|
126
|
-
version_requirements: *
|
112
|
+
version_requirements: *2156413800
|
127
113
|
description: Interpol is a toolkit for working with API endpoint definition files,
|
128
114
|
giving you a stub app, a schema validation middleware, and browsable documentation.
|
129
115
|
email:
|
@@ -133,10 +119,11 @@ extensions: []
|
|
133
119
|
extra_rdoc_files: []
|
134
120
|
files:
|
135
121
|
- README.md
|
136
|
-
-
|
122
|
+
- LICENSE
|
137
123
|
- Gemfile
|
138
124
|
- Rakefile
|
139
125
|
- lib/interpol/configuration.rb
|
126
|
+
- lib/interpol/configuration_ruby_18_extensions.rb
|
140
127
|
- lib/interpol/documentation.rb
|
141
128
|
- lib/interpol/documentation_app/config.rb
|
142
129
|
- lib/interpol/documentation_app.rb
|