docubot 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/bin/docubot +125 -125
  2. data/lib/docubot.rb +43 -43
  3. data/lib/docubot/bundle.rb +182 -182
  4. data/lib/docubot/converter.rb +28 -28
  5. data/lib/docubot/converters/haml.rb +9 -9
  6. data/lib/docubot/converters/markdown.rb +14 -14
  7. data/lib/docubot/index.rb +67 -67
  8. data/lib/docubot/link_tree.rb +111 -111
  9. data/lib/docubot/metasection.rb +61 -61
  10. data/lib/docubot/page.rb +167 -167
  11. data/lib/docubot/shells/default/0_License.md +59 -59
  12. data/lib/docubot/shells/default/Appendix/Glossary.md +4 -4
  13. data/lib/docubot/shells/default/Appendix/Index_Page.md +8 -8
  14. data/lib/docubot/shells/default/Appendix/Table of Contents.md +4 -4
  15. data/lib/docubot/shells/docubot-help/0_License.md +20 -20
  16. data/lib/docubot/shells/docubot-help/1_Getting_Started.md +47 -47
  17. data/lib/docubot/shells/docubot-help/2_Basic_Concepts/4 Adding Images.md +1 -1
  18. data/lib/docubot/shells/docubot-help/2_Basic_Concepts/index.md +5 -5
  19. data/lib/docubot/shells/docubot-help/3_Advanced_Topics/Controlling Glossary.md +2 -2
  20. data/lib/docubot/shells/docubot-help/3_Advanced_Topics/Controlling Indexing.md +9 -9
  21. data/lib/docubot/shells/docubot-help/3_Advanced_Topics/Controlling the Table of Contents.md +5 -5
  22. data/lib/docubot/shells/docubot-help/4_Appendix/Glossary.md +4 -4
  23. data/lib/docubot/shells/docubot-help/4_Appendix/Index_Page.md +5 -5
  24. data/lib/docubot/shells/docubot-help/4_Appendix/Table of Contents.md +7 -7
  25. data/lib/docubot/shells/docubot-help/index.txt +7 -7
  26. data/lib/docubot/snippet.rb +19 -19
  27. data/lib/docubot/snippets/glossary.rb +7 -7
  28. data/lib/docubot/snippets/index_entries.rb +6 -6
  29. data/lib/docubot/templates/_root/glossary.css +3 -3
  30. data/lib/docubot/templates/_root/glossary.js +57 -57
  31. data/lib/docubot/templates/index.haml +14 -14
  32. data/lib/docubot/templates/toc.haml +2 -2
  33. data/lib/docubot/templates/top.haml +32 -32
  34. data/lib/docubot/writers/chm/hhc.erb +1 -1
  35. data/lib/docubot/writers/chm/hhk.erb +2 -2
  36. data/lib/docubot/writers/html.rb +87 -87
  37. data/spec/_all.rb +12 -12
  38. data/spec/_helper.rb +16 -16
  39. data/spec/bundle.rb +339 -339
  40. data/spec/command.rb +3 -3
  41. data/spec/converters.rb +2 -2
  42. data/spec/global.rb +27 -27
  43. data/spec/glossary.rb +94 -94
  44. data/spec/index.rb +2 -2
  45. data/spec/page.rb +80 -80
  46. data/spec/samples/attributes/defaults.haml +34 -34
  47. data/spec/samples/attributes/explicit1.haml +42 -42
  48. data/spec/samples/attributes/explicit2.haml +41 -41
  49. data/spec/samples/attributes/hidden.haml +39 -39
  50. data/spec/samples/attributes/index.md +8 -8
  51. data/spec/samples/collisions/page1.md +2 -2
  52. data/spec/samples/collisions/page1.textile +2 -2
  53. data/spec/samples/collisions/page2.haml +3 -3
  54. data/spec/samples/collisions/page2.html +2 -2
  55. data/spec/samples/collisions/page2.txt +2 -2
  56. data/spec/samples/collisions/page3.md +2 -2
  57. data/spec/samples/files/index.md +1 -1
  58. data/spec/samples/glossary/Glossary.txt +4 -4
  59. data/spec/samples/glossary/Some Page.md +2 -2
  60. data/spec/samples/glossary/_glossary/Simple Term.md +2 -2
  61. data/spec/samples/glossary/_glossary/complex.haml +8 -8
  62. data/spec/samples/glossary/_glossary/project_x.md +3 -3
  63. data/spec/samples/hierarchy/1/1.1/1.1.1/index.haml +1 -1
  64. data/spec/samples/hierarchy/1/1.1/1.1.1/page.haml +3 -3
  65. data/spec/samples/hierarchy/1/1.1/page.haml +3 -3
  66. data/spec/samples/hierarchy/1/page.haml +3 -3
  67. data/spec/samples/hierarchy/2/2.1/2.1.1/page.haml +3 -3
  68. data/spec/samples/hierarchy/2/2.1/index.haml +1 -1
  69. data/spec/samples/hierarchy/2/2.1/page.haml +3 -3
  70. data/spec/samples/hierarchy/2/page.haml +3 -3
  71. data/spec/samples/hierarchy/main.haml +1 -1
  72. data/spec/samples/hierarchy/toc.md +1 -1
  73. data/spec/samples/links/index.txt +11 -11
  74. data/spec/samples/links/root.md +13 -13
  75. data/spec/samples/links/sub1/inner1.md +11 -11
  76. data/spec/samples/links/sub2.md +4 -4
  77. data/spec/samples/links/sub2/inner2.md +7 -7
  78. data/spec/samples/simplest/HTML.html +9 -9
  79. data/spec/samples/simplest/Haml.haml +12 -12
  80. data/spec/samples/simplest/Markdown.md +9 -9
  81. data/spec/samples/simplest/Text.txt +9 -9
  82. data/spec/samples/simplest/Textile.textile +9 -9
  83. data/spec/samples/templates/_templates/doubler.haml +6 -6
  84. data/spec/samples/templates/_templates/page.haml +1 -1
  85. data/spec/samples/templates/goaway.txt +2 -2
  86. data/spec/samples/templates/onepara_html.html +2 -2
  87. data/spec/samples/templates/onepara_md.md +4 -4
  88. data/spec/samples/templates/twopara_haml.haml +6 -6
  89. data/spec/samples/templates/twopara_textile.textile +5 -5
  90. data/spec/samples/titles/3_renamed.txt +1 -1
  91. data/spec/samples/titles/index.txt +1 -1
  92. data/spec/templates.rb +43 -43
  93. data/spec/toc.rb +128 -128
  94. data/spec/writer/chm.rb +2 -2
  95. data/spec/writer/html.rb +2 -2
  96. metadata +56 -25
  97. data/bin/docubot.bat +0 -1
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
2
- pattern = /\$\$(\w[\w: ]*\w)\$\$/
3
- DocuBot.handle_snippet pattern do |match, page|
4
- parts = match[ 2..-3 ].split(':',2)
5
- text, term = parts.first, parts.last
6
- page.bundle.glossary.term_used( term, page )
7
- "<span class='glossary' term='#{term}'>#{text}</span>"
1
+ # encoding: UTF-8
2
+ pattern = /\$\$(\w[\w: ]*\w)\$\$/
3
+ DocuBot.handle_snippet pattern do |match, page|
4
+ parts = match[ 2..-3 ].split(':',2)
5
+ text, term = parts.first, parts.last
6
+ page.bundle.glossary.term_used( term, page )
7
+ "<span class='glossary' term='#{term}'>#{text}</span>"
8
8
  end
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
- pattern = /@@(\w[\w ]*?)@@/
3
- DocuBot.handle_snippet pattern do |match, page|
4
- keyword = match[ 2..-3 ]
5
- page.bundle.index.add( keyword, page )
6
- keyword
1
+ # encoding: UTF-8
2
+ pattern = /@@(\w[\w ]*?)@@/
3
+ DocuBot.handle_snippet pattern do |match, page|
4
+ keyword = match[ 2..-3 ]
5
+ page.bundle.index.add( keyword, page )
6
+ keyword
7
7
  end
