Skip to content

Commit 9201f69

Browse files
authored
Merge pull request #356 from prikha/master
Add common api description before resources sections (closes #354)
2 parents 3ad1ab7 + ed281e8 commit 9201f69

15 files changed

+27
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ RspecApiDocumentation.configure do |config|
118118

119119
# Change the name of the API on index pages
120120
config.api_name = "API Documentation"
121+
122+
# Change the description of the API on index pages
123+
config.api_explanation = "API Description"
121124

122125
# Redefine what method the DSL thinks is the client
123126
# This is useful if you need to `let` your own client, most likely a model.

example/spec/acceptance_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
config.format = [:json, :combined_text, :html]
77
config.curl_host = 'http://localhost:3000'
88
config.api_name = "Example App API"
9+
config.api_explanation = "API Example Description"
910
end

features/api_blueprint_documentation.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Feature: Generate API Blueprint documentation from test examples
6464
RspecApiDocumentation.configure do |config|
6565
config.app = App
6666
config.api_name = "Example API"
67+
config.api_explanation = "Example API Description"
6768
config.format = :api_blueprint
6869
config.request_body_formatter = :json
6970
config.request_headers_to_include = %w[Content-Type Host]

features/html_documentation.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Feature: Generate HTML documentation from test examples
2424
RspecApiDocumentation.configure do |config|
2525
config.app = App
2626
config.api_name = "Example API"
27+
config.api_explanation = "<p>Example API Description</p>"
2728
config.request_headers_to_include = %w[Cookie]
2829
config.response_headers_to_include = %w[Content-Type]
2930
end
@@ -66,6 +67,12 @@ Feature: Generate HTML documentation from test examples
6667
| Greetings |
6768
And I should see the api name "Example API"
6869

70+
Scenario: Create an index with proper description
71+
When I open the index
72+
Then I should see the following resources:
73+
| Greetings |
74+
And I should see the api explanation "Example API Description"
75+
6976
Scenario: Example HTML documentation includes the parameters
7077
When I open the index
7178
And I navigate to "Greeting your favorite gem"

features/json_iodocs.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Feature: Json Iodocs
2424
RspecApiDocumentation.configure do |config|
2525
config.app = App
2626
config.api_name = "app"
27+
config.api_explanation = "desc"
2728
config.format = :json_iodocs
2829
config.io_docs_protocol = "https"
2930
end
@@ -70,6 +71,7 @@ Feature: Json Iodocs
7071
{
7172
"app" : {
7273
"name" : "app",
74+
"description": "desc",
7375
"protocol" : "https",
7476
"publicPath" : "",
7577
"baseURL" : null

features/markdown_documentation.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Feature: Generate Markdown documentation from test examples
4949
RspecApiDocumentation.configure do |config|
5050
config.app = App
5151
config.api_name = "Example API"
52+
config.api_explanation = "Example API Description"
5253
config.format = :markdown
5354
config.request_headers_to_include = %w[Content-Type Host]
5455
config.response_headers_to_include = %w[Content-Type Content-Length]
@@ -148,6 +149,7 @@ Feature: Generate Markdown documentation from test examples
148149
Then the file "doc/api/index.markdown" should contain exactly:
149150
"""
150151
# Example API
152+
Example API Description
151153
152154
## Help
153155

features/slate_documentation.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +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"
5253
config.format = :slate
5354
config.curl_host = 'http://localhost:3000'
5455
config.request_headers_to_include = %w[Content-Type Host]

features/textile_documentation.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Feature: Generate Textile documentation from test examples
4949
RspecApiDocumentation.configure do |config|
5050
config.app = App
5151
config.api_name = "Example API"
52+
config.api_explanation = "Example API Description"
5253
config.format = :textile
5354
config.request_headers_to_include = %w[Content-Type Host]
5455
config.response_headers_to_include = %w[Content-Type Content-Length]
@@ -148,6 +149,7 @@ Feature: Generate Textile documentation from test examples
148149
Then the file "doc/api/index.textile" should contain exactly:
149150
"""
150151
h1. Example API
152+
Example API Description
151153
152154
h2. Help
153155

lib/rspec_api_documentation/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def self.add_setting(name, opts = {})
7575
add_setting :curl_host, :default => nil
7676
add_setting :keep_source_order, :default => false
7777
add_setting :api_name, :default => "API Documentation"
78+
add_setting :api_explanation, :default => nil
7879
add_setting :io_docs_protocol, :default => "http"
7980
add_setting :request_headers_to_include, :default => nil
8081
add_setting :response_headers_to_include, :default => nil

lib/rspec_api_documentation/views/markup_index.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
module RspecApiDocumentation
44
module Views
55
class MarkupIndex < Mustache
6+
delegate :api_name, :api_explanation, to: :@configuration, prefix: false
7+
68
def initialize(index, configuration)
79
@index = index
810
@configuration = configuration
911
self.template_path = configuration.template_path
1012
end
1113

12-
def api_name
13-
@configuration.api_name
14-
end
15-
1614
def sections
1715
RspecApiDocumentation::Writers::IndexHelper.sections(examples, @configuration)
1816
end

lib/rspec_api_documentation/writers/json_iodocs_writer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def as_json(opts = nil)
9494
{
9595
@api_key.to_sym => {
9696
:name => @configuration.api_name,
97+
:description => @configuration.api_explanation,
9798
:protocol => @configuration.io_docs_protocol,
9899
:publicPath => "",
99100
:baseURL => @configuration.curl_host

spec/configuration_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
its(:curl_host) { should be_nil }
5353
its(:keep_source_order) { should be_falsey }
5454
its(:api_name) { should == "API Documentation" }
55+
its(:api_explanation) { should be_nil }
5556
its(:client_method) { should == :client }
5657
its(:io_docs_protocol) { should == "http" }
5758
its(:request_headers_to_include) { should be_nil }

templates/rspec_api_documentation/html_index.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<body>
1111
<div class="container">
1212
<h1>{{ api_name }}</h1>
13-
13+
{{{ api_explanation }}}
1414
{{# sections }}
1515
<div class="article">
1616
<h2>{{ resource_name }}</h2>

templates/rspec_api_documentation/markdown_index.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# {{ api_name }}
2+
{{{ api_explanation }}}
23

34
{{# sections }}
45
## {{ resource_name }}

templates/rspec_api_documentation/textile_index.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
h1. {{ api_name }}
2+
{{{ api_explanation }}}
23

34
{{# sections }}
45
h2. {{ resource_name }}

0 commit comments

Comments
 (0)