docubot 0.3.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/bin/docubot +5 -1
  2. data/lib/docubot.rb +4 -2
  3. data/lib/docubot/bundle.rb +109 -61
  4. data/lib/docubot/converter.rb +4 -1
  5. data/lib/docubot/converters/haml.rb +1 -1
  6. data/lib/docubot/glossary.rb +3 -0
  7. data/lib/docubot/link_tree.rb +109 -0
  8. data/lib/docubot/metasection.rb +61 -0
  9. data/lib/docubot/page.rb +40 -118
  10. data/lib/docubot/shells/docubot-help/3_Advanced_Topics/Controlling the Table of Contents.md +2 -4
  11. data/lib/docubot/shells/nvphysx/_templates/_root/common.css +10 -5
  12. data/lib/docubot/shells/nvphysx/_templates/_root/glossary.css +1 -0
  13. data/lib/docubot/shells/nvphysx/_templates/_root/glossary.js +11 -1
  14. data/lib/docubot/shells/nvphysx/_templates/section.haml +9 -0
  15. data/lib/docubot/templates/index.haml +13 -20
  16. data/lib/docubot/templates/section.haml +1 -4
  17. data/lib/docubot/templates/toc.haml +2 -11
  18. data/lib/docubot/templates/top.haml +7 -4
  19. data/lib/docubot/writers/chm.rb +6 -5
  20. data/lib/docubot/writers/chm/hhc.erb +35 -12
  21. data/lib/docubot/writers/chm/hhk.erb +1 -1
  22. data/lib/docubot/writers/chm/hhp.erb +2 -2
  23. data/lib/docubot/writers/html.rb +33 -23
  24. data/spec/_all.rb +1 -0
  25. data/spec/_helper.rb +10 -0
  26. data/spec/bundle.rb +193 -2
  27. data/spec/global.rb +28 -0
  28. data/spec/glossary.rb +13 -11
  29. data/spec/page.rb +35 -9
  30. data/spec/samples/attributes/defaults.haml +34 -0
  31. data/spec/samples/attributes/explicit1.haml +43 -0
  32. data/spec/samples/attributes/explicit2.haml +42 -0
  33. data/spec/samples/attributes/hidden.haml +40 -0
  34. data/spec/samples/attributes/index.md +8 -0
  35. data/spec/samples/collisions/page1.md +3 -0
  36. data/spec/samples/collisions/page1.textile +3 -0
  37. data/spec/samples/collisions/page2.haml +4 -0
  38. data/spec/samples/collisions/page2.html +3 -0
  39. data/spec/samples/collisions/page2.txt +3 -0
  40. data/spec/samples/collisions/page3.bin +1 -0
  41. data/spec/samples/collisions/page3.md +3 -0
  42. data/spec/samples/{link_test/sub2/bozo.bin → files/BUILDING.txt} +0 -0
  43. data/spec/samples/{titletest/1 First One.txt → files/_static/Thumbs.db} +0 -0
  44. data/spec/samples/{titletest/2_Second_One.txt → files/_static/foo.ai} +0 -0
  45. data/spec/samples/{titletest/4 Fourth_One.txt → files/_static/foo.png} +0 -0
  46. data/spec/samples/{titletest/5_Fifth One.txt → files/_static/foo.psd} +0 -0
  47. data/spec/samples/files/another.md +0 -0
  48. data/spec/samples/files/common.css +0 -0
  49. data/spec/samples/files/first.textile +0 -0
  50. data/spec/samples/files/index.md +2 -0
  51. data/spec/samples/files/section/foo.jpg +0 -0
  52. data/spec/samples/files/section/page.haml +0 -0
  53. data/spec/samples/files/section/sub section/Thumbs.db b/data/spec/samples/files/section/sub → section/Thumbs.db +0 -0
  54. data/spec/samples/files/section/sub section/foo.gif b/data/spec/samples/files/section/sub → section/foo.gif +0 -0
  55. data/spec/samples/files/section/sub section/page.txt b/data/spec/samples/files/section/sub → section/page.txt +0 -0
  56. data/spec/samples/{link_test → links}/index.txt +0 -0
  57. data/spec/samples/{link_test → links}/root.md +0 -0
  58. data/spec/samples/{link_test → links}/sub1/inner1.md +0 -0
  59. data/spec/samples/{link_test → links}/sub2.md +0 -0
  60. data/spec/samples/links/sub2/bozo.bin +0 -0
  61. data/spec/samples/{link_test → links}/sub2/inner2.md +0 -0
  62. data/spec/samples/templates/_templates/404.haml +1 -0
  63. data/spec/samples/templates/_templates/doubler.haml +7 -0
  64. data/spec/samples/templates/_templates/page.haml +2 -0
  65. data/spec/samples/templates/goaway.txt +3 -0
  66. data/spec/samples/templates/onepara_html.html +3 -0
  67. data/spec/samples/templates/onepara_md.md +5 -0
  68. data/spec/samples/templates/twopara_haml.haml +7 -0
  69. data/spec/samples/templates/twopara_textile.textile +6 -0
  70. data/spec/samples/titles/1 First One.txt b/data/spec/samples/titles/1 First → One.txt +0 -0
  71. data/spec/samples/titles/2_Second_One.txt +0 -0
  72. data/spec/samples/{titletest → titles}/3_renamed.txt +0 -0
  73. data/spec/samples/titles/4 Fourth_One.txt b/data/spec/samples/titles/4 → Fourth_One.txt +0 -0
  74. data/spec/samples/titles/5_Fifth One.txt b/data/spec/samples/titles/5_Fifth → One.txt +0 -0
  75. data/spec/samples/titles/911.txt +0 -0
  76. data/spec/samples/titles/index.txt +2 -0
  77. data/spec/templates.rb +42 -0
  78. data/spec/toc.rb +64 -30
  79. metadata +53 -14
  80. data/spec/samples/titletest/index.txt +0 -2
