docubot 0.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/bin/docubot +0 -0
  2. data/lib/docubot/bundle.rb +75 -11
  3. data/lib/docubot/glossary.rb +19 -14
  4. data/lib/docubot/page.rb +114 -56
  5. data/lib/docubot/shells/nvphysx/0_License.md +3 -0
  6. data/lib/docubot/shells/nvphysx/1_Getting_Started.haml +51 -0
  7. data/lib/docubot/shells/nvphysx/Appendix/Glossary.md +7 -0
  8. data/lib/docubot/shells/nvphysx/_glossary/APEX.md +1 -0
  9. data/lib/docubot/shells/nvphysx/_glossary/NVIDIA.md +1 -0
  10. data/lib/docubot/shells/nvphysx/_glossary/PhysX.textile +3 -0
  11. data/lib/docubot/shells/nvphysx/_static/NVBadge_3D.png +0 -0
  12. data/lib/docubot/shells/nvphysx/_static/PhysXbyNV_Black.png +0 -0
  13. data/lib/docubot/shells/nvphysx/_templates/_root/bg_green_bar_revised.gif +0 -0
  14. data/lib/docubot/shells/nvphysx/_templates/_root/close.png +0 -0
  15. data/lib/docubot/shells/nvphysx/_templates/_root/common.css +264 -0
  16. data/lib/docubot/shells/nvphysx/_templates/_root/glossary.css +4 -0
  17. data/lib/docubot/shells/nvphysx/_templates/_root/glossary.js +24 -0
  18. data/lib/docubot/shells/nvphysx/_templates/_root/nvdevtools.js +31 -0
  19. data/lib/docubot/shells/nvphysx/_templates/_root/nvidia-logo.gif +0 -0
  20. data/lib/docubot/shells/nvphysx/_templates/_root/right-sidebar.png +0 -0
  21. data/lib/docubot/shells/nvphysx/_templates/top.haml +28 -0
  22. data/lib/docubot/shells/nvphysx/index.txt +5 -0
  23. data/lib/docubot/snippet.rb +1 -0
  24. data/lib/docubot/snippets/glossary.rb +1 -0
  25. data/lib/docubot/templates/_root/glossary.css +4 -0
  26. data/lib/docubot/templates/_root/glossary.js +58 -0
  27. data/lib/docubot/templates/glossary.haml +3 -2
  28. data/lib/docubot/templates/top.haml +4 -0
  29. data/lib/docubot/writers/chm.rb +6 -3
  30. data/lib/docubot/writers/html.rb +1 -1
  31. data/spec/_all.rb +12 -0
  32. data/spec/_helper.rb +6 -0
  33. data/spec/bundle.rb +142 -0
  34. data/spec/command.rb +3 -0
  35. data/spec/converters.rb +2 -0
  36. data/spec/glossary.rb +93 -0
  37. data/spec/index.rb +2 -0
  38. data/spec/page.rb +24 -0
  39. data/spec/samples/glossary/Glossary.txt +5 -0
  40. data/spec/samples/glossary/Some Page.md +3 -0
  41. data/spec/samples/glossary/_glossary/Simple Term.md +3 -0
  42. data/spec/samples/glossary/_glossary/complex.haml +8 -0
  43. data/spec/samples/glossary/_glossary/project_x.md +4 -0
  44. data/spec/samples/link_test/index.txt +11 -0
  45. data/spec/samples/link_test/root.md +14 -0
  46. data/spec/samples/link_test/sub1/inner1.md +11 -0
  47. data/spec/samples/link_test/sub2.md +3 -0
  48. data/{test/site1_html/toc.css → spec/samples/link_test/sub2/bozo.bin} +0 -0
  49. data/spec/samples/link_test/sub2/inner2.md +7 -0
  50. data/spec/samples/simplest/HTML.html +10 -0
  51. data/spec/samples/simplest/Haml.haml +13 -0
  52. data/spec/samples/simplest/Markdown.md +10 -0
  53. data/spec/samples/simplest/Text.txt +10 -0
  54. data/spec/samples/simplest/Textile.textile +10 -0
  55. data/test/site1_html/toc.js b/data/spec/samples/titletest/1 First → One.txt +0 -0
  56. data/spec/samples/titletest/2_Second_One.txt +0 -0
  57. data/spec/samples/titletest/3_renamed.txt +2 -0
  58. data/spec/samples/titletest/4 Fourth_One.txt b/data/spec/samples/titletest/4 → Fourth_One.txt +0 -0
  59. data/spec/samples/titletest/5_Fifth One.txt b/data/spec/samples/titletest/5_Fifth → One.txt +0 -0
  60. data/spec/samples/titletest/index.txt +2 -0
  61. data/spec/templates.rb +2 -0
  62. data/spec/toc.rb +73 -0
  63. data/spec/writer/chm.rb +2 -0
  64. data/spec/writer/html.rb +2 -0
  65. metadata +74 -35
  66. data/test/all.rb +0 -8
  67. data/test/site1/A Slight Change of Heart/1 Ze First Page in Ze Section.md +0 -1
  68. data/test/site1/A Slight Change of Heart/2 Another Page in the Section.md +0 -1
  69. data/test/site1/A Slight Change of Heart/3_more_crap.haml +0 -17
  70. data/test/site1/appendices/gkheadftw.html +0 -2
  71. data/test/site1/appendices/index.md +0 -2
  72. data/test/site1/headers.md +0 -10
  73. data/test/site1/preamble.haml +0 -4
  74. data/test/site1/raw.textile +0 -10
  75. data/test/site1_html/A Slight Change of Heart/1 Ze First Page in Ze Section.html +0 -30
  76. data/test/site1_html/A Slight Change of Heart/2 Another Page in the Section.html +0 -30
  77. data/test/site1_html/A Slight Change of Heart/3_more_crap.html +0 -42
  78. data/test/site1_html/A Slight Change of Heart/3_more_crap.html#frist-post +0 -29
  79. data/test/site1_html/A Slight Change of Heart/3_more_crap.html#moar +0 -29
  80. data/test/site1_html/A Slight Change of Heart/index.html +0 -28
  81. data/test/site1_html/_index.html +0 -17
  82. data/test/site1_html/_toc.html +0 -73
  83. data/test/site1_html/appendices/gkheadftw.html +0 -32
  84. data/test/site1_html/appendices/index.html +0 -28
  85. data/test/site1_html/common.css +0 -108
  86. data/test/site1_html/glossary-terms.js +0 -1
  87. data/test/site1_html/headers.html +0 -42
  88. data/test/site1_html/preamble.html +0 -36
  89. data/test/site1_html/raw.html +0 -33
