Skip to content

Commit 3d22451

Browse files
author
Leonard Chin
committed
Add index template for Slate format
Rather than hard coding the front matter and api explanation rendering, use a mustache template for the index.
1 parent d979d45 commit 3d22451

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed
Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +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}
30-
31-
file.write configuration.api_explanation if configuration.api_explanation
24+
file.write markup_index_class.new(index, configuration).render
3225

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

spec/writers/slate_writer_spec.rb

Lines changed: 1 addition & 1 deletion
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
Lines changed: 8 additions & 0 deletions
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)