double_doc 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/double_doc/html_generator.rb +26 -5
- data/lib/double_doc/task.rb +6 -2
- data/lib/double_doc/version.rb +1 -1
- data/test/html_generator_test.rb +51 -0
- metadata +74 -109
@@ -5,34 +5,43 @@ require 'fileutils'
|
|
5
5
|
|
6
6
|
module DoubleDoc
|
7
7
|
class HtmlGenerator
|
8
|
+
DEFAULT_CSS = File.expand_path("../../templates/screen.css", File.dirname(__FILE__)).freeze
|
9
|
+
|
8
10
|
def initialize(sources, options)
|
9
11
|
@sources = sources
|
10
12
|
@template_file = options[:html_template] || File.expand_path("../../templates/default.html.erb", File.dirname(__FILE__))
|
11
13
|
@output_directory = Pathname.new(options[:html_destination])
|
12
14
|
@html_renderer = options[:html_renderer] || HtmlRenderer
|
13
|
-
@stylesheet = options[:html_css] ||
|
15
|
+
@stylesheet = options[:html_css] || DEFAULT_CSS
|
14
16
|
@title = options[:title] || 'Documentation'
|
15
17
|
end
|
16
18
|
|
17
19
|
def generate
|
20
|
+
FileUtils.mkdir_p(@output_directory)
|
21
|
+
|
18
22
|
copy_assets
|
23
|
+
generated_files = [@output_directory + File.basename(@stylesheet)]
|
19
24
|
|
20
25
|
@sources.each do |src|
|
21
26
|
dst = @output_directory + File.basename(src).sub(/\.md$/, '.html')
|
22
27
|
puts "#{src} -> #{dst}"
|
23
28
|
FileUtils.mkdir_p(File.dirname(dst))
|
24
29
|
File.open(dst, 'w') do |out|
|
25
|
-
markdown = File.new(src).read
|
30
|
+
markdown = self.class.convert_links_to_html!(File.new(src).read)
|
31
|
+
|
26
32
|
body = @html_renderer.render(markdown)
|
27
33
|
html = template.result(
|
28
34
|
:title => @title,
|
29
35
|
:body => body,
|
30
|
-
:css => @stylesheet,
|
36
|
+
:css => File.basename(@stylesheet),
|
31
37
|
:sitemap => sitemap
|
32
38
|
)
|
33
39
|
out.write(html)
|
34
40
|
end
|
41
|
+
generated_files << dst
|
35
42
|
end
|
43
|
+
|
44
|
+
clean_other_files(generated_files)
|
36
45
|
end
|
37
46
|
|
38
47
|
def sitemap
|
@@ -64,8 +73,8 @@ module DoubleDoc
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def copy_assets
|
67
|
-
if @stylesheet ==
|
68
|
-
FileUtils.cp(
|
76
|
+
if @stylesheet == DEFAULT_CSS
|
77
|
+
FileUtils.cp(DEFAULT_CSS, @output_directory)
|
69
78
|
end
|
70
79
|
end
|
71
80
|
|
@@ -73,6 +82,18 @@ module DoubleDoc
|
|
73
82
|
@template ||= Erubis::Eruby.new(File.read(@template_file))
|
74
83
|
end
|
75
84
|
|
85
|
+
def clean_other_files(except)
|
86
|
+
files_to_delete = Dir.glob(@output_directory + '**/*') - except.map(&:to_s)
|
87
|
+
FileUtils.rm_rf(files_to_delete)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.convert_links_to_html!(markdown)
|
91
|
+
markdown.gsub!(/(\[[^\]]+\]\([^\)]+)\.md([^\)]*)\)/) do |match|
|
92
|
+
$1 + '.html' + $2 + ')'
|
93
|
+
end
|
94
|
+
markdown
|
95
|
+
end
|
96
|
+
|
76
97
|
class SitemapItem
|
77
98
|
attr_reader :title, :path, :id, :children
|
78
99
|
attr_accessor :parent
|
data/lib/double_doc/task.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'pathname'
|
3
|
+
require 'tmpdir'
|
3
4
|
require 'double_doc/import_handler'
|
4
5
|
require 'double_doc/html_generator'
|
5
6
|
|
@@ -47,7 +48,7 @@ module DoubleDoc
|
|
47
48
|
def initialize(task_name, options)
|
48
49
|
md_dst = Pathname.new(options[:md_destination])
|
49
50
|
html_dst = Pathname.new(options[:html_destination]) if options[:html_destination]
|
50
|
-
sources = FileList[*options[:sources]]
|
51
|
+
sources = FileList[*options[:sources]].uniq
|
51
52
|
|
52
53
|
destinations = [md_dst, html_dst].compact
|
53
54
|
destinations.each do |dst|
|
@@ -58,16 +59,19 @@ module DoubleDoc
|
|
58
59
|
generate_task = task(task_name => destinations) do |t, args|
|
59
60
|
import_handler = DoubleDoc::ImportHandler.new(options[:root] || Rake.original_dir)
|
60
61
|
|
62
|
+
generated_md_files = []
|
63
|
+
|
61
64
|
sources.each do |src|
|
62
65
|
dst = md_dst + File.basename(src)
|
63
66
|
puts "#{src} -> #{dst}"
|
64
67
|
File.open(dst, 'w') do |out|
|
65
68
|
out.write(import_handler.resolve_imports(File.new(src)))
|
66
69
|
end
|
70
|
+
generated_md_files << dst
|
67
71
|
end
|
68
72
|
|
69
73
|
if html_dst || args[:html_destination]
|
70
|
-
html_generator = DoubleDoc::HtmlGenerator.new(
|
74
|
+
html_generator = DoubleDoc::HtmlGenerator.new(generated_md_files, options.merge(args))
|
71
75
|
html_generator.generate
|
72
76
|
end
|
73
77
|
|
data/lib/double_doc/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
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], { :html_destination => @destination })
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm_rf(@root)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#generate" do
|
21
|
+
before do
|
22
|
+
File.open(@input_file_name, 'w') do |f|
|
23
|
+
f.puts "## Hello"
|
24
|
+
f.puts "and some text and a link to [the other file](other.md)"
|
25
|
+
f.puts "and a link with params [params](params.md?foo=bar)"
|
26
|
+
f.puts "and a link with a fragment [params](params.md#foo-bar)"
|
27
|
+
end
|
28
|
+
|
29
|
+
File.open(@destination + 'some_trash.html', 'w') do |f|
|
30
|
+
f.puts 'what ever'
|
31
|
+
end
|
32
|
+
|
33
|
+
@generator.generate
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should put an html document in the destination directory" do
|
37
|
+
assert File.exist?(@output_file_name), 'did not create the html file'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should convert .md links to .html links" do
|
41
|
+
output = File.read(@output_file_name)
|
42
|
+
output.must_match(/<a href="other.html">the other file<\/a>/)
|
43
|
+
output.must_match(/<a href="params.html\?foo=bar">params<\/a>/)
|
44
|
+
output.must_match(/<a href="params.html#foo-bar">params<\/a>/)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should clean the destination for other files" do
|
48
|
+
assert !File.exist?(@destination + 'some_trash.html'), 'did not clean the destination directory'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,118 +1,90 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: double_doc
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 1.0.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mick Staugaard
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 3
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
prerelease: false
|
31
|
-
requirement: *id001
|
32
|
-
type: :development
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
33
15
|
name: guard
|
34
|
-
|
35
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70252209375540 !ruby/object:Gem::Requirement
|
36
17
|
none: false
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
version: "0"
|
44
|
-
prerelease: false
|
45
|
-
requirement: *id002
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
46
22
|
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70252209375540
|
25
|
+
- !ruby/object:Gem::Dependency
|
47
26
|
name: minitest
|
48
|
-
|
49
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70252209375120 !ruby/object:Gem::Requirement
|
50
28
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
|
56
|
-
- 0
|
57
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
58
34
|
prerelease: false
|
59
|
-
|
60
|
-
|
35
|
+
version_requirements: *70252209375120
|
36
|
+
- !ruby/object:Gem::Dependency
|
61
37
|
name: rake
|
62
|
-
|
63
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70252209374700 !ruby/object:Gem::Requirement
|
64
39
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
prerelease: false
|
73
|
-
requirement: *id004
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
74
44
|
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70252209374700
|
47
|
+
- !ruby/object:Gem::Dependency
|
75
48
|
name: erubis
|
76
|
-
|
77
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70252209374280 !ruby/object:Gem::Requirement
|
78
50
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
segments:
|
84
|
-
- 2
|
85
|
-
- 1
|
86
|
-
version: "2.1"
|
87
|
-
prerelease: false
|
88
|
-
requirement: *id005
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
89
55
|
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70252209374280
|
58
|
+
- !ruby/object:Gem::Dependency
|
90
59
|
name: redcarpet
|
91
|
-
|
92
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70252209373780 !ruby/object:Gem::Requirement
|
93
61
|
none: false
|
94
|
-
requirements:
|
62
|
+
requirements:
|
95
63
|
- - ~>
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
- 2
|
101
|
-
version: "0.2"
|
102
|
-
prerelease: false
|
103
|
-
requirement: *id006
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.1'
|
104
66
|
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70252209373780
|
69
|
+
- !ruby/object:Gem::Dependency
|
105
70
|
name: pygments.rb
|
106
|
-
|
107
|
-
|
71
|
+
requirement: &70252209373280 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.2'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70252209373280
|
80
|
+
description: A simple framework for writing and generating beautiful documentation
|
81
|
+
for your code
|
82
|
+
email:
|
108
83
|
- mick@staugaard.com
|
109
84
|
executables: []
|
110
|
-
|
111
85
|
extensions: []
|
112
|
-
|
113
86
|
extra_rdoc_files: []
|
114
|
-
|
115
|
-
files:
|
87
|
+
files:
|
116
88
|
- lib/double_doc/doc_extractor.rb
|
117
89
|
- lib/double_doc/html_generator.rb
|
118
90
|
- lib/double_doc/html_renderer.rb
|
@@ -126,40 +98,33 @@ files:
|
|
126
98
|
- templates/screen.css
|
127
99
|
- README.md
|
128
100
|
- test/doc_extractor_test.rb
|
101
|
+
- test/html_generator_test.rb
|
129
102
|
- test/test_helper.rb
|
130
103
|
homepage: http://staugaard.github.com/double_doc
|
131
104
|
licenses: []
|
132
|
-
|
133
105
|
post_install_message:
|
134
106
|
rdoc_options: []
|
135
|
-
|
136
|
-
require_paths:
|
107
|
+
require_paths:
|
137
108
|
- lib
|
138
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
110
|
none: false
|
140
|
-
requirements:
|
141
|
-
- -
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
|
144
|
-
|
145
|
-
- 0
|
146
|
-
version: "0"
|
147
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
116
|
none: false
|
149
|
-
requirements:
|
150
|
-
- -
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
|
153
|
-
segments:
|
154
|
-
- 0
|
155
|
-
version: "0"
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
156
121
|
requirements: []
|
157
|
-
|
158
122
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.10
|
160
124
|
signing_key:
|
161
125
|
specification_version: 3
|
162
126
|
summary: Documentation right where you want it
|
163
|
-
test_files:
|
127
|
+
test_files:
|
164
128
|
- test/doc_extractor_test.rb
|
129
|
+
- test/html_generator_test.rb
|
165
130
|
- test/test_helper.rb
|