@@ -1,5 +1,6 @@
1
1
  -# TODO: Breakdown by letter.
2
2
  %dl#glossary
3
- - global.glossary.each do |term,defn|
3
+ - global.glossary.each do |term,page|
4
+ - next if page.hide
4
5
  %dt= term
5
- %dd= defn
6
+ %dd= page.to_html
@@ -3,6 +3,9 @@
3
3
  %head
4
4
  %meta(http-equiv='Content-Type' content='text/html; charset=utf-8')
5
5
  %link{:rel=>'stylesheet', :type=>'text/css', :href=>"#{root}common.css", :media=>'all'}
6
+ %link{:rel=>'stylesheet', :type=>'text/css', :href=>"#{root}glossary.css", :media=>'all'}
7
+ %script{:type=>'text/javascript', :src=>"#{root}glossary-terms.js"}
8
+ %script{:type=>'text/javascript', :src=>"#{root}glossary.js"}
6
9
  %title= page.title
7
10
  %body{ :class=>page.style }
8
11
  #content
@@ -19,6 +22,7 @@
19
22
  - if page.author?
20
23
  #author= page.author
21
24
  #pagebody
25
+ #glossary-box
22
26
  #mainbody= contents
23
27
  #pagefooter
24
28
  Copyright ©#{Time.now.year}#{ " #{global.company}" if global.company? }.
@@ -14,7 +14,8 @@ class DocuBot::CHMWriter < DocuBot::HTMLWriter
14
14
  write_hhc