@@ -1,24 +1,50 @@
1
1
  #encoding: UTF-8
2
2
  require File.join(File.dirname(__FILE__), "_helper")
3
3
 
4
- describe "Pages from 'titletest'" do
4
+ describe "Validating page titles" do
5
5
  before do
6
- @bundle = DocuBot::Bundle.new( SAMPLES/'titletest' )
6
+ @bundle = DocuBot::Bundle.new( SAMPLES/'titles' )
7
7
  @toc = @bundle.toc
8
8
  end
9
9
  it "knows who its bundle is" do
10
- @toc.pages.each{ |page| page.bundle.must_equal @bundle }
10
+ @toc.children.each{ |node| node.page.bundle.must_equal @bundle }
11
11
  end
12
- it "ignores leading numbers for the titles" do
13
- @toc.pages.each{ |page| page.title.must_match /^\D/ }
12
+ it "ignores leading numbers for the titles (unless all numbers)" do
13
+ @toc.children.each{ |node| node.page.title.must_match /(?:^\D|^\d+$)/ }
14
14
  end
15
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
16
+ @toc.children.find{ |page| page.title =~ /renamed/i }.must_be_nil
17
+ @toc.children.find{ |page| page.title == 'Third One' }.wont_be_nil
18
18
  end
19
19
  it "replaces underscores with spaces in the title" do
20
20
  %w[ First Second Third Fourth Fifth ].each_with_index do |name,i|
21
- @toc.pages[i].title.must_equal "#{name} One"
21
+ @toc.children[i].page.title.must_equal "#{name} One"
22
22
  end
23
23
  end
