Skip to content

Commit 35bac0b

Browse files
authored
Merge pull request #375 from cookpad/slate-api-explanation
Add index template and api explanation for Slate formatter
2 parents 97c129d + 3d22451 commit 35bac0b

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

features/slate_documentation.feature

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Feature: Generate Slate documentation from test examples
4949
RspecApiDocumentation.configure do |config|
5050
config.app = App
5151
config.api_name = "Example API"
52-
config.api_explanation = "Description"
52+
config.api_explanation = "An explanation of the API"
5353
config.format = :slate
5454
config.curl_host = 'http://localhost:3000'
5555
config.request_headers_to_include = %w[Content-Type Host]
@@ -293,3 +293,9 @@ Feature: Generate Slate documentation from test examples
293293
"""
294294
## Getting welcome message
295295
"""
296+
297+
Scenario: API explanation should be included
298+
Then the file "doc/api/index.html.md" should contain:
299+
"""
300+
An explanation of the API
301+
"""
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module RspecApiDocumentation
22
module Views
33
class SlateIndex < MarkdownIndex
4+
def initialize(index, configuration)
5+
super
6+
self.template_name = "rspec_api_documentation/slate_index"
7+
end
48
end
59
end
610
end

lib/rspec_api_documentation/writers/slate_writer.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ def markup_example_class
2121
def write
2222
File.open(configuration.docs_dir.join("#{FILENAME}.#{extension}"), 'w+') do |file|
2323

24-
file.write %Q{---\n}
25-
file.write %Q{title: "#{configuration.api_name}"\n}
26-
file.write %Q{language_tabs:\n}
27-
file.write %Q{ - json: JSON\n}
28-
file.write %Q{ - shell: cURL\n}
29-
file.write %Q{---\n\n}
24+
file.write markup_index_class.new(index, configuration).render
3025

3126
IndexHelper.sections(index.examples, @configuration).each do |section|
3227

spec/writers/slate_writer_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
FakeFS do
2323
template_dir = File.join(configuration.template_path, "rspec_api_documentation")
2424
FileUtils.mkdir_p(template_dir)
25-
File.open(File.join(template_dir, "markdown_index.mustache"), "w+") { |f| f << "{{ mustache }}" }
25+
File.open(File.join(template_dir, "slate_index.mustache"), "w+") { |f| f << "{{ mustache }}" }
2626
FileUtils.mkdir_p(configuration.docs_dir)
2727

2828
writer.write
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: {{ api_name }}
3+
language_tabs:
4+
- json: JSON
5+
- shell: cURL
6+
---
7+
8+
{{{ api_explanation }}}

0 commit comments

Comments
 (0)