15
15
  write_hhk
16
16
  write_hhp
17
- puts "...%.2fs to write the CHM support files" % ((lap=Time.now)-lap)
17
+ puts "...%.2fs to write the CHM support files" % (Time.now-lap)
18
+ lap = Time.now
18
19
 
19
20
  # This will fail if a handle is open to it on Windows
20
21
  begin
@@ -26,12 +27,14 @@ class DocuBot::CHMWriter < DocuBot::HTMLWriter
26
27
  end
27
28
  end
28
29
  `hhc.exe "#{FileUtils.win_path @hhp}"`.gsub( /[\r\n]+/, "\n" )
29
- puts "...%.2fs to create the CHM" % ((lap=Time.now)-lap)
30
+ puts "...%.2fs to create the CHM" % (Time.now-lap)
31
+ lap = Time.now
30
32
 
31
33
  # Clean out the intermediary files
32
34
  FileUtils.rm( [ @hhc, @hhp, @hhk ] )
33
35
  FileUtils.rm_r( @html_path )
34
- puts "...%.2fs to clean up temporary files" % ((lap=Time.now)-lap)
36
+ puts "...%.2fs to clean up temporary files" % (Time.now-lap)
37
+ lap = Time.now
35
38
 
36
39
  # Spin a new thread so it doesn't hold up the Ruby process, but sleep long enough for it to get going.
37
40
  Thread.new{ `hh.exe "#{FileUtils.win_path @chm_path}"` }
@@ -37,7 +37,7 @@ class DocuBot::HTMLWriter < DocuBot::Writer
37
37
  template = Haml::Engine.new( IO.read( template ), HAML_OPTIONS )
38
38
  @bundle.toc.descendants.each do |page|
39
39
  next if page.sublink?
40
- contents = page.to_html!
40
+ contents = page.to_html
41
41
  root = "../" * page.depth
42
42
  html = template.render( o, :page=>page, :contents=>contents, :global=>@bundle.toc, :root=>root )
43
43
  FileUtils.mkdir_p( File.dirname( page.html_path ) )