24
- end
24
+ it "doesn't change names of files that are all numbers" do
25
+ @toc.children.find{ |node| node.page.title == '911' }.wont_be_nil
26
+ end
27
+ end
28
+
29
+ describe "Traversing page hierarchy" do
30
+ before do
31
+ @out, @err = capture_io do
32
+ @bundle = DocuBot::Bundle.new( SAMPLES/'links' )
33
+ end
34
+ end
35
+ it "should have #pages returning an array" do
36
+ @bundle.pages.must_be_kind_of Array
37
+ @bundle.pages.length.must_equal 6
38
+ end
39
+ it "every item should be a Page" do
40
+ @bundle.pages.each do |page|
41
+ page.must_be_kind_of DocuBot::Page
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "Testing user variables" do
47
+ it "should identify if a variable has been defined"
48
+ it "should inherit variables from the global"
49
+ it "should override variables from the global"
50
+ end
@@ -0,0 +1,34 @@
1
+ This page specifies no attributes; what defaults will it get?
2
+
3
+ %h2#h1 Heading 1
4
+ %p#p1-1 Paragraph Number 1.1
5
+ %p#p1-2 Paragraph Number 1.2
6
+ %ul
7
+ %li A list of items
8
+ %li A list of items
9
+ %li A list of items
10
+
11
+ %h3#h1-1 Heading 1.1
12
+ %p#p1-1-1 Paragraph Number 1.1.1
13
+
14
+ %h2#h2 Heading 2
15
+ %h3#h2-1 Heading 2.1
16
+ %h4#h2-1-1 Heading 2.1.1
17
+ %h5#h2-1-1-1 Heading 2.1.1.1
18
+ %p#p2-1-1-1-1 Paragraph Number 2.1.1.1.1
19
+
20
+ %h3#h2-2 Heading 2.2
21
+ %p#p2-2-1 Paragraph Number 2.2.1
22
+ %dl
23
+ %dt#dt1 Giggity
24
+ %dd#dd1 Quagmire
25
+ %dt#dt2 Zanzibar
26
+ %dd#dd2 The Best
27
+
28
+ %p#p2-2-2 Paragraph Number 2.2.2
29
+
30
+ %h1#h0 Heading 0
31
+ %p#p0-1
32
+ Paragraph 0.1
33
+ Whoa, this heading is larger than any other before it!
34
+
@@ -0,0 +1,43 @@
1
+ title: Jiggly Awesome
2
+ keywords: explicit, metasection, attributes/specifying
3
+ no-index: headings, definitions
4
+ auto-section:false
5
+ toc: #h1, #h1-1, #div
6
+ auto-id : true
7
+ +++
8
+ %h2#h1 Heading 1
9
+ %p#p1-1 Paragraph Number 1.1
10
+ %p#p1-2 Paragraph Number 1.2
11
+ %ul
12
+ %li A list of items
13
+ %li A list of items
14
+ %li A list of items
15
+
16
+ %h3#h1-1 Heading 1.1
17
+ %p#p1-1-1 Paragraph Number 1.1.1
18
+
19
+ %h2#h2 Heading 2
20
+ %h3#h2-1 Heading 2.1
21
+ %h4#h2-1-1 Heading 2.1.1
22
+ %h5#h2-1-1-1 Heading 2.1.1.1
23
+ %p#p2-1-1-1-1 Paragraph Number 2.1.1.1.1
24
+
25
+ %h3#h2-2 Heading 2.2
26
+ %p#p2-2-1 Paragraph Number 2.2.1
27
+ %dl
28
+ %dt#dt1 Giggity
29
+ %dd#dd1 Quagmire
30
+ %dt#dt2 Zanzibar
31
+ %dd#dd2 The Best
32
+
33
+ %p#p2-2-2 Paragraph Number 2.2.2
34
+
35
+ %h1#h0 Heading 0
36
+ %p#p0-1
37
+ Paragraph 0.1
38
+ Whoa, this heading is larger than any other before it!
39
+
40
+ #div
41
+ Text content
42
+ %b is
43
+ cool.
@@ -0,0 +1,42 @@
1
+ title: Combo the Other
2
+ keywords: explicit, metasection, attributes/specifying
3
+ no-index: headings
4
+ auto-section:true
5
+ toc: Heading 1, #h1-1, Giggity, #h0
6
+ +++
7
+ %h2#h1 Heading 1
8
+ %p#p1-1 Paragraph Number 1.1
9
+ %p#p1-2 Paragraph Number 1.2
10
+ %ul
11
+ %li A list of items
12
+ %li A list of items
13
+ %li A list of items
14
+
15
+ %h3#h1-1 Heading 1.1
16
+ %p#p1-1-1 Paragraph Number 1.1.1
17
+
18
+ %h2#h2 Heading 2
19
+ %h3#h2-1 Heading 2.1
20
+ %h4#h2-1-1 Heading 2.1.1
21
+ %h5#h2-1-1-1 Heading 2.1.1.1
22
+ %p#p2-1-1-1-1 Paragraph Number 2.1.1.1.1
23
+
24
+ %h3#h2-2 Heading 2.2
25
+ %p#p2-2-1 Paragraph Number 2.2.1
26
+ %dl
27
+ %dt Giggity
28
+ %dd#dd1 Quagmire
29
+ %dt#dt2 Zanzibar
30
+ %dd#dd2 The Best
31
+
32
+ %p#p2-2-2 Paragraph Number 2.2.2
33
+
34
+ %h1#h0 Heading 0
35
+ %p#p0-1
36
+ Paragraph 0.1
37
+ Whoa, this heading is larger than any other before it!
38
+
39
+ #div
40
+ Text content
41
+ %b is
42
+ cool.
@@ -0,0 +1,40 @@
1
+ auto-id: true
2
+ hide: true
3
+ toc: Heading 1, Heading 2
4
+ +++
5
+ %h2 Heading 1
6
+ %p Paragraph Number 1.1
7
+ %p Paragraph Number 1.2
8
+ %ul
9
+ %li A list of items
10
+ %li A list of items
11
+ %li A list of items
12
+
13
+ %h3 Heading 1.1
14
+ %p Paragraph Number 1.1.1
15
+
16
+ %h2 Heading 2
17
+ %h3 Heading 2.1
18
+ %h4 Heading 2.1.1
19
+ %h5 Heading 2.1.1.1
20
+ %p Paragraph Number 2.1.1.1.1
21
+
22
+ %h3 Heading 2.2
23
+ %p Paragraph Number 2.2.1
24
+ %dl
25
+ %dt#dt1 Giggity
26
+ %dd#dd1 Quagmire
27
+ %dt Zanzibar
28
+ %dd The Best
29
+
30
+ %p Paragraph Number 2.2.2
31
+
32
+ %h1 Heading 0
33
+ %p
34
+ Paragraph 0.1
35
+ Whoa, this heading is larger than any other before it!
36
+
37
+ #div
38
+ Text content
39
+ %b is
40
+ cool.
@@ -0,0 +1,8 @@
1
+ title : Friggles® The Cat, ©2009
2
+ author :Gavin Kistner
3
+ default: All About Mr. Friggles
4
+ quotes:"It's all about Mr. Benjamin", "I have never seen this cat before in my life!"
5
+ author.email : !@phrogz.net
6
+ author website :http://phrogz.net
7
+ awesome : true
8
+ +++
@@ -0,0 +1,3 @@
1
+ title: Page 1 (from Markdown)
2
+ +++
3
+ This will collide with Page 1 (from Textile)
@@ -0,0 +1,3 @@
1
+ title: Page 1 (from Textile)
2
+ +++
3
+ This will collide with Page 1 (from Markdown)
@@ -0,0 +1,4 @@
1
+ title: Page 2 (from haml)
2
+ +++
3
+ %p
4
+ This will collide with Page 2 (from html) and Page 2 (from text)
@@ -0,0 +1,3 @@
1
+ title: Page 2 (from html)
2
+ +++
3
+ <p>This will collide with Page 2 (from text) and Page 2 (from haml).</p>
@@ -0,0 +1,3 @@
1
+ title: Page 2 (from text)
2
+ +++
3
+ This will collide with Page 2 (from html) and Page 2 (from haml)
@@ -0,0 +1 @@
1
+ (Some unrecognized file type.)
@@ -0,0 +1,3 @@
1
+ title: Page 3
2
+ +++
3
+ This won't collide with page3.bin
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ ignore: **/*.psd, **/*.ai, **/Thumbs.db, BUILDING.txt
2
+ +++
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ %p Oops! The page you were looking for was not found. (Tee hee!)
@@ -0,0 +1,7 @@
1
+ #doubler
2
+ - if page.multiplier?
3
+ - page.multiplier.to_i.times do
4
+ = contents
5
+ - else
6
+ = contents
7
+ = contents
@@ -0,0 +1,2 @@
1
+ #pager
2
+ = contents
@@ -0,0 +1,3 @@
1
+ template: 404
2
+ +++
3
+ I DO NOT LIKE YOU
@@ -0,0 +1,3 @@
1
+ title: 1*1
2
+ +++
3
+ <p>Para1</p>
@@ -0,0 +1,5 @@
1
+ title : 1*2
2
+ template : doubler
3
+ multiplier : 3
4
+ +++
5
+ Para1
@@ -0,0 +1,7 @@
1
+ title : 2*1
2
+ template: page
3
+ +++
4
+ %p
5
+ Para1
6
+ %p
7
+ Para2
@@ -0,0 +1,6 @@
1
+ title: 2*2
2
+ template: doubler
3
+ +++
4
+ p. Para1
5
+
6
+ p. Para2
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ title : Title Changin'
2
+ +++
@@ -1,2 +1,44 @@
1
1
  #encoding: UTF-8
