double_doc 2.0.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/double_doc/doc_extractor.rb +11 -4
- data/lib/double_doc/task.rb +20 -20
- data/lib/double_doc/version.rb +1 -1
- data/readme.md +31 -40
- metadata +36 -18
- data/test/client_test.rb +0 -51
- data/test/doc_extractor_test.rb +0 -49
- data/test/html_generator_test.rb +0 -95
- data/test/import_handler_test.rb +0 -58
- data/test/test_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf0f5b64a04ff19b143dec8d636ec1739a93995
|
4
|
+
data.tar.gz: 45b58b67cc55f5694d76ca7287df6a1e6751f68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1099135bb55d66c3e947bac4628ac08f4b94507b4043231fa6ba5da4f65812a9b6130a64855b4977fd457c3b78480cede64fa7d9842c302dacdab74f3beba3d8
|
7
|
+
data.tar.gz: bc38df6d8cd3ba04685ac6a15aabf39e73d7f04ebf89f1819ea77a8491120dba84b206d00a20faeebf374ad71ad6b5a73ba5e8b118a4f6f035c487f49524930e
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module DoubleDoc
|
2
2
|
class DocExtractor
|
3
3
|
TYPES = {
|
4
|
-
'rb' =>
|
5
|
-
'js' => %r{
|
6
|
-
|
4
|
+
'rb' => /(^\s*|\s+)##\s?(?<documentation_line>.*?)(?<newline_marker>\\?)$/,
|
5
|
+
'js' => %r{(^\s*|\s+)///\s?(?<documentation_line>.*?)(?<newline_marker>\\?)$}
|
6
|
+
}.freeze
|
7
7
|
|
8
8
|
def self.extract(source, options = {})
|
9
9
|
case source
|
@@ -28,13 +28,20 @@ module DoubleDoc
|
|
28
28
|
extractor = TYPES[options[:type]]
|
29
29
|
|
30
30
|
add_empty_line = false
|
31
|
+
append_to_previous = false
|
31
32
|
lines.each do |line|
|
32
33
|
if match = line.match(extractor)
|
33
34
|
if add_empty_line
|
34
35
|
doc << ''
|
35
36
|
add_empty_line = false
|
36
37
|
end
|
37
|
-
|
38
|
+
new_string = match[:documentation_line].rstrip
|
39
|
+
if append_to_previous
|
40
|
+
doc[-1] << new_string
|
41
|
+
else
|
42
|
+
doc << new_string
|
43
|
+
end
|
44
|
+
append_to_previous = !match[:newline_marker].empty?
|
38
45
|
else
|
39
46
|
add_empty_line = !doc.empty?
|
40
47
|
end
|
data/lib/double_doc/task.rb
CHANGED
@@ -6,17 +6,17 @@ require 'double_doc/client'
|
|
6
6
|
module DoubleDoc
|
7
7
|
|
8
8
|
## ### Rake Task
|
9
|
-
##
|
10
|
-
##
|
11
|
-
## `double_doc` is picked to avoid conflicts with the `doc` rake task in rails.
|
9
|
+
## Generate documentation by telling DoubleDoc what the input files are, and where the output should go.
|
10
|
+
## In the example, `double_doc` is picked to avoid conflicts with the `doc` rake task in rails.
|
12
11
|
##
|
13
12
|
## ```ruby
|
14
13
|
## require 'double_doc'
|
15
14
|
##
|
16
|
-
## DoubleDoc::Task.new(
|
17
|
-
## :
|
18
|
-
## :
|
19
|
-
## :
|
15
|
+
## DoubleDoc::Task.new(
|
16
|
+
## :double_doc,
|
17
|
+
## sources: 'doc/source/*.md',
|
18
|
+
## md_destination: 'doc/generated',
|
19
|
+
## html_destination: 'site'
|
20
20
|
## )
|
21
21
|
## ```
|
22
22
|
##
|
@@ -24,25 +24,24 @@ module DoubleDoc
|
|
24
24
|
##
|
25
25
|
## | name | Description
|
26
26
|
## | -------------------- | -----------
|
27
|
-
## | __sources__ | __Required__.
|
28
|
-
## | __md_destination__ | __Required__.
|
29
|
-
## | __html_destination__ |
|
30
|
-
## | __html_template__ |
|
31
|
-
## | __html_renderer__ |
|
32
|
-
## | __html_css__ |
|
33
|
-
## | __title__ |
|
34
|
-
##
|
35
|
-
## If you just want to use double_doc to generate your README.md for github, you should write your documentation in doc/README.md and put this in your Rakefile:
|
27
|
+
## | __sources__ | __Required__. Documentation source directory (string or array of strings).
|
28
|
+
## | __md_destination__ | __Required__. Directory where the generated markdown files should go.
|
29
|
+
## | __html_destination__ | Where a pretty HTML version of the documentation should go.
|
30
|
+
## | __html_template__ | Custom ERB template for HTML rendering, see default template for inspiration (templates/default.html.erb).
|
31
|
+
## | __html_renderer__ | Custom html rendered, defaults to `DoubleDoc::HtmlRenderer`.
|
32
|
+
## | __html_css__ | Custom CSS document path.
|
33
|
+
## | __title__ | Title for generated HTML, defaults to "Documentation".
|
34
|
+
## To generate a README.md for github, write documentation in doc/README.md and put this in the Rakefile:
|
36
35
|
##
|
37
36
|
## ```ruby
|
38
37
|
## require 'double_doc'
|
39
38
|
##
|
40
|
-
## DoubleDoc::Task.new(:double_doc, :
|
39
|
+
## DoubleDoc::Task.new(:double_doc, sources: 'doc/README.md', md_destination: '.')
|
41
40
|
## ```
|
42
41
|
##
|
43
|
-
## Then
|
42
|
+
## Then run `rake double_doc`, which will generate a `readme.md` in the root of the project.
|
44
43
|
##
|
45
|
-
## If
|
44
|
+
## If a gh-pages branch exists, run `rake doc:publish` to generate html documentation and push it to your github pages.
|
46
45
|
class Task
|
47
46
|
include Rake::DSL if defined?(Rake::DSL)
|
48
47
|
|
@@ -60,7 +59,7 @@ module DoubleDoc
|
|
60
59
|
|
61
60
|
desc "Generate markdown #{html_dst ? 'and HTML ' : ''}DoubleDoc documentation"
|
62
61
|
generated_task = task(task_name => destinations) do |t, args|
|
63
|
-
opts = args.merge(options.merge(:roots => roots))
|
62
|
+
opts = args.to_h.merge(options.merge(:roots => roots))
|
64
63
|
client = DoubleDoc::Client.new(options[:sources], opts)
|
65
64
|
client.process
|
66
65
|
end
|
@@ -80,6 +79,7 @@ module DoubleDoc
|
|
80
79
|
generated_task.execute(:html_destination => dir)
|
81
80
|
html_files = Dir.glob(Pathname.new(dir) + '*.html')
|
82
81
|
|
82
|
+
# FIXME: fail when something fails and don't just continue
|
83
83
|
`git add .`
|
84
84
|
`git commit -n -m 'Updated documentation'`
|
85
85
|
`git checkout gh-pages`
|
data/lib/double_doc/version.rb
CHANGED
data/readme.md
CHANGED
@@ -2,22 +2,16 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/zendesk/double_doc.svg?branch=master)](https://travis-ci.org/zendesk/double_doc)
|
4
4
|
|
5
|
+
<!-- only modify doc/readme.md and not Readme.md -->
|
5
6
|
|
6
|
-
|
7
|
-
when ever you change the API. The main reason why this is a problem is that very often the documentation lives very for from your code.
|
7
|
+
Write documentation with your code, to keep them in sync, ideal for public API docs.
|
8
8
|
|
9
|
-
This
|
10
|
-
|
11
|
-
DoubleDoc allows you to write the documentation right where your code is, and you can combine it all into a well structured document.
|
12
|
-
|
13
|
-
This document was generated using DoubleDoc, and the source of this project is a great source for inspiration for how to use DoubleDoc.
|
9
|
+
This document was generated using DoubleDoc from [doc/readme.md](doc/readme.md), and the source of this project is a great source for how to use DoubleDoc.
|
14
10
|
|
15
11
|
### Documentation Format
|
16
|
-
|
17
|
-
|
12
|
+
Write documentation in markdown right in source code files by double commenting it:
|
18
13
|
```ruby
|
19
14
|
class User < ActiveRecord::Base
|
20
|
-
|
21
15
|
## ```js
|
22
16
|
## {
|
23
17
|
## "id": 1,
|
@@ -27,9 +21,8 @@ class User < ActiveRecord::Base
|
|
27
21
|
def as_json
|
28
22
|
# this comment will not be included in the documentation
|
29
23
|
# as it only has a single # character
|
30
|
-
super(:
|
24
|
+
super(only: [:id, :name])
|
31
25
|
end
|
32
|
-
|
33
26
|
end
|
34
27
|
|
35
28
|
class UsersController < ApplicationController
|
@@ -39,22 +32,22 @@ class UsersController < ApplicationController
|
|
39
32
|
## #### Format
|
40
33
|
## @import app/models/user.rb
|
41
34
|
def show
|
42
|
-
render :
|
35
|
+
render json: User.find(params[:id])
|
43
36
|
end
|
44
37
|
end
|
45
38
|
```
|
46
39
|
|
47
|
-
|
40
|
+
Then write a markdown document about User API:
|
48
41
|
|
49
42
|
## Users
|
50
|
-
|
43
|
+
Access users by using our REST API, blah blah blah...
|
51
44
|
|
52
45
|
@import app/controllers/users_controller.rb
|
53
46
|
|
54
|
-
And DoubleDoc will generate this markdown document
|
47
|
+
And DoubleDoc will generate this markdown document:
|
55
48
|
|
56
49
|
## Users
|
57
|
-
|
50
|
+
Access users in by using our REST API, blah blah blah...
|
58
51
|
|
59
52
|
### Getting a User
|
60
53
|
`GET /users/{id}.json`
|
@@ -68,17 +61,17 @@ And DoubleDoc will generate this markdown document for you:
|
|
68
61
|
```
|
69
62
|
|
70
63
|
### Rake Task
|
71
|
-
|
72
|
-
|
73
|
-
`double_doc` is picked to avoid conflicts with the `doc` rake task in rails.
|
64
|
+
Generate documentation by telling DoubleDoc what the input files are, and where the output should go.
|
65
|
+
In the example, `double_doc` is picked to avoid conflicts with the `doc` rake task in rails.
|
74
66
|
|
75
67
|
```ruby
|
76
68
|
require 'double_doc'
|
77
69
|
|
78
|
-
DoubleDoc::Task.new(
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
70
|
+
DoubleDoc::Task.new(
|
71
|
+
:double_doc,
|
72
|
+
sources: 'doc/source/*.md',
|
73
|
+
md_destination: 'doc/generated',
|
74
|
+
html_destination: 'site'
|
82
75
|
)
|
83
76
|
```
|
84
77
|
|
@@ -86,33 +79,31 @@ The available options are:
|
|
86
79
|
|
87
80
|
| name | Description
|
88
81
|
| -------------------- | -----------
|
89
|
-
| __sources__ | __Required__.
|
90
|
-
| __md_destination__ | __Required__.
|
91
|
-
| __html_destination__ |
|
92
|
-
| __html_template__ |
|
93
|
-
| __html_renderer__ |
|
94
|
-
| __html_css__ |
|
95
|
-
| __title__ |
|
96
|
-
|
97
|
-
If you just want to use double_doc to generate your README.md for github, you should write your documentation in doc/README.md and put this in your Rakefile:
|
82
|
+
| __sources__ | __Required__. Documentation source directory (string or array of strings).
|
83
|
+
| __md_destination__ | __Required__. Directory where the generated markdown files should go.
|
84
|
+
| __html_destination__ | Where a pretty HTML version of the documentation should go.
|
85
|
+
| __html_template__ | Custom ERB template for HTML rendering, see default template for inspiration (templates/default.html.erb).
|
86
|
+
| __html_renderer__ | Custom html rendered, defaults to `DoubleDoc::HtmlRenderer`.
|
87
|
+
| __html_css__ | Custom CSS document path.
|
88
|
+
| __title__ | Title for generated HTML, defaults to "Documentation".
|
89
|
+
To generate a README.md for github, write documentation in doc/README.md and put this in the Rakefile:
|
98
90
|
|
99
91
|
```ruby
|
100
92
|
require 'double_doc'
|
101
93
|
|
102
|
-
DoubleDoc::Task.new(:double_doc, :
|
94
|
+
DoubleDoc::Task.new(:double_doc, sources: 'doc/README.md', md_destination: '.')
|
103
95
|
```
|
104
96
|
|
105
|
-
Then
|
97
|
+
Then run `rake double_doc`, which will generate a `readme.md` in the root of the project.
|
106
98
|
|
107
|
-
If
|
99
|
+
If a gh-pages branch exists, run `rake doc:publish` to generate html documentation and push it to your github pages.
|
108
100
|
|
109
101
|
### Notes
|
110
|
-
|
102
|
+
- Tested on ruby 2.0+
|
103
|
+
- Does not work on jruby because of its dependency on redcarpet.
|
111
104
|
|
112
105
|
### TODO
|
113
|
-
* Tests
|
114
106
|
* Support for directory structures
|
115
|
-
* Documentation for the Rake task
|
116
107
|
* Documentation for the Guard
|
117
108
|
* Add support for extracting documentation from JavaScript files
|
118
109
|
|
@@ -125,4 +116,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
125
116
|
|
126
117
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
127
118
|
|
128
|
-
THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
119
|
+
THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: double_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -25,7 +25,35 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: maxitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mime-types
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bump
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
@@ -94,8 +122,8 @@ dependencies:
|
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0.2'
|
97
|
-
description:
|
98
|
-
|
125
|
+
description: Write documentation with your code, to keep them in sync, ideal for public
|
126
|
+
API docs.
|
99
127
|
email:
|
100
128
|
- mick@staugaard.com
|
101
129
|
executables: []
|
@@ -115,12 +143,7 @@ files:
|
|
115
143
|
- readme.md
|
116
144
|
- templates/default.html.erb
|
117
145
|
- templates/screen.css
|
118
|
-
|
119
|
-
- test/doc_extractor_test.rb
|
120
|
-
- test/html_generator_test.rb
|
121
|
-
- test/import_handler_test.rb
|
122
|
-
- test/test_helper.rb
|
123
|
-
homepage: http://staugaard.github.com/double_doc
|
146
|
+
homepage: https://github.com/zendesk/double_doc
|
124
147
|
licenses: []
|
125
148
|
metadata: {}
|
126
149
|
post_install_message:
|
@@ -139,13 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
162
|
version: '0'
|
140
163
|
requirements: []
|
141
164
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.4.5
|
165
|
+
rubygems_version: 2.4.5.1
|
143
166
|
signing_key:
|
144
167
|
specification_version: 4
|
145
168
|
summary: Documentation right where you want it
|
146
|
-
test_files:
|
147
|
-
- test/client_test.rb
|
148
|
-
- test/doc_extractor_test.rb
|
149
|
-
- test/html_generator_test.rb
|
150
|
-
- test/import_handler_test.rb
|
151
|
-
- test/test_helper.rb
|
169
|
+
test_files: []
|
data/test/client_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe "import handler" do
|
4
|
-
subject do
|
5
|
-
DoubleDoc::Client.new(sources, options)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '#process' do
|
9
|
-
let(:destination) { Dir.mktmpdir }
|
10
|
-
let(:sources) { [Bundler.root + 'doc/readme.md'] }
|
11
|
-
let(:options) { { :md_destination => destination, :roots => [Bundler.root], :quiet => true } }
|
12
|
-
|
13
|
-
before do
|
14
|
-
subject.process
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'produces output at the md_destination' do
|
18
|
-
File.exists?(destination + '/readme.md').must_equal true
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'with a missing directory' do
|
22
|
-
let(:destination) { Dir.mktmpdir + '/tmp' }
|
23
|
-
|
24
|
-
it 'creates the directory' do
|
25
|
-
File.exists?(destination + '/readme.md').must_equal true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'with multiple sources' do
|
30
|
-
let(:sources) { %w(readme todo).map{|f| Bundler.root + "doc/#{f}.md" } }
|
31
|
-
|
32
|
-
it 'processes all sources' do
|
33
|
-
File.exists?(destination + '/readme.md').must_equal true
|
34
|
-
File.exists?(destination + '/todo.md').must_equal true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'producing html' do
|
39
|
-
let(:options) { {
|
40
|
-
:md_destination => destination,
|
41
|
-
:html_destination => destination + '/html',
|
42
|
-
:roots => [Bundler.root],
|
43
|
-
:quiet => true
|
44
|
-
} }
|
45
|
-
|
46
|
-
it 'creates html files' do
|
47
|
-
File.exists?(destination + '/html/readme.html').must_equal true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/test/doc_extractor_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe "the doc extractor" do
|
4
|
-
|
5
|
-
def self.it_acts_like_an_extractor
|
6
|
-
it "extracts documentation" do
|
7
|
-
subject.must_match(/this line should be extracted/)
|
8
|
-
subject.must_match(/this line should also be extracted/)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "doesn't extract regular comments" do
|
12
|
-
subject.wont_match(/this line should not be extracted/)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "doesn't add any extra new-lines" do
|
16
|
-
subject.must_match(/^this/m)
|
17
|
-
subject.must_match(/extracted\n$/m)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "adds an empty line between documentation sections" do
|
21
|
-
subject.must_match(/extracted\n\nthis/m)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "on .rb files" do
|
26
|
-
## this line should be extracted
|
27
|
-
# this line should not be extracted
|
28
|
-
## this line should also be extracted
|
29
|
-
|
30
|
-
subject do
|
31
|
-
DoubleDoc::DocExtractor.extract(File.new(__FILE__))
|
32
|
-
end
|
33
|
-
|
34
|
-
it_acts_like_an_extractor
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'on .js files' do
|
38
|
-
subject do
|
39
|
-
source = <<-EOS
|
40
|
-
/// this line should be extracted
|
41
|
-
// this line should not be extracted
|
42
|
-
/// this line should also be extracted
|
43
|
-
EOS
|
44
|
-
DoubleDoc::DocExtractor.extract(source, :type => 'js')
|
45
|
-
end
|
46
|
-
|
47
|
-
it_acts_like_an_extractor
|
48
|
-
end
|
49
|
-
end
|
data/test/html_generator_test.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'tmpdir'
|
4
|
-
|
5
|
-
describe "the html generator" do
|
6
|
-
before do
|
7
|
-
@root = Pathname.new(Dir.mktmpdir)
|
8
|
-
@input_file_name = @root + 'source/input.md'
|
9
|
-
@destination = @root + 'destination'
|
10
|
-
@output_file_name = @destination + 'input.html'
|
11
|
-
Dir.mkdir(@root + 'source')
|
12
|
-
Dir.mkdir(@destination)
|
13
|
-
@generator = DoubleDoc::HtmlGenerator.new([@input_file_name], {
|
14
|
-
:html_destination => @destination,
|
15
|
-
:quiet => true
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
FileUtils.rm_rf(@root)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#generate" do
|
24
|
-
before do
|
25
|
-
File.open(@input_file_name, 'w') do |f|
|
26
|
-
f.puts "## Hello"
|
27
|
-
f.puts "and some text and a link to [the other file](other.md)"
|
28
|
-
f.puts "and a link with params [params](params.md?foo=bar)"
|
29
|
-
f.puts "and a link with a fragment [params](params.md#foo-bar)"
|
30
|
-
end
|
31
|
-
|
32
|
-
File.open(@destination + 'some_trash.html', 'w') do |f|
|
33
|
-
f.puts 'what ever'
|
34
|
-
end
|
35
|
-
|
36
|
-
@generator.generate
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should put an html document in the destination directory" do
|
40
|
-
assert File.exist?(@output_file_name), 'did not create the html file'
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should convert .md links to .html links" do
|
44
|
-
output = File.read(@output_file_name)
|
45
|
-
output.must_match(/<a href="other.html">the other file<\/a>/)
|
46
|
-
output.must_match(/<a href="params.html\?foo=bar">params<\/a>/)
|
47
|
-
output.must_match(/<a href="params.html#foo-bar">params<\/a>/)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "navigation" do
|
53
|
-
before do
|
54
|
-
@input_file_one = @root + 'source/file_one.md'
|
55
|
-
File.open(@input_file_one, 'w') do |f|
|
56
|
-
f.puts "## Title One"
|
57
|
-
end
|
58
|
-
|
59
|
-
@input_file_two = @root + 'source/file_two.md'
|
60
|
-
File.open(@input_file_two, 'w') do |f|
|
61
|
-
f.puts "## Title Two"
|
62
|
-
end
|
63
|
-
|
64
|
-
@input_files = [@input_file_one, @input_file_two]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should generate links for each page in the navigation area" do
|
68
|
-
generator = DoubleDoc::HtmlGenerator.new(@input_files, {
|
69
|
-
:html_destination => @destination,
|
70
|
-
:quiet => true
|
71
|
-
})
|
72
|
-
generator.generate
|
73
|
-
|
74
|
-
output = File.read(@destination + 'file_one.html')
|
75
|
-
|
76
|
-
output.must_match(/<li>\s*<a class="source" href="file_one.html">Title One<\/a>\s*<\/li>/)
|
77
|
-
output.must_match(/<li>\s*<a class="source" href="file_two.html">Title Two<\/a>\s*<\/li>/)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should skip specified filed" do
|
81
|
-
generator = DoubleDoc::HtmlGenerator.new(@input_files, {
|
82
|
-
:html_destination => @destination,
|
83
|
-
:exclude_from_navigation => ['file_two.html'],
|
84
|
-
:quiet => true
|
85
|
-
})
|
86
|
-
generator.generate
|
87
|
-
|
88
|
-
output = File.read(@destination + 'file_one.html')
|
89
|
-
|
90
|
-
output.must_match(/<li>\s*<a class="source" href="file_one.html">Title One<\/a>\s*<\/li>/)
|
91
|
-
output.wont_match(/<li>\s*<a class="source" href="file_two.html">Title Two<\/a>\s*<\/li>/)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
data/test/import_handler_test.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe "import handler" do
|
4
|
-
subject do
|
5
|
-
roots = Array(root).push(options.merge( :quiet => true ))
|
6
|
-
DoubleDoc::ImportHandler.new(*roots)
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
ENV["BUNDLE_GEMFILE"] = Bundler.root.join("Gemfile").to_s
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "multiple roots" do
|
14
|
-
let(:root) { [Bundler.root + 'lib', Bundler.root + 'doc'] }
|
15
|
-
let(:options) {{}}
|
16
|
-
|
17
|
-
it "finds files from either root" do
|
18
|
-
subject.find_file("double_doc.rb").must_be_instance_of File
|
19
|
-
subject.find_file("readme.md").must_be_instance_of File
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "with gemfile" do
|
24
|
-
let(:root) { Bundler.root }
|
25
|
-
let(:options) {{ :gemfile => true }}
|
26
|
-
|
27
|
-
describe "rubygems" do
|
28
|
-
describe "load_paths" do
|
29
|
-
it "should add Gemfile load paths" do
|
30
|
-
subject.load_paths.must_include root
|
31
|
-
subject.load_paths.size.must_be :>, 1
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "find_file" do
|
36
|
-
it "should resolve files" do
|
37
|
-
subject.find_file("bundler.rb").must_be_instance_of File
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should raise if unable to find file" do
|
41
|
-
lambda do
|
42
|
-
subject.find_file("nope.rb")
|
43
|
-
end.must_raise LoadError
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "find_file" do
|
49
|
-
it "should resolve files from path" do
|
50
|
-
subject.find_file("double_doc.rb").must_be_instance_of File
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should resolve file from git" do
|
54
|
-
subject.find_file("mime-types.rb").must_be_instance_of File
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/test/test_helper.rb
DELETED