@@ -0,0 +1,12 @@
1
+ #encoding: UTF-8
2
+ $: << '..'
3
+ require 'spec/bundle'
4
+ require 'spec/toc'
5
+ require 'spec/converters'
6
+ require 'spec/page'
7
+ require 'spec/glossary'
8
+ require 'spec/index'
9
+ require 'spec/templates'
10
+ require 'spec/command'
11
+ require 'spec/writer/html'
12
+ require 'spec/writer/chm'
@@ -0,0 +1,6 @@
1
+ $: << File.join( File.dirname(__FILE__), '..' )
2
+ $: << File.join( File.dirname(__FILE__), '..', 'lib' )
3
+ require 'minitest/spec'
4
+ require 'docubot'
5
+ SAMPLES = File.dirname(__FILE__)/'samples'
6
+ MiniTest::Unit.autorun
@@ -0,0 +1,142 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
3
+
4
+ describe "AbusedBundle" do
5
+ it 'requires a valid path' do
6
+ proc{ DocuBot::Bundle.new }.must_raise(ArgumentError)
7
+ proc{ DocuBot::Bundle.new "does not exist" }.must_raise(RuntimeError)
8
+ DocuBot::Bundle.new(SAMPLES/'empty').wont_be_nil
9
+ end
10
+ end
11
+
12
+ describe "Bundle from empty directory" do
13
+ before do
14
+ @out, @err = capture_io do
15
+ @bundle = DocuBot::Bundle.new SAMPLES/'empty'
16
+ end
17
+ end
18
+
19
+ it "should have an empty TOC" do
20
+ @bundle.toc.wont_be_nil
21
+ @bundle.toc.pages.must_be_empty
22
+ end
23
+
24
+ it "should have an empty index" do
25
+ @bundle.index.wont_be_nil
26
+ @bundle.index.entries.must_be_empty
27
+ end
28
+
29
+ it "should have an empty glossary" do
30
+ @bundle.glossary.wont_be_nil
31
+ @bundle.glossary.entries.must_be_empty
32
+ end
33
+
34
+ it "should have an empty external link list" do
35
+ @bundle.external_links.wont_be_nil
36
+ @bundle.external_links.must_be_empty
37
+ end
38
+
39
+ it "should have an empty internal link list" do
40
+ @bundle.internal_links.wont_be_nil
41
+ @bundle.internal_links.must_be_empty
42
+ end
43
+
44
+ it "should have an empty file link list" do
45
+ @bundle.file_links.wont_be_nil
46
+ @bundle.file_links.must_be_empty
47
+ end
48
+
49
+ it "should have an empty broken link list" do
50
+ @bundle.broken_links.wont_be_nil
51
+ @bundle.broken_links.must_be_empty
52
+ end
53
+
54
+ it "should produce no warnings" do
55
+ @err.must_be_empty
56
+ end
57
+
58
+ end
59
+
60
+
61
+ describe "Gathering links" do
62
+ before do
63
+ @out, @err = capture_io do
64
+ @bundle = DocuBot::Bundle.new SAMPLES/'link_test'
65
+ end
66
+ end
67
+
68
+ it "should have link collections be pages hashed to arrays of strings" do
69
+ %w[ external_links internal_links file_links broken_links ].each do |method|
70
+ collection = @bundle.send(method)
71
+ collection.must_be_kind_of Hash
72
+ collection.keys.each do |key|
73
+ key.must_be_kind_of DocuBot::Page
74
+ end
75
+ collection.values.each do |value|
76
+ value.must_be_kind_of Array
77
+ value.each do |item|
78
+ item.must_be_kind_of String
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ it "should identify (but not validate) external links" do
85
+ known_external = %w[ http://www.google.com/ http://phrogz.net http://phrogz.net/tmp/gkhead.jpg HTTP://NONEXISTENT.SITE ]
86
+ all_external = @bundle.external_links.values.flatten
87
+ known_external.each do |link|
88
+ all_external.must_include link
89
+ end
90
+ end
91
+
92
+ it "should identify and warn about broken internal links" do
93
+ known_broken = %w[
94
+ fork.html sub1.html root.md sub1/inner1.md
95
+ inner2.html ../sub1 sub1/inner1.md
96
+ ../index.html ../sub1 ../index.md
97
+ sub2/GORKBO.bin
98
+ ]
99
+ all_broken = @bundle.broken_links.values.flatten
100
+ known_broken.each do |link|
101
+ all_broken.must_include link
102
+ @err.must_include link
103
+ end
104
+ end
105
+
106
+ it "should identify valid links to pages or sections" do
107
+ known_internal = %w[
108
+ sub1/inner1.html sub2.html sub2/inner2.html sub1/../sub2/inner2.html
109
+ ../root.html inner1.html ../sub2.html ../sub2/inner2.html
110
+ ../sub1/index.html index.html
111
+ ]
112
+ all_internal = @bundle.internal_links.values.flatten
113
+ known_internal.each do |link|
114
+ all_internal.must_include link
115
+ end
116
+ end
117
+
118
+ it "should identify valid links to internal files" do
119
+ known_file_links = %w[ ../sub2/bozo.bin bozo.bin sub2/bozo.bin ]
120
+ all_file_links = @bundle.file_links.values.flatten
121
+ known_file_links.each do |link|
122
+ all_file_links.must_include link
123
+ end
124
+ end
125
+
126
+ it "should identify and warn about invalid sub-page anchors" do
127
+ known_broken = %w[ #GORKBO ../root.html#GORKBO ]
128
+ all_broken = @bundle.broken_links.values.flatten
129
+ known_broken.each do |link|
130
+ all_broken.must_include link
131
+ @err.must_include link
132
+ end
133
+ end
134
+
135
+ it "should identify valid sub-page anchors" do
136
+ known_internal = %w[ #sub-id root.html#sub-id ../root.html#sub-id ]
137
+ all_internal = @bundle.internal_links.values.flatten
138
+ known_internal.each do |link|
139
+ all_internal.must_include link
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,3 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
3
+
@@ -0,0 +1,2 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
@@ -0,0 +1,93 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
3
+
4
+ describe "Glossary Scanner" do
5
+ before do
6
+ @public_terms = [ "Simple Term", "Complex Term" ]
7
+ @hidden_terms = [ "Secret Term"]
8
+ @all_terms = @public_terms + @hidden_terms
9
+ @expected_paragraphs = {
10
+ "Simple Term" => 2,
11
+ "Complex Term" => 3
12
+ }
13
+ @out, @err = capture_io do
14
+ @bundle = DocuBot::Bundle.new SAMPLES/'glossary'
15
+ @glossary = @bundle.glossary
16
+ @page = @bundle.toc.every_page.find{ |page| page.title=='Glossary' }
17
+ @fulldoc = Nokogiri::HTML( @page.to_html )
18
+ end
19
+ end
20
+
21
+ # No _glossary folder handled in the Bundle spec for empty site
22
+
23
+ it "should have one internal entry for each term defined in _glossary" do
24
+ @glossary.entries.size.must_equal @all_terms.length
25
+ end
26
+
27
+ it "should honor page titles as terms" do
28
+ @all_terms.each do |term|
29
+ @glossary.entries[term].wont_be_nil
30
+ end
31
+ end
32
+
33
+ it "uses DocuBot::Page instances for the definitions" do
34
+ @glossary.entries.values.each do |defn|
35
+ defn.must_be_kind_of DocuBot::Page
36
+ end
37
+ @glossary.entries["Secret Term"].hide.must_equal true
38
+ end
39
+
40
+ it "supports iterating over the entries with each" do
41
+ count = 0
42
+ @glossary.each do |page,defn|
43
+ page.must_be_kind_of String
44
+ defn.must_be_kind_of DocuBot::Page
45
+ count += 1
46
+ end
47
+ count.must_equal @all_terms.length
48
+ end
49
+
50
+
51
+ it "uses converters for page content" do
52
+ @expected_paragraphs.each do |term,paras|
53
+ @glossary.entries[term].nokodoc.xpath('//p').length.must_equal paras
54
+ end
55
+ end
56
+
57
+ it "supports a glossary template that generates HTML for terms" do
58
+ definitions = @fulldoc.xpath('//dt')
59
+ @expected_paragraphs.each do |term,paras|
60
+ dt = definitions.find{ |node| node.inner_text==term }
61
+ dt.wont_be_nil
62
+ dt.next_element.xpath('.//p').length.must_equal paras
63
+ end
64
+ end
65
+
66
+ it "does not include hidden pages in the output" do
67
+ definitions = @fulldoc.xpath('//dt')
68
+ @hidden_terms.each do |term|
69
+ @fulldoc.at_xpath("//dt[text()='#{term}']").must_be_nil
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "Glossary Snippet" do
75
+ before do
76
+ @out, @err = capture_io do
77
+ @bundle = DocuBot::Bundle.new SAMPLES/'glossary'
78
+ @glossary = @bundle.glossary
79
+ end
80
+ end
81
+
82
+ it "should know about missing terms" do
83
+ @glossary.missing_terms.must_include "crazy term"
84
+ end
85
+
86
+ it "should not mistake alternate text for a missing term" do
87
+ @glossary.missing_terms.wont_include "more complex term"
88
+ end
89
+
90
+ it "should warn about missing terms" do
91
+ @err.must_include "crazy term"
92
+ end
93
+ end
@@ -0,0 +1,2 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
@@ -0,0 +1,24 @@
1
+ #encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), "_helper")
3
+
4
+ describe "Pages from 'titletest'" do
5
+ before do
6
+ @bundle = DocuBot::Bundle.new( SAMPLES/'titletest' )
7
+ @toc = @bundle.toc
8
+ end
9
+ it "knows who its bundle is" do
10
+ @toc.pages.each{ |page| page.bundle.must_equal @bundle }
11
+ end
12
+ it "ignores leading numbers for the titles" do
13
+ @toc.pages.each{ |page| page.title.must_match /^\D/ }
14
+ end
15
+ it "honors pages specifying their title" do
16
+ @toc.pages.find{ |page| page.title =~ /renamed/i }.must_be_nil
17
+ @toc.pages.find{ |page| page.title == 'Third One' }.wont_be_nil
18
+ end
19
+ it "replaces underscores with spaces in the title" do
20
+ %w[ First Second Third Fourth Fifth ].each_with_index do |name,i|
21
+ @toc.pages[i].title.must_equal "#{name} One"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ template: glossary
2
+ +++
3
+ The `glossary.haml` template writes out the glossary contents.
4
+ This page tells it where to be generated and how to be named.
5
+ The contents of this page are ignored by the `glossary.haml` template.
@@ -0,0 +1,3 @@
1
+ This page mentions both a $$simple term$$ and a $$more complex term:complex term$$.
2
+
3
+ It also mentions a $$crazy term$$, which is never defined.
@@ -0,0 +1,3 @@
1
+ This is a simple term.
2
+
3
+ It is defined in two paragraphs.
@@ -0,0 +1,8 @@
1
+ title: Complex Term
2
+ todo : Document why this is complex.
3
+ +++
4
+ - 3.times do |i|
5
+ %p
6
+ This is a complex term.
7
+ It is described in three paragraphs.
8
+ This is paragraph ##{i+1}.
@@ -0,0 +1,4 @@
1
+ title: Secret Term
2
+ hide : true
3
+ +++
4
+ This must not be shown until the aliens have revealed themselves to the public.
@@ -0,0 +1,11 @@
1
+ The global root of the site is not a valid link.
2
+
3
+ | external | valid | file | broken |
4
+ -----------------+----------+-------+------+--------+
5
+ | root.md | 1 | 6 | 0 | 5 |
6
+ | sub1/inner1.md | 1 | 5 | 1 | 4 |
7
+ | sub2/inner2.md | 1 | 2 | 1 | 3 |
8
+ | sub2.md | 1 | 0 | 1 | 1 |
9
+ -----------------+----------+-------+------+--------+
10
+ TOTALS | 4 | 13 | 3 | 13 |
11
+ +----------+-------+------+--------+
@@ -0,0 +1,14 @@
1
+ [External](http://www.google.com/)
2
+ [Internal](#sub-id)
3
+ [Internal](root.html#sub-id)
4
+ [Internal](sub1/inner1.html)
5
+ [Internal](sub2.html)
6
+ [Internal](sub2/inner2.html)
7
+ [Internal](sub1/../sub2/inner2.html)
8
+ [BROKEN](fork.html)
9
+ [BROKEN](sub1.html)
10
+ [BROKEN](root.md)
11
+ [BROKEN](sub1/inner1.md)
12
+ [BROKEN](#GORKBO)
13
+
14
+ <div id="sub-id">Just in case</div>
@@ -0,0 +1,11 @@
1
+ [External](http://phrogz.net)
2
+ [Internal](../root.html)
3
+ [Internal](../root.html#sub-id)
4
+ [Internal](inner1.html)
5
+ [Internal](../sub2.html)
6
+ [Internal](../sub2/inner2.html)
7
+ [File](../sub2/bozo.bin)
8
+ [BROKEN](inner2.html)
9
+ [BROKEN](../sub1)
10
+ [BROKEN](sub1/inner1.md)
11
+ [BROKEN](../root.html#GORKBO)
@@ -0,0 +1,3 @@
1
+ [External](HTTP://NONEXISTENT.SITE)
2
+ [File](sub2/bozo.bin)
3
+ [BROKEN](sub2/GORKBO.bin)
@@ -0,0 +1,7 @@
1
+ [External](http://phrogz.net/tmp/gkhead.jpg)
2
+ [Internal](../sub1/index.html) Even though there isn't an index.md file.
3
+ [Internal](index.html) Even though there isn't an index.md file.
4
+ [File](bozo.bin)
5
+ [BROKEN](../index.html) Because the global root is not a valid link.
6
+ [BROKEN](../sub1)
7
+ [BROKEN](../index.md)