Skip to content

Commit 2004e37

Browse files
committed
Moved explanation up to top of endpoint documentatino
and changed curl to use shell formatter in slate.
1 parent 269515b commit 2004e37

File tree

3 files changed

+13
-64
lines changed

3 files changed

+13
-64
lines changed

lib/rspec_api_documentation/views/slate_example.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ def initialize(example, configuration)
66
self.template_name = "rspec_api_documentation/slate_example"
77
end
88

9-
def curl_with_linebreaks
10-
requests.map {|request| request[:curl].lines }.flatten.map do |line|
11-
line.rstrip.gsub("\t", ' ').gsub(' ', ' ').gsub('\\', '\')
12-
end.join "<br>"
13-
end
14-
159
def explanation_with_linebreaks
1610
explanation.gsub "\n", "<br>\n"
1711
end
@@ -21,13 +15,13 @@ def write
2115

2216
sections.each do |section|
2317
file.write "# #{section[:resource_name]}\n\n"
24-
end
2518

26-
section[:examples].examples.sort_by!(&:description) unless configuration.keep_source_order
19+
section[:examples].examples.sort_by!(&:description) unless configuration.keep_source_order
2720

28-
section[:examples].examples.each do |example|
29-
markup_example = markup_example_class.new(example, configuration)
30-
file.write markup_example.render
21+
section[:examples].examples.each do |example|
22+
markup_example = markup_example_class.new(example, configuration)
23+
file.write markup_example.render
24+
end
3125
end
3226
end
3327
end

spec/views/slate_example_spec.rb

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,6 @@
1010
let(:configuration) { RspecApiDocumentation::Configuration.new }
1111
let(:slate_example) { described_class.new(rad_example, configuration) }
1212

13-
describe '#curl_with_linebreaks' do
14-
subject { slate_example.curl_with_linebreaks }
15-
16-
before(:each) { allow(slate_example).to receive(:requests).and_return requests }
17-
18-
context 'marshaling' do
19-
let(:requests) { [{curl: 'One'}, {curl: "Two \nThree" }, {curl: 'Four '}] }
20-
21-
it 'joins all the Curl requests with linebreaks, stripping trailing whitespace' do
22-
expect(subject).to be == [
23-
'One', 'Two', 'Three', 'Four'
24-
].join('<br>')
25-
end
26-
end
27-
28-
context 'escaping' do
29-
let(:requests) { [{curl: string}] }
30-
31-
context 'spaces' do
32-
let(:string) { 'a b' }
33-
34-
it 'replaces them with nonbreaking spaces' do
35-
expect(subject).to be == 'a&nbsp;b'
36-
end
37-
end
38-
39-
context 'tabs' do
40-
let(:string) { "a\tb" }
41-
42-
it 'replaces them with two nonbreaking spaces' do
43-
expect(subject).to be == 'a&nbsp;&nbsp;b'
44-
end
45-
end
46-
47-
context 'backslashes' do
48-
let(:string) { 'a\\b'}
49-
50-
it 'replaces them with an HTML entity' do
51-
expect(subject).to be == 'a&#92;b'
52-
end
53-
end
54-
end
55-
end
56-
5713
describe '#explanation_with_linebreaks' do
5814
it 'returns the explanation with HTML linebreaks' do
5915
explanation = "Line 1\nLine 2\nLine 3\Line 4"

templates/rspec_api_documentation/slate_example.mustache

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## {{ description }}
22

3+
{{# explanation }}
4+
5+
{{{ explanation_with_linebreaks }}}
6+
{{/ explanation }}
7+
38
### Request
49

510
#### Endpoint
@@ -13,11 +18,6 @@
1318

1419
`{{ http_method }} {{ route }}`
1520

16-
{{# explanation }}
17-
18-
{{{ explanation_with_linebreaks }}}
19-
{{/ explanation }}
20-
2121
#### Parameters
2222

2323
{{# requests}}
@@ -78,9 +78,8 @@ None known.
7878
{{/ has_response_fields? }}
7979

8080
{{# curl }}
81-
82-
### cURL
83-
84-
<code>{{{ curl_with_linebreaks }}}</code>
81+
```shell
82+
{{{ curl }}}
83+
```
8584
{{/ curl }}
8685
{{/ requests}}

0 commit comments

Comments
 (0)