apiaryio 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +3 -0
- data/README.md +1 -0
- data/apiary.gemspec +1 -0
- data/lib/apiary/cli.rb +1 -0
- data/lib/apiary/command/preview.rb +40 -4
- data/lib/apiary/file_templates/preview.erb +29 -0
- data/lib/apiary/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e639544bbbeeeccb5ee418216fccdd4931adfd1
|
|
4
|
+
data.tar.gz: c1adc732daf47c4a9a988d15a65098c5fb52633d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45a77fc5663fde0d5079acb6021e8f4607cf87816079edea83ff8f27ffc33578c9ee9cab39dfbd05c0e5033a4c93591f60192954dd68390a2b8b9bd5f9577799
|
|
7
|
+
data.tar.gz: 6e8940c09315916b67f5ff75448aac975d87fd1d9cc4ec35a4b9388752e92ca5308f91777978eb61a1ba11afe44d88b24122e4ad5c607051d4dbfcf07038bf27
|
data/.rubocop_todo.yml
CHANGED
data/README.md
CHANGED
|
@@ -98,6 +98,7 @@ Options:
|
|
|
98
98
|
[--server], [--no-server] # Start standalone web server on port 8080
|
|
99
99
|
[--port=PORT] # Set port for --server option
|
|
100
100
|
[--host=HOST] # Set host for --server option
|
|
101
|
+
[--watch], [--no-watch] # Reload API documentation when API Description Document has changed
|
|
101
102
|
|
|
102
103
|
Show API documentation in browser or write it to file
|
|
103
104
|
```
|
data/apiary.gemspec
CHANGED
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
|
|
|
26
26
|
gem.add_runtime_dependency 'thor', '~> 0.19.1'
|
|
27
27
|
gem.add_runtime_dependency 'json', '~> 1.8'
|
|
28
28
|
gem.add_runtime_dependency 'launchy', '~> 2.4'
|
|
29
|
+
gem.add_runtime_dependency 'listen', '~> 2.0'
|
|
29
30
|
|
|
30
31
|
gem.add_development_dependency 'bundler', '~> 1.12'
|
|
31
32
|
gem.add_development_dependency 'rake', '~> 10.0'
|
data/lib/apiary/cli.rb
CHANGED
|
@@ -25,6 +25,7 @@ module Apiary
|
|
|
25
25
|
method_option :server, type: :boolean, desc: 'Start standalone web server on port 8080'
|
|
26
26
|
method_option :port, type: :numeric, banner: 'PORT', desc: 'Set port for --server option'
|
|
27
27
|
method_option :host, type: :string, desc: 'Set host for --server option'
|
|
28
|
+
method_option :watch, type: :boolean, desc: 'Reload API documentation when API Description Document has changed'
|
|
28
29
|
|
|
29
30
|
def preview
|
|
30
31
|
cmd = Apiary::Command::Preview.new options
|
|
@@ -6,6 +6,7 @@ require 'json'
|
|
|
6
6
|
require 'tmpdir'
|
|
7
7
|
require 'erb'
|
|
8
8
|
require 'launchy'
|
|
9
|
+
require 'listen'
|
|
9
10
|
|
|
10
11
|
require 'apiary/agent'
|
|
11
12
|
require 'apiary/helpers'
|
|
@@ -29,6 +30,8 @@ module Apiary::Command
|
|
|
29
30
|
@options.proxy ||= ENV['http_proxy']
|
|
30
31
|
@options.server ||= false
|
|
31
32
|
@options.json ||= false
|
|
33
|
+
@options.watch ||= false
|
|
34
|
+
@options.interval ||= 1000
|
|
32
35
|
@options.host ||= '127.0.0.1'
|
|
33
36
|
@options.headers ||= {
|
|
34
37
|
accept: 'text/html',
|
|
@@ -36,6 +39,8 @@ module Apiary::Command
|
|
|
36
39
|
user_agent: Apiary.user_agent
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
@changed = timestamp
|
|
43
|
+
|
|
39
44
|
begin
|
|
40
45
|
@source_path = api_description_source_path(@options.path)
|
|
41
46
|
rescue StandardError => e
|
|
@@ -45,17 +50,44 @@ module Apiary::Command
|
|
|
45
50
|
|
|
46
51
|
def execute
|
|
47
52
|
if @options.server
|
|
53
|
+
watch
|
|
48
54
|
server
|
|
49
55
|
else
|
|
50
56
|
show
|
|
51
57
|
end
|
|
52
58
|
end
|
|
53
59
|
|
|
60
|
+
def watch
|
|
61
|
+
if @options.watch
|
|
62
|
+
listener = Listen.to(File.dirname(@source_path), only: /#{File.basename(@source_path)}/) do |modified|
|
|
63
|
+
@changed = timestamp
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
listener.start
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def timestamp
|
|
71
|
+
Time.now.getutc.to_i.to_s
|
|
72
|
+
end
|
|
73
|
+
|
|
54
74
|
def server
|
|
55
|
-
|
|
75
|
+
generate_app = get_app('/') do
|
|
56
76
|
generate
|
|
57
77
|
end
|
|
58
78
|
|
|
79
|
+
change_app = get_app('/changed') do
|
|
80
|
+
@changed
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
source_app = get_app('/source') do
|
|
84
|
+
api_description_source(@source_path)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
app = Rack::Builder.new do
|
|
88
|
+
run Rack::Cascade.new([source_app, change_app, generate_app])
|
|
89
|
+
end
|
|
90
|
+
|
|
59
91
|
Rack::Server.start(Port: @options.port, Host: @options.host, app: app)
|
|
60
92
|
end
|
|
61
93
|
|
|
@@ -69,9 +101,11 @@ module Apiary::Command
|
|
|
69
101
|
end
|
|
70
102
|
end
|
|
71
103
|
|
|
72
|
-
def
|
|
104
|
+
def get_app(path)
|
|
73
105
|
Rack::Builder.new do
|
|
74
|
-
|
|
106
|
+
map path do
|
|
107
|
+
run ->(env) { [200, {}, [yield]] }
|
|
108
|
+
end
|
|
75
109
|
end
|
|
76
110
|
end
|
|
77
111
|
|
|
@@ -104,7 +138,9 @@ module Apiary::Command
|
|
|
104
138
|
|
|
105
139
|
data = {
|
|
106
140
|
title: File.basename(@source_path, '.*'),
|
|
107
|
-
source: source
|
|
141
|
+
source: source,
|
|
142
|
+
interval: @options.interval,
|
|
143
|
+
watch: @options.watch
|
|
108
144
|
}
|
|
109
145
|
|
|
110
146
|
template.result(binding)
|
|
@@ -10,6 +10,35 @@
|
|
|
10
10
|
var embed = new Apiary.Embed({
|
|
11
11
|
apiBlueprint: "<%= escape_javascript data[:source] %>"
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
if (<%= data[:watch] %>) {
|
|
15
|
+
var changed = null
|
|
16
|
+
var xhrChanged = new XMLHttpRequest();
|
|
17
|
+
var xhrData = new XMLHttpRequest();
|
|
18
|
+
setInterval(function() {
|
|
19
|
+
xhrChanged.open('GET', window.location.href + "/changed", true);
|
|
20
|
+
xhrChanged.send();
|
|
21
|
+
|
|
22
|
+
xhrChanged.onreadystatechange = function() {
|
|
23
|
+
if (xhrChanged.readyState == 4 && xhrChanged.status == 200) {
|
|
24
|
+
if (!changed) {
|
|
25
|
+
changed = xhrChanged.responseText
|
|
26
|
+
}
|
|
27
|
+
if (changed != xhrChanged.responseText) {
|
|
28
|
+
changed = xhrChanged.responseText
|
|
29
|
+
xhrData.open('GET', window.location.href + "/source", true);
|
|
30
|
+
xhrData.send();
|
|
31
|
+
|
|
32
|
+
xhrData.onreadystatechange = function() {
|
|
33
|
+
if (xhrData.readyState == 4 && xhrData.status == 200) {
|
|
34
|
+
embed.iframeElement.contentWindow.postMessage({"origin": embed.ORIGIN, "eventType": "anonymousPreview", "data": {"code": xhrData.responseText}}, '*');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, <%= data[:interval] %>);
|
|
41
|
+
}
|
|
13
42
|
</script>
|
|
14
43
|
</body>
|
|
15
44
|
</html>
|
data/lib/apiary/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: apiaryio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Apiary Ltd.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - ~>
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '2.4'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: listen
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ~>
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '2.0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ~>
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '2.0'
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: bundler
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|