@@ -1,4 +1,4 @@
1
- #glossary-box { display:none; position:absolute; width:30%; background:#e0efcc; border:1px solid #82a851; padding:0.5em 0.9em; font-size:9pt; font-family:Calibri, Tahoma; }
2
- #glossary-box * { margin:0 }
3
- span.glossary { color:#36401C; border-bottom:1px dotted #6e8e34; cursor:help; }
1
+ #glossary-box { display:none; position:absolute; width:30%; background:#e0efcc; border:1px solid #82a851; padding:0.5em 0.9em; font-size:9pt; font-family:Calibri, Tahoma; }
2
+ #glossary-box * { margin:0 }
3
+ span.glossary { color:#36401C; border-bottom:1px dotted #6e8e34; cursor:help; }
4
4
  span.glossary-missing { border-bottom:1px dotted #c00 }
@@ -1,58 +1,58 @@
1
- function handleEvent(obj,eventName,callback,useCapture){
2
- return obj.addEventListener ? obj.addEventListener(eventName,callback,useCapture||false) : obj.attachEvent("on"+eventName,callback);
3
- }
4
-
5
- cssClass = {
6
- _killCache : {},
7
- _findCache : {},
8
- add : function cssClassAdd(obj,className){
9
- this.kill(obj,className);
10
- obj.className+=(obj.className.length?' ':'')+className;
11
- },
12
- kill : function cssClassKill(obj,className){
13
- var re = this._killCache[className] || (this._killCache[className]=new RegExp('(?:^|\\s+)'+className+'(?:\\s+|$)','g') );
14
- obj.className = obj.className.replace(re,'');
15
- },
16
- has : function cssClassHas(obj,className){
17
- var re = this._findCache[className] || (this._findCache[className]=new RegExp('(?:^|\\s+)'+className+'(?:\\s+|$)') );
18
- return re.test( obj.className );
19
- }
20
- };
21
-
22
- function glossaryClick(evt){
23
- if (!evt) evt=event;
24
- var target = evt.target || evt.srcElement;
25
- var term = target.getAttribute('term') || target.innerHTML;
26
- var box = document.getElementById('glossary-box');
27
- box.style.display = 'block';
28
- var scroll = (document.documentElement.scrollTop || document.body.scrollTop )*1;
29
- box.style.left = (evt.clientX+5) + 'px';
30
- box.style.top = (evt.clientY+5) + scroll + 'px';
31
-
32
- var html = $glossaryTerms[term.toLowerCase()];
33
- box.innerHTML = html;
34
-
35
- evt.cancelBubble = true;
36
- if (evt.stopPropogation) evt.stopPropogation();
37
- return false;
38
- }
39
-
40
- handleEvent(window,'load',function(){
41
- for ( var spans=document.getElementsByTagName('span'),i=spans.length-1; i>=0; --i ){
42
- var span = spans[i];
43
- if (cssClass.has(span,'glossary')){
44
- var term = span.getAttribute('term') || span.innerHTML;
45
- if ($glossaryTerms[term.toLowerCase()]){
46
- handleEvent(span,'click',glossaryClick);
47
- }else{
48
- cssClass.kill(span,'glossary');
49
- cssClass.add(span,'glossary-missing');
50
- }
51
-
52
- }
53
- }
54
- var box = document.getElementById('glossary-box');
55
- handleEvent( document.body, 'click', function(){
56
- box.style.display = 'none';
57
- });
1
+ function handleEvent(obj,eventName,callback,useCapture){
2
+ return obj.addEventListener ? obj.addEventListener(eventName,callback,useCapture||false) : obj.attachEvent("on"+eventName,callback);
3
+ }
4
+
5
+ cssClass = {
6
+ _killCache : {},
7
+ _findCache : {},
8
+ add : function cssClassAdd(obj,className){
9
+ this.kill(obj,className);
10
+ obj.className+=(obj.className.length?' ':'')+className;
11
+ },
12
+ kill : function cssClassKill(obj,className){
13
+ var re = this._killCache[className] || (this._killCache[className]=new RegExp('(?:^|\\s+)'+className+'(?:\\s+|$)','g') );
14
+ obj.className = obj.className.replace(re,'');
15
+ },
16
+ has : function cssClassHas(obj,className){
17
+ var re = this._findCache[className] || (this._findCache[className]=new RegExp('(?:^|\\s+)'+className+'(?:\\s+|$)') );
18
+ return re.test( obj.className );
19
+ }
20
+ };
21
+
22
+ function glossaryClick(evt){
23
+ if (!evt) evt=event;
24
+ var target = evt.target || evt.srcElement;
25
+ var term = target.getAttribute('term') || target.innerHTML;
26
+ var box = document.getElementById('glossary-box');
27
+ box.style.display = 'block';
28
+ var scroll = (document.documentElement.scrollTop || document.body.scrollTop )*1;
29
+ box.style.left = (evt.clientX+5) + 'px';
30
+ box.style.top = (evt.clientY+5) + scroll + 'px';
31
+
32
+ var html = $glossaryTerms[term.toLowerCase()];
33
+ box.innerHTML = html;
34
+
35
+ evt.cancelBubble = true;
36
+ if (evt.stopPropogation) evt.stopPropogation();
37
+ return false;
38
+ }
39
+
40
+ handleEvent(window,'load',function(){
41
+ for ( var spans=document.getElementsByTagName('span'),i=spans.length-1; i>=0; --i ){
42
+ var span = spans[i];
43
+ if (cssClass.has(span,'glossary')){
44
+ var term = span.getAttribute('term') || span.innerHTML;
45
+ if ($glossaryTerms[term.toLowerCase()]){
46
+ handleEvent(span,'click',glossaryClick);
47
+ }else{
48
+ cssClass.kill(span,'glossary');
49
+ cssClass.add(span,'glossary-missing');
50
+ }
51
+
52
+ }
53
+ }
54
+ var box = document.getElementById('glossary-box');
55
+ handleEvent( document.body, 'click', function(){
56
+ box.style.display = 'none';
57
+ });
58
58
  });
@@ -1,14 +1,14 @@
1
- -# TODO: Breakdown by letter.
2
- %ul#index
3
- - global.index.entries.sort_by{ |k,p| k.downcase }.each do |keyword,pages|
4
- - if pages.length == 1
5
- %li
6
- %a{ :href => pages.first.html_path }= keyword
7
- - else
8
- %li
9
- = keyword
10
- %ul
11
- - pages.each do |page|
12
- %li
13
- %a{ :href => page.html_path }= page.title
14
-
1
+ -# TODO: Breakdown by letter.
2
+ %ul#index
3
+ - global.index.entries.sort_by{ |k,p| k.downcase }.each do |keyword,pages|
4
+ - if pages.length == 1
5
+ %li
6
+ %a{ :href => pages.first.html_path }= keyword
7
+ - else
8
+ %li
9
+ = keyword
10
+ %ul
11
+ - pages.each do |page|
12
+ %li
13
+ %a{ :href => page.html_path }= page.title
14
+
@@ -1,3 +1,3 @@
1
- %ul#toc
2
- - li_pages_for global.toc
1
+ %ul#toc
2
+ - li_pages_for global.toc
3
3
 
@@ -1,32 +1,32 @@
1
- !!! Strict
2
- %html
3
- %head
4
- %meta(http-equiv='Content-Type' content='text/html; charset=utf-8')
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
- - if custom_css
8
- %link{:rel=>'stylesheet', :type=>'text/css', :href=>"#{root}#{custom_css}", :media=>'all'}
9
- %script{:type=>'text/javascript', :src=>"#{root}glossary-terms.js"}
10
- %script{:type=>'text/javascript', :src=>"#{root}glossary.js"}
11
- - if custom_js
12
- %script{:type=>'text/javascript', :src=>"#{root}#{custom_js}"}
13
- %title= page.title
14
- %body{ :class=>page.style }
15
- #content
16
- #pagetop
17
- #breadcrumb
18
- = global.short_title || global.title
19
- %span.sep &gt;
20
- - breadcrumb.each do |node|
21
- %a{ :href=>root/node.link }= node.page.short_title || node.title
22
- %span.sep &gt;
23
- = page.title
24
- %h1#title= page.title
25
- - if page.author
26
- #author= page.author
27
- #pagebody
28
- #glossary-box
29
- #mainbody= contents
30
- #pagefooter
31
- Copyright ©#{Time.now.year}#{ " #{global.company}" if global.company }.
32
- All Rights Reserved.
1
+ !!! Strict
2
+ %html
3
+ %head
4
+ %meta(http-equiv='Content-Type' content='text/html; charset=utf-8')
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
+ - if custom_css
8
+ %link{:rel=>'stylesheet', :type=>'text/css', :href=>"#{root}#{custom_css}", :media=>'all'}
9
+ %script{:type=>'text/javascript', :src=>"#{root}glossary-terms.js"}
10
+ %script{:type=>'text/javascript', :src=>"#{root}glossary.js"}
11
+ - if custom_js
12
+ %script{:type=>'text/javascript', :src=>"#{root}#{custom_js}"}
13
+ %title= page.title
14
+ %body{ :class=>page.style }
15
+ #content
16
+ #pagetop
17
+ #breadcrumb
18
+ = global.short_title || global.title
19
+ %span.sep &gt;
20
+ - breadcrumb.each do |node|
21
+ %a{ :href=>root/node.link }= node.page.short_title || node.title
22
+ %span.sep &gt;
23
+ = page.title
24
+ %h1#title= page.title
25
+ - if page.author
26
+ #author= page.author
27
+ #pagebody
28
+ #glossary-box
29
+ #mainbody= contents
30
+ #pagefooter
31
+ Copyright ©#{Time.now.year}#{ " #{global.company}" if global.company }.
32
+ All Rights Reserved.
@@ -38,7 +38,7 @@ ICON = {
38
38
  %>
39
39
  <LI> <OBJECT type="text/sitemap">
40
40
  <param name="Name" value="<%=CGI.escapeHTML child.title%>">
41
- <param name="Local" value="<%=FileUtils.win_path( @html_path / child.link ).gsub('&','%26')%>">
41
+ <param name="Local" value="<%=FileUtils.win_path( @html_path / child.link ).gsub('&','&amp;')%>">
42
42
  <param name="ImageNumber" value="<%=icon%>">
43
43
  </OBJECT>
44
44
  <%@write_section[child] unless child.children.empty?%>
@@ -11,14 +11,14 @@
11
11
  <%@global.index.each do |entry,pages|%>
12
12
  <LI> <OBJECT type="text/sitemap">
13
13
  <param name="Name" value="<%=entry%>">
14
- <param name="Local" value="<%=FileUtils.win_path( @html_path/pages.first.html_path )%>">
14
+ <param name="Local" value="<%=FileUtils.win_path( @html_path/pages.first.html_path.gsub('&','&amp;') )%>">
15
15
  </OBJECT>
16
16
  <%unless pages.length==1%>
17
17
  <UL>
18
18
  <%pages.each do |page|%>
19
19
  <LI> <OBJECT type="text/sitemap">
20
20
  <param name="Name" value="<%=page.title%>">
21
- <param name="Local" value="<%=FileUtils.win_path( @html_path/page.html_path )%>">
21
+ <param name="Local" value="<%=FileUtils.win_path( @html_path/page.html_path.gsub('&','&amp;') )%>">
22
22
  </OBJECT>
23
23
  <%end%>
24
24
  </UL>
@@ -1,88 +1,88 @@
1
- class DocuBot::HTMLWriter < DocuBot::Writer
2
- handles_type :html
3
-
4
- # Specify nil for destination to place "<source>_html" next to the source.
5
- def write( destination=nil )
6
- start = Time.now
7
-
8
- source = @bundle.source
9
- @html_path = destination || File.dirname(source)/"#{File.basename source}_html"
10
- FileUtils.rm_rf(@html_path) if File.exists?(@html_path)
11
- FileUtils.mkdir(@html_path)
12
-
13
- master_templates = DocuBot::TEMPLATE_DIR
14
- source_templates = source/'_templates'
15
- master_root = master_templates/'_root'
16
- source_root = source_templates/'_root'
17
-
18
- # Copy any files found in the source directory that weren't made into pages
19
- @bundle.extras.each do |file|
20
- FileUtils.mkdir_p( @html_path / File.dirname( file ) )
21
- FileUtils.cp( source / file, @html_path / file )
22
- end
23
-
24
- # Copy files from template to root of destination
25
- # Record these as extras so that the CHMWriter can access them
26
- Dir.chdir @html_path do
27
- existing_files = Dir[ '*' ]
28
- FileUtils.copy( Dir[ master_templates/'_root'/'*' ], '.' )
29
- FileUtils.copy( Dir[ source_templates/'_root'/'*' ], '.' )
30
- new_files = Dir[ '*' ] - existing_files
31
- @bundle.extras.concat( new_files )
32
- end
33
-
34
- Dir.chdir @html_path do
35
- o = Object.new
36
-
37
- # Write out every page
38
- top = File.exists?( source_templates/'top.haml' ) ? source_templates/'top.haml' : master_templates/'top.haml'
39
- top = Haml::Engine.new( IO.read( top ), HAML_OPTIONS )
40
- @bundle.toc.descendants.each do |node|
41
- next if node.anchor
42
-
43
- contents = node.page.to_html
44
- template = node.page.template # Call page.to_html first to ensure page.template is set
45
-
46
- custom_js = "#{template}.js"
47
- custom_js = nil unless File.exists?( source_root/custom_js ) || File.exists?( master_root/custom_js )
48
-
49
- custom_css = "#{template}.css"
50
- custom_css = nil unless File.exists?( source_root/custom_css ) || File.exists?( master_root/custom_css )
51
-
52
- variables = {
53
- :page => node.page,
54
- :contents => contents,
55
- :global => @bundle.global,
56
- :root => node.page.root,
57
- :breadcrumb => node.ancestors,
58
- :custom_js => custom_js,
59
- :custom_css => custom_css
60
- }
61
- html = top.render( o, variables )
62
- FileUtils.mkdir_p( File.dirname( node.file ) )
63
- File.open( node.file, 'w' ){ |f| f << html }
64
- end
65
-
66
- File.open( 'glossary-terms.js', 'w' ){ |f| f << @bundle.glossary.to_js }
67
- end
68
-
69
- puts "...%.2fs to write the HTML" % (Time.now - start)
70
- end
71
- end
72
-
73
- module Haml::Helpers
74
- def li_pages_for( node )
75
- node.children.each do |child|
76
- haml_tag :li, :class=>(child.anchor ? 'sublink' : child.children.empty? ? 'section' : 'page' ) do
77
- haml_tag :a, :href=>child.link do
78
- haml_concat child.title
79
- end
80
- unless child.children.empty?
81
- haml_tag :ul do
82
- li_pages_for child
83
- end
84
- end
85
- end
86
- end
87
- end
1
+ class DocuBot::HTMLWriter < DocuBot::Writer
2
+ handles_type :html
3
+
4
+ # Specify nil for destination to place "<source>_html" next to the source.
5
+ def write( destination=nil )
6
+ start = Time.now
7
+
8
+ source = @bundle.source
9
+ @html_path = destination || File.dirname(source)/"#{File.basename source}_html"
10
+ FileUtils.rm_rf(@html_path) if File.exists?(@html_path)
11
+ FileUtils.mkdir(@html_path)
12
+
13
+ master_templates = DocuBot::TEMPLATE_DIR
14
+ source_templates = source/'_templates'
15
+ master_root = master_templates/'_root'
16
+ source_root = source_templates/'_root'
17
+
18
+ # Copy any files found in the source directory that weren't made into pages
19
+ @bundle.extras.each do |file|
20
+ FileUtils.mkdir_p( @html_path / File.dirname( file ) )
21
+ FileUtils.cp( source / file, @html_path / file )
22
+ end
23
+
24
+ # Copy files from template to root of destination
25
+ # Record these as extras so that the CHMWriter can access them
26
+ Dir.chdir @html_path do
27
+ existing_files = Dir[ '*' ]
28
+ FileUtils.copy( Dir[ master_templates/'_root'/'*' ], '.' )
29
+ FileUtils.copy( Dir[ source_templates/'_root'/'*' ], '.' )
30
+ new_files = Dir[ '*' ] - existing_files
31
+ @bundle.extras.concat( new_files )
32
+ end
33
+
34
+ Dir.chdir @html_path do
35
+ o = Object.new
36
+
37
+ # Write out every page
38
+ top = File.exists?( source_templates/'top.haml' ) ? source_templates/'top.haml' : master_templates/'top.haml'
39
+ top = Haml::Engine.new( IO.read( top ), HAML_OPTIONS )
40
+ @bundle.toc.descendants.each do |node|
41
+ next if node.anchor
42
+
43
+ contents = node.page.to_html
44
+ template = node.page.template # Call page.to_html first to ensure page.template is set
45
+
46
+ custom_js = "#{template}.js"
47
+ custom_js = nil unless File.exists?( source_root/custom_js ) || File.exists?( master_root/custom_js )
48
+
49
+ custom_css = "#{template}.css"
50
+ custom_css = nil unless File.exists?( source_root/custom_css ) || File.exists?( master_root/custom_css )
51
+
52
+ variables = {
53
+ :page => node.page,
54
+ :contents => contents,
55
+ :global => @bundle.global,
56
+ :root => node.page.root,
57
+ :breadcrumb => node.ancestors,
58
+ :custom_js => custom_js,
59
+ :custom_css => custom_css
60
+ }
61
+ html = top.render( o, variables )
62
+ FileUtils.mkdir_p( File.dirname( node.file ) )
63
+ File.open( node.file, 'w' ){ |f| f << html }
64
+ end
65
+
66
+ File.open( 'glossary-terms.js', 'w' ){ |f| f << @bundle.glossary.to_js }
67
+ end
68
+
69
+ puts "...%.2fs to write the HTML" % (Time.now - start)
70
+ end
71
+ end
72
+
73
+ module Haml::Helpers
74
+ def li_pages_for( node )
75
+ node.children.each do |child|
76
+ haml_tag :li, :class=>(child.anchor ? 'sublink' : child.children.empty? ? 'section' : 'page' ) do
77
+ haml_tag :a, :href=>child.link do
78
+ haml_concat child.title
79
+ end
80
+ unless child.children.empty?
81
+ haml_tag :ul do
82
+ li_pages_for child
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
88
  end