Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index template and api explanation for Slate formatter #375

Merged
merged 2 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}}