2
2
  require File.join(File.dirname(__FILE__), "_helper")
3
+
4
+ describe "Variety Hour" do
5
+ before do
6
+ @bundle = DocuBot::Bundle.new( SAMPLES/'templates' )
7
+ @page_by_title = Hash[ *@bundle.pages.map{ |p| [p.title,p] }.flatten ]
8
+ end
9
+
10
+ it "uses the 'page' template if not specified" do
11
+ @page_by_title.must_include '1*1'
12
+ html = @page_by_title['1*1'].to_html
13
+ html.must_include 'pager'
14
+ html.scan(/<p>/).length.must_equal 1
15
+ end
16
+
17
+ it "passes the page for use by another specified template" do
18
+ @page_by_title.must_include '1*2'
19
+ html = @page_by_title['1*2'].to_html
20
+ html.must_include 'doubler'
21
+ html.scan(/<p>/).length.must_equal 3
22
+ end
23
+
24
+ it "can use the 'page' template explicitly" do
25
+ @page_by_title.must_include '2*1'
26
+ html = @page_by_title['2*1'].to_html
27
+ html.must_include 'page'
28
+ html.scan(/<p>/).length.must_equal 2
29
+ end
30
+
31
+ it "should have templates handle missing attributes" do
32
+ @page_by_title.must_include '2*2'
33
+ html = @page_by_title['2*2'].to_html
34
+ html.must_include 'doubler'
35
+ html.scan(/<p>/).length.must_equal 4
36
+ end
37
+
38
+ it "can have templates that do not include contents" do
39
+ @page_by_title.must_include 'goaway'
40
+ html = @page_by_title['goaway'].to_html
41
+ html.must_include 'Oops!'
42
+ html.wont_include 'I DO NOT LIKE YOU'
43
+ end
44
+ end
@@ -14,32 +14,18 @@ describe "Simplest Table of Contents" do
14
14
  @toc.bundle.must_equal @bundle
