smashing_docs 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +32 -3
- data/gem_rspec/base_spec.rb +55 -0
- data/gem_rspec/conf_spec.rb +5 -0
- data/gem_rspec/install_generator_spec.rb +2 -2
- data/gem_rspec/spec_helper.rb +0 -1
- data/lib/base.rb +43 -0
- data/lib/conf.rb +3 -2
- data/lib/generators/smashing_documentation/build_docs_generator.rb +18 -0
- data/lib/generators/smashing_documentation/install_generator.rb +2 -1
- data/lib/templates/real_template.md +36 -7
- data/smashing_docs.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26647e5613a7de2ae48b1b45290021d6421c2fbc
|
4
|
+
data.tar.gz: d3895c49e8d1f5cc6703cc9fc3e03d599794068f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dab20613149d2467798fe72dc8fbaa72980c82514a499eed11f2bf6c079b6a79990e82b479af5d415188910ffac121937f4da5586f9a8bba7c787ef5964952a9
|
7
|
+
data.tar.gz: d6946b59dd25a634d646d6951d7e222affb951b2ce9fce69b90fde20aa1d09317f37b03b26419b6b27c88cace31955e13b78d62a5f7e24551721191a37eb5f0f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,8 +17,12 @@ After you bundle, run:
|
|
17
17
|
`rails generate smashing_documentation:install`
|
18
18
|
|
19
19
|
SmashingDocs will be configured to run on all your controller tests with the default
|
20
|
-
template
|
21
|
-
|
20
|
+
template.
|
21
|
+
|
22
|
+
#### To generate your docs
|
23
|
+
|
24
|
+
Run `rails g smashing_documentation:build_docs`, and your docs will be waiting for you
|
25
|
+
in the `smashing_docs` folder.
|
22
26
|
|
23
27
|
## Manual RSpec Installation
|
24
28
|
|
@@ -43,7 +47,7 @@ RSpec.configure do |config|
|
|
43
47
|
config.after(:each, type: :controller) do
|
44
48
|
SmashingDocs.run!(request, response, true)
|
45
49
|
end
|
46
|
-
config.after(:suite) { SmashingDocs.finish! }
|
50
|
+
# config.after(:suite) { SmashingDocs.finish! }
|
47
51
|
end
|
48
52
|
```
|
49
53
|
|
@@ -142,6 +146,7 @@ end
|
|
142
146
|
```
|
143
147
|
|
144
148
|
#### Adding information, e.g. notes
|
149
|
+
|
145
150
|
SmashingDocs will log all requests and responses by default, but you can add some
|
146
151
|
**optional** parameters as well.
|
147
152
|
|
@@ -153,3 +158,27 @@ end
|
|
153
158
|
```
|
154
159
|
You can store any information with `:note`, `:message`, or any other key you can think of.
|
155
160
|
To access information in the template, just use `<%= information[:key] %>`
|
161
|
+
|
162
|
+
#### Auto-Push Docs to Your Project Wiki
|
163
|
+
|
164
|
+
SmashingDocs can automatically push your generated docs to your project wiki.
|
165
|
+
|
166
|
+
**To enable this feature**
|
167
|
+
1. Clone your wiki repo from Github into the same parent folder as your app
|
168
|
+
|
169
|
+
Your folder structure should be
|
170
|
+
|
171
|
+
../projects/my_rails_app
|
172
|
+
|
173
|
+
../projects/my_rails_app.wiki
|
174
|
+
|
175
|
+
2. Set auto_push to true in `spec_helper.rb` or `test_helper.rb`
|
176
|
+
|
177
|
+
``` ruby
|
178
|
+
SmashingDocs.config do |c|
|
179
|
+
# configs
|
180
|
+
c.auto_push = true
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
3. Build your docs with `rails g smashing_documentation:build_docs`
|
data/gem_rspec/base_spec.rb
CHANGED
@@ -115,4 +115,59 @@ RSpec.describe SmashingDocs do
|
|
115
115
|
expect(tests.first.compile_template).to include("Endpoint note")
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
describe "#app_name" do
|
120
|
+
it "returns the name of the app it is installed in" do
|
121
|
+
expect(SmashingDocs.current.send(:app_name)).to eq("smashing_docs")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#output_file" do
|
126
|
+
it "returns only the file name of the configured output file" do
|
127
|
+
expect(SmashingDocs.current.send(:output_file)).to eq("fake_output.md")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#wiki_repo_exists(wiki_repo)" do
|
132
|
+
context "when the repo exists" do
|
133
|
+
let(:wiki_repo) { "../#{SmashingDocs.current.send(:app_name)}.wiki" }
|
134
|
+
it "returns true" do
|
135
|
+
expect(SmashingDocs.current.send(:wiki_repo_exists?, wiki_repo)).to eq(true)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when the repo does not exist" do
|
140
|
+
let(:wiki_repo) { "../ifyoumakethisdirectorythetestwillfail.wiki" }
|
141
|
+
it "returns false" do
|
142
|
+
expect(SmashingDocs.current.send(:wiki_repo_exists?, wiki_repo)).to eq(false)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#copy_docs_to_wiki_repo(wiki_repo)" do
|
148
|
+
let(:wiki_repo) { "../#{SmashingDocs.current.send(:app_name)}.wiki" }
|
149
|
+
let(:output_file) { SmashingDocs.current.send(:output_file) }
|
150
|
+
it "makes a copy of the docs in the wiki folder" do
|
151
|
+
`rm -f ../smashing_docs.wiki/"#{output_file}"` # -f just in case the file's stubborn
|
152
|
+
expect(!File.exist?("../smashing_docs.wiki/#{output_file}"))
|
153
|
+
SmashingDocs.current.send(:copy_docs_to_wiki_repo, wiki_repo)
|
154
|
+
expect(File.exist?("../smashing_docs.wiki/#{output_file}"))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#auto_push?" do
|
159
|
+
context "when auto_push configuration is false" do
|
160
|
+
let!(:config) { SmashingDocs.config { |c| c.auto_push = false } }
|
161
|
+
it "returns false" do
|
162
|
+
expect(!SmashingDocs.current.send(:auto_push?))
|
163
|
+
end
|
164
|
+
end
|
165
|
+
context "when auto_push configuration is true" do
|
166
|
+
let!(:config) { SmashingDocs.config { |c| c.auto_push = true } }
|
167
|
+
it "returns true" do
|
168
|
+
expect(SmashingDocs.current.send(:auto_push?))
|
169
|
+
SmashingDocs.config { |c| c.auto_push = false } # Config stays changed without this line
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
118
173
|
end
|
data/gem_rspec/conf_spec.rb
CHANGED
@@ -5,6 +5,7 @@ RSpec.describe SmashingDocs::Conf do
|
|
5
5
|
SmashingDocs.config do |c|
|
6
6
|
c.template_file = "gem_spec/fake_template.md.erb"
|
7
7
|
c.output_file = "api_docs.md"
|
8
|
+
c.auto_push = false
|
8
9
|
c.run_all = true
|
9
10
|
end
|
10
11
|
}
|
@@ -19,4 +20,8 @@ RSpec.describe SmashingDocs::Conf do
|
|
19
20
|
it "sets run_all" do
|
20
21
|
expect(SmashingDocs::Conf.run_all).to eq(true)
|
21
22
|
end
|
23
|
+
|
24
|
+
it "sets the auto_push boolean" do
|
25
|
+
expect(!SmashingDocs::Conf.auto_push)
|
26
|
+
end
|
22
27
|
end
|
@@ -30,13 +30,13 @@ RSpec.describe SmashingDocumentation::Generators::InstallGenerator, type: :gener
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
33
|
context "when rspec is not installed" do
|
35
34
|
it "does not install smashing_docs" do
|
35
|
+
`rm -f "#{rails_helper}"`
|
36
36
|
File.rename('spec', 's') if Dir.exists?('spec')
|
37
37
|
run_generator
|
38
|
-
expect(File).to_not exist(rails_helper)
|
39
38
|
File.rename('s', 'spec') if Dir.exists?('s')
|
39
|
+
expect(File).to_not exist(rails_helper)
|
40
40
|
|
41
41
|
# STDOUT is not tested here because it is suppressed in generator tests
|
42
42
|
end
|
data/gem_rspec/spec_helper.rb
CHANGED
data/lib/base.rb
CHANGED
@@ -16,6 +16,17 @@ class SmashingDocs
|
|
16
16
|
@tests = []
|
17
17
|
end
|
18
18
|
|
19
|
+
def add_docs_to_wiki
|
20
|
+
wiki_repo = "../#{app_name}.wiki"
|
21
|
+
if wiki_repo && wiki_repo_exists?(wiki_repo)
|
22
|
+
copy_docs_to_wiki_repo(wiki_repo)
|
23
|
+
push_docs_to_github(wiki_repo)
|
24
|
+
else
|
25
|
+
puts "Wiki folder was not found. Please set up and clone your"\
|
26
|
+
" wiki before using auto push"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def information(key, value)
|
20
31
|
@information[key] = value
|
21
32
|
end
|
@@ -60,6 +71,10 @@ class SmashingDocs
|
|
60
71
|
end
|
61
72
|
end
|
62
73
|
|
74
|
+
def auto_push?
|
75
|
+
self.class::Conf.auto_push
|
76
|
+
end
|
77
|
+
|
63
78
|
# = = = =
|
64
79
|
# These class methods are used to persist test data across tests
|
65
80
|
# RSpec and Minitest do not support hooks that would allow
|
@@ -69,6 +84,7 @@ class SmashingDocs
|
|
69
84
|
unless current.tests.empty?
|
70
85
|
current.sort_by_url!
|
71
86
|
current.output_testcases_to_file
|
87
|
+
current.add_docs_to_wiki if current.auto_push?
|
72
88
|
current.clean_up!
|
73
89
|
end
|
74
90
|
end
|
@@ -94,3 +110,30 @@ class SmashingDocs
|
|
94
110
|
yield(self::Conf)
|
95
111
|
end
|
96
112
|
end
|
113
|
+
# = = = =
|
114
|
+
private
|
115
|
+
|
116
|
+
def app_name
|
117
|
+
directory = `pwd`
|
118
|
+
directory.match(/\w+\n/).to_s.gsub(/\n/, "")
|
119
|
+
end
|
120
|
+
|
121
|
+
def output_file
|
122
|
+
SmashingDocs::Conf.output_file.match(/\w+\.md/).to_s
|
123
|
+
end
|
124
|
+
|
125
|
+
def wiki_repo_exists?(wiki_repo)
|
126
|
+
File.exist?(wiki_repo)
|
127
|
+
end
|
128
|
+
|
129
|
+
def copy_docs_to_wiki_repo(wiki_repo)
|
130
|
+
`cp "#{SmashingDocs::Conf.output_file}" "#{wiki_repo}"`
|
131
|
+
end
|
132
|
+
|
133
|
+
def push_docs_to_github(wiki_repo)
|
134
|
+
Dir.chdir(wiki_repo) do
|
135
|
+
`git add "#{output_file}"`
|
136
|
+
`git commit -m "Update Docs -- Auto post by SmashingDocs"`
|
137
|
+
`git push`
|
138
|
+
end
|
139
|
+
end
|
data/lib/conf.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class SmashingDocs::Conf
|
2
2
|
class << self
|
3
|
-
attr_accessor :template_file, :output_file, :run_all
|
4
|
-
|
3
|
+
attr_accessor :template_file, :output_file, :auto_push, :run_all
|
4
|
+
@output_file = 'documentation.md'
|
5
|
+
|
5
6
|
def template
|
6
7
|
raise 'You must set a template file.' unless template_file
|
7
8
|
File.read(template_file)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module SmashingDocumentation
|
3
|
+
module Generators
|
4
|
+
class BuildDocsGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../../../templates/", __FILE__)
|
6
|
+
def build_docs
|
7
|
+
destination = "spec/spec_helper.rb"
|
8
|
+
if File.exist?(destination)
|
9
|
+
uncomment_lines(destination, /config.after\(:suite\) \{ SmashingDocs.finish! \}/)
|
10
|
+
`rspec spec`
|
11
|
+
comment_lines(destination, /config.after\(:suite\) \{ SmashingDocs.finish! \}/)
|
12
|
+
else
|
13
|
+
puts "Could not find spec/spec_helper.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -24,6 +24,7 @@ module SmashingDocumentation
|
|
24
24
|
"SmashingDocs.config do |c|\n"\
|
25
25
|
" c.template_file = 'smashing_docs/template.md'\n"\
|
26
26
|
" c.output_file = 'smashing_docs/api_docs.md'\n"\
|
27
|
+
" c.auto_push = false\n"\
|
27
28
|
" c.run_all = true\n"\
|
28
29
|
"end"
|
29
30
|
) unless File.readlines(destination).grep(/SmashingDocs.config/).any?
|
@@ -37,7 +38,7 @@ module SmashingDocumentation
|
|
37
38
|
"\n config.after(:each, type: :controller) do\n"\
|
38
39
|
" SmashingDocs.run!(request, response, true)\n"\
|
39
40
|
" end\n"\
|
40
|
-
"
|
41
|
+
" # config.after(:suite) { SmashingDocs.finish! }",
|
41
42
|
after: "RSpec.configure do |config|"
|
42
43
|
) unless File.readlines(destination).grep(/SmashingDocs.finish/).any?
|
43
44
|
end
|
@@ -1,16 +1,45 @@
|
|
1
|
+
## <%= information[:endpoint_title] || ' ' %>
|
2
|
+
|
1
3
|
#### <%= request.method %> <%= request.path %>
|
2
4
|
|
3
|
-
<%= information[:
|
5
|
+
<%= information[:about] %>
|
4
6
|
|
5
|
-
|
6
|
-
|
|
7
|
-
|
8
|
-
|
7
|
+
### Query Parameters
|
8
|
+
| Parameter | Value |
|
9
|
+
| --------- | ----- |
|
10
|
+
<%=
|
11
|
+
table_entries = []
|
12
|
+
request_params = request.params.except(:controller, :action, :format)
|
13
|
+
request_params.each do |param, value|
|
9
14
|
table_entries << "| #{param} | #{value} |"
|
10
15
|
end
|
11
|
-
table_entries.join("\n") %>
|
12
16
|
|
13
|
-
|
17
|
+
table_entries << "| none | nil |" if table_entries.empty?
|
18
|
+
table_entries.join("\n")
|
19
|
+
%>
|
20
|
+
|
21
|
+
### Response
|
22
|
+
**Status: <%= response.status %>**
|
23
|
+
|
24
|
+
**Response Headers**
|
25
|
+
|
26
|
+
| Field | Value |
|
27
|
+
| ----- | ----- |
|
28
|
+
<%=
|
29
|
+
table_entries = []
|
30
|
+
response.headers.each do |header, value|
|
31
|
+
table_entries << "| #{header} | #{value} |"
|
32
|
+
end
|
33
|
+
|
34
|
+
table_entries << "| none | nil |" if table_entries.empty?
|
35
|
+
table_entries.join("\n")
|
36
|
+
%>
|
37
|
+
|
38
|
+
**JSON Example**
|
14
39
|
```json
|
15
40
|
<%= JSON.pretty_generate(JSON.parse(response.body)) %>
|
16
41
|
```
|
42
|
+
|
43
|
+
<%= information[:note] %>
|
44
|
+
|
45
|
+
=================================================================================
|
data/smashing_docs.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.require_paths = ['lib']
|
11
11
|
s.summary = "Uses your test cases to write example documentation for your API."
|
12
12
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
-
s.version = '1.
|
13
|
+
s.version = '1.1.0'
|
14
14
|
|
15
15
|
s.add_development_dependency "bundler", "~> 1.11"
|
16
16
|
s.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smashing_docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rockwell
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-02-
|
13
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- gem_rspec/test_case_spec.rb
|
92
92
|
- lib/base.rb
|
93
93
|
- lib/conf.rb
|
94
|
+
- lib/generators/smashing_documentation/build_docs_generator.rb
|
94
95
|
- lib/generators/smashing_documentation/install_generator.rb
|
95
96
|
- lib/smashing_docs.rb
|
96
97
|
- lib/templates/real_template.md
|