grape-markdown 0.0.2 → 0.0.3
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/lib/grape-markdown/{config.rb → configuration.rb} +5 -1
- data/lib/grape-markdown/document.rb +12 -5
- data/lib/grape-markdown/parameter.rb +1 -1
- data/lib/grape-markdown/resource.rb +4 -4
- data/lib/grape-markdown/route.rb +4 -0
- data/lib/grape-markdown/sample_generator.rb +17 -7
- data/lib/grape-markdown/version.rb +1 -1
- data/lib/grape-markdown.rb +2 -2
- data/spec/grape-markdown/{config_spec.rb → configuration_spec.rb} +14 -2
- data/spec/grape-markdown/document_spec.rb +4 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23c66a58fc6dbd66c82241230455c5f2cb22dcae
|
4
|
+
data.tar.gz: c516acd4dcba953c7b5d90bd1553aa5ea344ffba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c38c1468ba6b71342d5330f534a858fdea4c43ce7f484134070747916ed142dd9dfb0166ffd40fa9d0f1395b3fe64d6cce175dc9fcdea5bb70a50db296013433
|
7
|
+
data.tar.gz: 12530734727aa1e69062043254b019369bfbe9b773d62948da103934ac7f367b38a6500970d22347b6b5cbc841d223f4f03791c154b79630c9a89e4b355fe49b
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module GrapeMarkdown
|
2
|
-
class
|
2
|
+
class Configuration
|
3
3
|
SETTINGS = [
|
4
4
|
:name,
|
5
5
|
:description,
|
@@ -13,6 +13,10 @@ module GrapeMarkdown
|
|
13
13
|
class << self
|
14
14
|
attr_accessor(*SETTINGS)
|
15
15
|
|
16
|
+
def extend(setting)
|
17
|
+
self.class.send :attr_accessor, setting
|
18
|
+
end
|
19
|
+
|
16
20
|
def request_headers
|
17
21
|
@request_headers ||= []
|
18
22
|
end
|
@@ -2,7 +2,10 @@ module GrapeMarkdown
|
|
2
2
|
class Document
|
3
3
|
attr_reader :api_class, :document_template, :properties_template
|
4
4
|
|
5
|
-
delegate(
|
5
|
+
delegate(
|
6
|
+
*GrapeMarkdown::Configuration::SETTINGS,
|
7
|
+
to: 'GrapeMarkdown::Configuration'
|
8
|
+
)
|
6
9
|
|
7
10
|
def initialize(api_class)
|
8
11
|
@api_class = api_class
|
@@ -11,7 +14,7 @@ module GrapeMarkdown
|
|
11
14
|
end
|
12
15
|
|
13
16
|
def generate
|
14
|
-
|
17
|
+
render(document_template, binding)
|
15
18
|
end
|
16
19
|
|
17
20
|
def write
|
@@ -35,15 +38,15 @@ module GrapeMarkdown
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def properties_table(resource)
|
38
|
-
|
41
|
+
render(properties_template, resource.resource_binding)
|
39
42
|
end
|
40
43
|
|
41
44
|
def formatted_request_headers
|
42
|
-
formatted_headers(GrapeMarkdown::
|
45
|
+
formatted_headers(GrapeMarkdown::Configuration.request_headers)
|
43
46
|
end
|
44
47
|
|
45
48
|
def formatted_response_headers
|
46
|
-
formatted_headers(GrapeMarkdown::
|
49
|
+
formatted_headers(GrapeMarkdown::Configuration.response_headers)
|
47
50
|
end
|
48
51
|
|
49
52
|
def show_request_sample?(route)
|
@@ -52,6 +55,10 @@ module GrapeMarkdown
|
|
52
55
|
|
53
56
|
private
|
54
57
|
|
58
|
+
def render(template, binding = nil)
|
59
|
+
ERB.new(template, nil, '-').result(binding)
|
60
|
+
end
|
61
|
+
|
55
62
|
def template_for(name)
|
56
63
|
directory = File.dirname(File.expand_path(__FILE__))
|
57
64
|
path = File.join(directory, "./templates/#{name}.md.erb")
|
@@ -32,12 +32,12 @@ module GrapeMarkdown
|
|
32
32
|
"#{title} #{route.route_type} [#{route.route_path_without_format}]"
|
33
33
|
end
|
34
34
|
|
35
|
-
def sample_request
|
36
|
-
sample_generator.request
|
35
|
+
def sample_request(pretty = true)
|
36
|
+
sample_generator.request(pretty: pretty)
|
37
37
|
end
|
38
38
|
|
39
|
-
def sample_response(route)
|
40
|
-
sample_generator.response(route.list
|
39
|
+
def sample_response(route, pretty = true)
|
40
|
+
sample_generator.response(list: route.list?, pretty: pretty)
|
41
41
|
end
|
42
42
|
|
43
43
|
def unique_params
|
data/lib/grape-markdown/route.rb
CHANGED
@@ -18,28 +18,38 @@ module GrapeMarkdown
|
|
18
18
|
|
19
19
|
hash = Hash[array.compact]
|
20
20
|
|
21
|
-
hash = hash.reverse_merge(id:
|
22
|
-
hash = { root => hash } if
|
21
|
+
hash = hash.reverse_merge(id: Configuration.generate_id) if id
|
22
|
+
hash = { root => hash } if Configuration.include_root
|
23
23
|
|
24
24
|
hash
|
25
25
|
end
|
26
26
|
|
27
|
-
def request
|
27
|
+
def request(opts = {})
|
28
28
|
hash = sample
|
29
29
|
|
30
30
|
return unless hash.present?
|
31
31
|
|
32
|
-
|
32
|
+
json(hash, opts[:pretty])
|
33
33
|
end
|
34
34
|
|
35
|
-
def response(
|
35
|
+
def response(opts = {})
|
36
36
|
hash = sample(true)
|
37
37
|
|
38
38
|
return unless hash.present?
|
39
39
|
|
40
|
-
hash = [hash] if list
|
40
|
+
hash = [hash] if opts[:list]
|
41
41
|
|
42
|
-
|
42
|
+
json(hash, opts[:pretty])
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def json(hash, pretty = true)
|
48
|
+
if pretty
|
49
|
+
JSON.pretty_generate(hash)
|
50
|
+
else
|
51
|
+
JSON.generate(hash)
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
data/lib/grape-markdown.rb
CHANGED
@@ -2,7 +2,7 @@ require 'grape'
|
|
2
2
|
|
3
3
|
module GrapeMarkdown
|
4
4
|
autoload :Version, 'grape-markdown/version'
|
5
|
-
autoload :
|
5
|
+
autoload :Configuration, 'grape-markdown/configuration'
|
6
6
|
autoload :Parameter, 'grape-markdown/parameter'
|
7
7
|
autoload :SampleGenerator, 'grape-markdown/sample_generator'
|
8
8
|
autoload :Route, 'grape-markdown/route'
|
@@ -10,7 +10,7 @@ module GrapeMarkdown
|
|
10
10
|
autoload :Document, 'grape-markdown/document'
|
11
11
|
|
12
12
|
def self.config
|
13
|
-
block_given? ? yield(
|
13
|
+
block_given? ? yield(Configuration) : Configuration
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe GrapeMarkdown::
|
3
|
+
describe GrapeMarkdown::Configuration do
|
4
4
|
include_context 'configuration'
|
5
5
|
|
6
|
-
subject { GrapeMarkdown::
|
6
|
+
subject { GrapeMarkdown::Configuration }
|
7
7
|
|
8
8
|
it 'allows for name to be set' do
|
9
9
|
subject.name = name
|
@@ -17,6 +17,18 @@ describe GrapeMarkdown::Config do
|
|
17
17
|
expect(subject.description).to eq(description)
|
18
18
|
end
|
19
19
|
|
20
|
+
context '.extend' do
|
21
|
+
before do
|
22
|
+
subject.extend(:foo)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'allows for adding a new setting' do
|
26
|
+
subject.foo = :bar
|
27
|
+
|
28
|
+
expect(subject.foo).to eq(:bar)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
context '.include_root' do
|
21
33
|
it 'defaults to false' do
|
22
34
|
expect(subject.include_root).to be(false)
|
@@ -42,8 +42,10 @@ describe GrapeMarkdown::Document do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'exposes configuration settings' do
|
45
|
-
GrapeMarkdown::
|
46
|
-
|
45
|
+
GrapeMarkdown::Configuration::SETTINGS.each do |setting|
|
46
|
+
value = GrapeMarkdown.config.send(setting)
|
47
|
+
|
48
|
+
expect(subject.send(setting)).to eq(value)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Allen
|
@@ -169,7 +169,7 @@ files:
|
|
169
169
|
- Rakefile
|
170
170
|
- grape-markdown.gemspec
|
171
171
|
- lib/grape-markdown.rb
|
172
|
-
- lib/grape-markdown/
|
172
|
+
- lib/grape-markdown/configuration.rb
|
173
173
|
- lib/grape-markdown/document.rb
|
174
174
|
- lib/grape-markdown/parameter.rb
|
175
175
|
- lib/grape-markdown/resource.rb
|
@@ -179,7 +179,7 @@ files:
|
|
179
179
|
- lib/grape-markdown/templates/properties.md.erb
|
180
180
|
- lib/grape-markdown/version.rb
|
181
181
|
- lib/grape/markdown.rb
|
182
|
-
- spec/grape-markdown/
|
182
|
+
- spec/grape-markdown/configuration_spec.rb
|
183
183
|
- spec/grape-markdown/document_spec.rb
|
184
184
|
- spec/grape-markdown/resource_spec.rb
|
185
185
|
- spec/grape-markdown/route_spec.rb
|
@@ -212,7 +212,7 @@ signing_key:
|
|
212
212
|
specification_version: 4
|
213
213
|
summary: Allows for generating a Markdown document from you Grape API
|
214
214
|
test_files:
|
215
|
-
- spec/grape-markdown/
|
215
|
+
- spec/grape-markdown/configuration_spec.rb
|
216
216
|
- spec/grape-markdown/document_spec.rb
|
217
217
|
- spec/grape-markdown/resource_spec.rb
|
218
218
|
- spec/grape-markdown/route_spec.rb
|