15
15
  end
16
16
 
17
- it "responds to queries for undefined attributes" do
18
- @toc.never_defined_attribute?.must_equal false
19
- @toc.never_defined_attribute.must_be_nil
20
- end
21
-
22
- it "responds to queries for defined attributes" do
23
- @toc.title?.must_equal true
24
- @toc.title.wont_be_nil
25
- end
26
-
27
- it "defaults to the name 'Table of Contents'" do
28
- @toc.title.must_equal "Table of Contents"
29
- end
30
-
31
17
  it "preserves simple names as titles" do
32
- @toc.pages.length.must_equal @files.length
18
+ @toc.children.length.must_equal @files.length
33
19
  @files.each do |source_file|
34
20
  filename_without_extension = source_file.sub( /\.[^.]+$/, '' )
35
- @toc.pages.find{ |page| page.title==filename_without_extension }.wont_be_nil
21
+ @toc.children.find{ |node| node.title==filename_without_extension }.wont_be_nil
36
22
  end
37
23
  end
38
24
 
39
25
  it "preserves file system ordering" do
40
26
  @files.each_with_index do |source_file,i|
41
27
  filename_without_extension = source_file.sub( /\.[^.]+$/, '' )
42
- @toc.pages[i].title.must_equal filename_without_extension
28
+ @toc.children[i].title.must_equal filename_without_extension
43
29
  end
