Skip to content

Commit

Permalink
Merge pull request #375 from cookpad/slate-api-explanation
Browse files Browse the repository at this point in the history
Add index template and api explanation for Slate formatter
  • Loading branch information
oestrich authored Apr 14, 2018
2 parents 97c129d + 3d22451 commit 35bac0b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 7 additions & 1 deletion features/slate_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: Generate Slate documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
config.api_name = "Example API"
config.api_explanation = "Description"
config.api_explanation = "An explanation of the API"
config.format = :slate
config.curl_host = 'http://localhost:3000'
config.request_headers_to_include = %w[Content-Type Host]
Expand Down Expand Up @@ -293,3 +293,9 @@ Feature: Generate Slate documentation from test examples
"""
## Getting welcome message
"""

Scenario: API explanation should be included
Then the file "doc/api/index.html.md" should contain:
"""
An explanation of the API
"""
4 changes: 4 additions & 0 deletions lib/rspec_api_documentation/views/slate_index.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module RspecApiDocumentation
module Views
class SlateIndex < MarkdownIndex
def initialize(index, configuration)
super
self.template_name = "rspec_api_documentation/slate_index"
end
end
end
end
7 changes: 1 addition & 6 deletions lib/rspec_api_documentation/writers/slate_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ def markup_example_class
def write
File.open(configuration.docs_dir.join("#{FILENAME}.#{extension}"), 'w+') do |file|

file.write %Q{---\n}
file.write %Q{title: "#{configuration.api_name}"\n}
file.write %Q{language_tabs:\n}
file.write %Q{ - json: JSON\n}
file.write %Q{ - shell: cURL\n}
file.write %Q{---\n\n}
file.write markup_index_class.new(index, configuration).render

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

Expand Down
2 changes: 1 addition & 1 deletion spec/writers/slate_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
FakeFS do
template_dir = File.join(configuration.template_path, "rspec_api_documentation")
FileUtils.mkdir_p(template_dir)
File.open(File.join(template_dir, "markdown_index.mustache"), "w+") { |f| f << "{{ mustache }}" }
File.open(File.join(template_dir, "slate_index.mustache"), "w+") { |f| f << "{{ mustache }}" }
FileUtils.mkdir_p(configuration.docs_dir)

writer.write
Expand Down
8 changes: 8 additions & 0 deletions templates/rspec_api_documentation/slate_index.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: {{ api_name }}
language_tabs:
- json: JSON
- shell: cURL
---

{{{ api_explanation }}}

0 comments on commit 35bac0b

Please sign in to comment.