44
30
  end
45
31
 
@@ -48,26 +34,74 @@ describe "Simplest Table of Contents" do
48
34
  @toc.ancestors.must_be_empty
49
35
  end
50
36
 
51
- it "is the parent of all top-level pages" do
52
- @toc.pages.each{ |page| page.parent.must_equal @toc }
37
+ it "is not the parent of any top-level links" do
38
+ @toc.children.each{ |node| node.parent.wont_equal @toc }
53
39
  end
54
40
 
55
- it "is not a leaf" do
56
- @toc.leaf?.must_equal false
57
- end
58
-
59
41
  it "is at depth 0 with no root" do
60
42
  @toc.depth.must_equal 0
61
- @toc.root.must_equal ""
62
- end
63
-
64
- it "raises an error setting a non-standard attribute" do
65
- proc{ @toc.title = "Yo!" }.must_raise(NoMethodError)
66
- end
43
+ end
67
44
  end
68
45
 
69
46
  describe "Renamed Table of Contents" do
70
47
  it "honors the title of the root index file" do
71
- DocuBot::Bundle.new(SAMPLES/'titletest').toc.title.must_equal "Title Changin'"
48
+ DocuBot::Bundle.new(SAMPLES/'titles').global.title.must_equal "Title Changin'"
49
+ end
50
+ end
51
+
52
+ describe "Sub-page Links in the Table of Contents" do
53
+ before do
54
+ @out, @err = capture_io do
55
+ @bundle = DocuBot::Bundle.new SAMPLES/'attributes'
56
+ @toc = @bundle.toc
57
+ end
58
+ end
59
+
60
+ it "should find pages by html link" do
61
+ e1 = @toc.find('explicit1.html')
62
+ e1.wont_be_nil
63
+ e1.page.wont_be_nil
64
+ e1.page.file == 'explicit1.haml'
65
+ end
66
+
67
+ it "should not have entries for hidden pages" do
68
+ @bundle.pages_by_title['hidden'].wont_be_empty
69
+ hidden = @bundle.page_by_html_path['hidden.html']
70
+ hidden.wont_be_nil
71
+ @toc.find('hidden.html').must_be_nil
72
+ @toc.descendants.select{ |node| node.link['hidden.html'] }.must_be_empty
73
+ end
74
+
75
+ it "should warn about failed TOC requests" do
76
+ # explicit2.haml has an existing ID on the element for "Heading 1",
77
+ # so it can't update the HTML id or the TOC request to match.
78
+ @err.must_include "Heading 1"
79
+ end
80
+
81
+ it "should have sub-entries" do
82
+ e2 = @toc.find('explicit2.html')
83
+
84
+ e2.children.length.must_equal 3
85
+
86
+ # The first sub-link is not "Heading 1" because explicit2.haml has an existing ID on that element
87
+ # and so cannot (at this time) change either the HTML id or the TOC request to match.
88
+ # It is ignored.
89
+ kid = e2.children[0]
90
+ kid.title.must_equal "Heading 1.1"
91
+ kid.link.must_equal 'explicit2.html#h1-1'
92
+ kid.page.must_equal e2.page
93
+
94
+ kid = e2.children[1]
95
+ kid.title.must_equal "Giggity"
96
+ kid.file.must_equal 'explicit2.html'
97
+ # No assumptions are made about the generated id.
98
+ kid.page.must_equal e2.page
99
+
100
+ kid = e2.children[2]
101
+ kid.title.must_equal "Heading 0"
102
+ kid.file.must_equal 'explicit2.html'
103
+ kid.anchor.must_equal 'h0'
104
+ kid.link.must_equal 'explicit2.html#h0'
105
+ kid.page.must_equal e2.page
72
106
  end
73
107
  end