Bayeux 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.hgrc +2 -0
- data/.rvmrc +27 -0
- data/Gemfile +42 -0
- data/Gemfile.lock +42 -0
- data/HISTORY +63 -0
- data/README.rdoc +19 -0
- data/Rakefile +89 -0
- data/VERSION +1 -0
- data/bib/Modules.bib +21 -0
- data/code/render/latex/active4d.render +132 -0
- data/code/render/latex/all_hallows_eve.render +96 -0
- data/code/render/latex/amy.render +171 -0
- data/code/render/latex/blackboard.render +111 -0
- data/code/render/latex/brilliance_black.render +552 -0
- data/code/render/latex/brilliance_dull.render +561 -0
- data/code/render/latex/cobalt.render +162 -0
- data/code/render/latex/dawn.render +126 -0
- data/code/render/latex/eiffel.render +132 -0
- data/code/render/latex/espresso_libre.render +123 -0
- data/code/render/latex/idle.render +93 -0
- data/code/render/latex/iplastic.render +99 -0
- data/code/render/latex/lazy.render +96 -0
- data/code/render/latex/mac_classic.render +135 -0
- data/code/render/latex/magicwb_amiga.render +117 -0
- data/code/render/latex/pastels_on_dark.render +204 -0
- data/code/render/latex/slush_poppies.render +123 -0
- data/code/render/latex/spacecadet.render +81 -0
- data/code/render/latex/sunburst.render +186 -0
- data/code/render/latex/twilight.render +153 -0
- data/code/render/latex/zenburnesque.render +126 -0
- data/code/render/old/txt2tags.render +131 -0
- data/code/render/xhtml/active4d.render +140 -0
- data/code/render/xhtml/all_hallows_eve.render +104 -0
- data/code/render/xhtml/amy.render +179 -0
- data/code/render/xhtml/blackboard.render +119 -0
- data/code/render/xhtml/brilliance_black.render +560 -0
- data/code/render/xhtml/brilliance_dull.render +569 -0
- data/code/render/xhtml/cobalt.render +170 -0
- data/code/render/xhtml/dawn.render +134 -0
- data/code/render/xhtml/eiffel.render +140 -0
- data/code/render/xhtml/espresso_libre.render +131 -0
- data/code/render/xhtml/files/css/active4d.css +114 -0
- data/code/render/xhtml/files/css/all_hallows_eve.css +72 -0
- data/code/render/xhtml/files/css/amy.css +147 -0
- data/code/render/xhtml/files/css/blackboard.css +88 -0
- data/code/render/xhtml/files/css/brilliance_black.css +605 -0
- data/code/render/xhtml/files/css/brilliance_dull.css +599 -0
- data/code/render/xhtml/files/css/cobalt.css +149 -0
- data/code/render/xhtml/files/css/dawn.css +121 -0
- data/code/render/xhtml/files/css/eiffel.css +121 -0
- data/code/render/xhtml/files/css/espresso_libre.css +109 -0
- data/code/render/xhtml/files/css/idle.css +62 -0
- data/code/render/xhtml/files/css/iplastic.css +80 -0
- data/code/render/xhtml/files/css/lazy.css +73 -0
- data/code/render/xhtml/files/css/mac_classic.css +123 -0
- data/code/render/xhtml/files/css/magicwb_amiga.css +104 -0
- data/code/render/xhtml/files/css/pastels_on_dark.css +188 -0
- data/code/render/xhtml/files/css/slush_poppies.css +85 -0
- data/code/render/xhtml/files/css/spacecadet.css +51 -0
- data/code/render/xhtml/files/css/sunburst.css +180 -0
- data/code/render/xhtml/files/css/twilight.css +137 -0
- data/code/render/xhtml/files/css/zenburnesque.css +91 -0
- data/code/render/xhtml/idle.render +101 -0
- data/code/render/xhtml/iplastic.render +107 -0
- data/code/render/xhtml/lazy.render +104 -0
- data/code/render/xhtml/mac_classic.render +143 -0
- data/code/render/xhtml/magicwb_amiga.render +125 -0
- data/code/render/xhtml/pastels_on_dark.render +212 -0
- data/code/render/xhtml/slush_poppies.render +131 -0
- data/code/render/xhtml/spacecadet.render +89 -0
- data/code/render/xhtml/sunburst.render +194 -0
- data/code/render/xhtml/twilight.render +161 -0
- data/code/render/xhtml/zenburnesque.render +134 -0
- data/code/syntax/actionscript.syntax +97 -0
- data/code/syntax/active4d.syntax +276 -0
- data/code/syntax/active4d_html.syntax +311 -0
- data/code/syntax/active4d_ini.syntax +50 -0
- data/code/syntax/active4d_library.syntax +21 -0
- data/code/syntax/ada.syntax +33 -0
- data/code/syntax/antlr.syntax +151 -0
- data/code/syntax/apache.syntax +191 -0
- data/code/syntax/applescript.syntax +384 -0
- data/code/syntax/asp.syntax +70 -0
- data/code/syntax/asp_vb.net.syntax +129 -0
- data/code/syntax/bibtex.syntax +151 -0
- data/code/syntax/blog_html.syntax +41 -0
- data/code/syntax/blog_markdown.syntax +42 -0
- data/code/syntax/blog_text.syntax +27 -0
- data/code/syntax/blog_textile.syntax +27 -0
- data/code/syntax/build.syntax +53 -0
- data/code/syntax/bulletin_board.syntax +287 -0
- data/code/syntax/cake.syntax +55 -0
- data/code/syntax/camlp4.syntax +36 -0
- data/code/syntax/cm.syntax +32 -0
- data/code/syntax/coldfusion.syntax +119 -0
- data/code/syntax/context_free.syntax +176 -0
- data/code/syntax/cs.syntax +59 -0
- data/code/syntax/css.syntax +195 -0
- data/code/syntax/css_experimental.syntax +1925 -0
- data/code/syntax/csv.syntax +68 -0
- data/code/syntax/d.syntax +142 -0
- data/code/syntax/diff.syntax +81 -0
- data/code/syntax/dokuwiki.syntax +204 -0
- data/code/syntax/dot.syntax +47 -0
- data/code/syntax/doxygen.syntax +43 -0
- data/code/syntax/dylan.syntax +62 -0
- data/code/syntax/eiffel.syntax +78 -0
- data/code/syntax/erlang.syntax +922 -0
- data/code/syntax/f-script.syntax +80 -0
- data/code/syntax/fortran.syntax +141 -0
- data/code/syntax/fxscript.syntax +142 -0
- data/code/syntax/greasemonkey.syntax +34 -0
- data/code/syntax/gri.syntax +83 -0
- data/code/syntax/groovy.syntax +191 -0
- data/code/syntax/gtd.syntax +22 -0
- data/code/syntax/gtdalt.syntax +143 -0
- data/code/syntax/haml.syntax +88 -0
- data/code/syntax/haskell.syntax +88 -0
- data/code/syntax/html-asp.syntax +27 -0
- data/code/syntax/html.syntax +362 -0
- data/code/syntax/html_django.syntax +36 -0
- data/code/syntax/html_for_asp.net.syntax +424 -0
- data/code/syntax/html_mason.syntax +119 -0
- data/code/syntax/html_rails.syntax +40 -0
- data/code/syntax/html_tcl.syntax +26 -0
- data/code/syntax/icalendar.syntax +32 -0
- data/code/syntax/inform.syntax +48 -0
- data/code/syntax/ini.syntax +55 -0
- data/code/syntax/installer_distribution_script.syntax +77 -0
- data/code/syntax/io.syntax +81 -0
- data/code/syntax/java.syntax +211 -0
- data/code/syntax/javaproperties.syntax +20 -0
- data/code/syntax/javascript.syntax +256 -0
- data/code/syntax/javascript_+_prototype.syntax +72 -0
- data/code/syntax/javascript_+_prototype_bracketed.syntax +140 -0
- data/code/syntax/jquery_javascript.syntax +114 -0
- data/code/syntax/json.syntax +136 -0
- data/code/syntax/languagedefinition.syntax +708 -0
- data/code/syntax/latex.syntax +566 -0
- data/code/syntax/latex_beamer.syntax +41 -0
- data/code/syntax/latex_log.syntax +50 -0
- data/code/syntax/latex_memoir.syntax +64 -0
- data/code/syntax/lexflex.syntax +219 -0
- data/code/syntax/lighttpd.syntax +54 -0
- data/code/syntax/lilypond.syntax +492 -0
- data/code/syntax/lisp.syntax +61 -0
- data/code/syntax/literate_haskell.syntax +24 -0
- data/code/syntax/logo.syntax +29 -0
- data/code/syntax/logtalk.syntax +152 -0
- data/code/syntax/lua.syntax +86 -0
- data/code/syntax/m.syntax +142 -0
- data/code/syntax/macports_portfile.syntax +163 -0
- data/code/syntax/makefile.syntax +36 -0
- data/code/syntax/man.syntax +17 -0
- data/code/syntax/mediawiki.syntax +567 -0
- data/code/syntax/mips.syntax +66 -0
- data/code/syntax/mod_perl.syntax +50 -0
- data/code/syntax/modula-3.syntax +47 -0
- data/code/syntax/moinmoin.syntax +189 -0
- data/code/syntax/mootools.syntax +572 -0
- data/code/syntax/movable_type.syntax +162 -0
- data/code/syntax/multimarkdown.syntax +39 -0
- data/code/syntax/objective-c++.syntax +18 -0
- data/code/syntax/objective-c.syntax +233 -0
- data/code/syntax/ocaml.syntax +764 -0
- data/code/syntax/ocamllex.syntax +167 -0
- data/code/syntax/ocamlyacc.syntax +184 -0
- data/code/syntax/opengl.syntax +14 -0
- data/code/syntax/pascal.syntax +77 -0
- data/code/syntax/perl.syntax +1115 -0
- data/code/syntax/plain_text.syntax +32 -0
- data/code/syntax/postscript.syntax +114 -0
- data/code/syntax/processing.syntax +106 -0
- data/code/syntax/prolog.syntax +40 -0
- data/code/syntax/property_list.syntax +635 -0
- data/code/syntax/python.syntax +868 -0
- data/code/syntax/python_django.syntax +21 -0
- data/code/syntax/qmake_project.syntax +114 -0
- data/code/syntax/qt_c++.syntax +26 -0
- data/code/syntax/quake3_config.syntax +32 -0
- data/code/syntax/r.syntax +81 -0
- data/code/syntax/r_console.syntax +16 -0
- data/code/syntax/ragel.syntax +201 -0
- data/code/syntax/rd_r_documentation.syntax +91 -0
- data/code/syntax/regexp.syntax +50 -0
- data/code/syntax/release_notes.syntax +46 -0
- data/code/syntax/remind.syntax +253 -0
- data/code/syntax/restructuredtext.syntax +250 -0
- data/code/syntax/rez.syntax +80 -0
- data/code/syntax/ruby.syntax +1035 -0
- data/code/syntax/ruby_experimental.syntax +145 -0
- data/code/syntax/ruby_on_rails.syntax +88 -0
- data/code/syntax/s5.syntax +69 -0
- data/code/syntax/scheme.syntax +347 -0
- data/code/syntax/scilab.syntax +41 -0
- data/code/syntax/setext.syntax +147 -0
- data/code/syntax/shell-unix-generic.syntax +384 -0
- data/code/syntax/slate.syntax +149 -0
- data/code/syntax/sql.syntax +237 -0
- data/code/syntax/sql_rails.syntax +18 -0
- data/code/syntax/ssh-config.syntax +33 -0
- data/code/syntax/standard_ml.syntax +121 -0
- data/code/syntax/strings_file.syntax +39 -0
- data/code/syntax/subversion_commit_message.syntax +36 -0
- data/code/syntax/sweave.syntax +84 -0
- data/code/syntax/swig.syntax +57 -0
- data/code/syntax/tcl.syntax +152 -0
- data/code/syntax/template_toolkit.syntax +121 -0
- data/code/syntax/tex.syntax +86 -0
- data/code/syntax/tex_math.syntax +49 -0
- data/code/syntax/textile.syntax +215 -0
- data/code/syntax/tsv.syntax +50 -0
- data/code/syntax/twiki.syntax +241 -0
- data/code/syntax/txt2tags.syntax +79 -0
- data/code/syntax/vectorscript.syntax +57 -0
- data/code/syntax/xhtml_1.0.syntax +4027 -0
- data/code/syntax/xml.syntax +180 -0
- data/code/syntax/xml_strict.syntax +92 -0
- data/code/syntax/xsl.syntax +60 -0
- data/code/syntax/yaml.syntax +160 -0
- data/code/syntax/yui_javascript.syntax +176 -0
- data/lib/bayeux/bayeux.rb +727 -0
- data/lib/bayeux/html_gen.rb +506 -0
- data/lib/bayeux/latex_gen.rb +333 -0
- data/lib/bayeux/para_block.rb +201 -0
- data/lib/bayeux/text_gen.rb +307 -0
- data/lib/bayeux/tree_walker.rb +166 -0
- data/lib/filters/bayeux.rb +44 -0
- data/lib/filters/pandoc.rb +23 -0
- data/lib/filters/section_id.rb +105 -0
- data/lib/helpers/breadcrumbs.rb +64 -0
- data/lib/helpers/site_toc.rb +11 -0
- data/lib/lib/uv.rb +92 -0
- data/lib/lib/uv/render_processor.rb +146 -0
- data/lib/lib/uv/utility.rb +67 -0
- data/lib/refs/Doc_Blocks.rb +2 -0
- data/lib/refs/References.rb +104 -0
- metadata +415 -0
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'facets'
|
2
|
+
|
3
|
+
class BayeuxTextGen
|
4
|
+
|
5
|
+
# Default Constructor
|
6
|
+
def initialize(syntax_tree)
|
7
|
+
@syntax_tree = syntax_tree
|
8
|
+
@text_string = String.new
|
9
|
+
@text = String.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Return the AST as an HTML string (stored in @text_string)
|
13
|
+
def generate
|
14
|
+
|
15
|
+
# Create a walker for the trees in the forest
|
16
|
+
walker = TreeWalker.new
|
17
|
+
|
18
|
+
walker.on_before_down = self.method(:generate_node_start)
|
19
|
+
walker.on_after_up = self.method(:generate_node_end)
|
20
|
+
|
21
|
+
walker.on_no_siblings = self.method(:generate_full_node)
|
22
|
+
walker.on_no_children = self.method(:generate_full_node)
|
23
|
+
|
24
|
+
# Clear the internal HTML representation
|
25
|
+
@text_string.clear
|
26
|
+
|
27
|
+
# Walk the forest
|
28
|
+
@syntax_tree.block_forest.each{|tree|
|
29
|
+
walker.walk_tree(tree)
|
30
|
+
}
|
31
|
+
|
32
|
+
return @text_string
|
33
|
+
end
|
34
|
+
|
35
|
+
###
|
36
|
+
### Walker Hooks. These are called by the tree walker on specific
|
37
|
+
### events
|
38
|
+
###
|
39
|
+
|
40
|
+
# Output the full contents of the node, properly bracketed as an
|
41
|
+
# HTML expression. This is only called if we have no sub-nodes to
|
42
|
+
# deal with
|
43
|
+
def generate_full_node(block)
|
44
|
+
|
45
|
+
# Check if we need to add a space
|
46
|
+
# Check if we need to add a space
|
47
|
+
if not block.content[0] =~ /\s[:;.,?!]/
|
48
|
+
@text_string << " "
|
49
|
+
end
|
50
|
+
|
51
|
+
case block.type
|
52
|
+
|
53
|
+
# Headers
|
54
|
+
when :h1, :h2, :h3, :h4, :h5, :h6
|
55
|
+
@text_string << "#{block.content.strip}\n"
|
56
|
+
|
57
|
+
# Ordinary paragraphs
|
58
|
+
when :paragraph
|
59
|
+
@text_string << "#{block.content.word_wrap(70)}\n\n"
|
60
|
+
|
61
|
+
when :none
|
62
|
+
@text_string << "#{block.content.word_wrap(70)}"
|
63
|
+
|
64
|
+
# Special paragraphs
|
65
|
+
when :block_quote
|
66
|
+
@text_string << "#{block.content.word_wrap(60).indent(5)}\n\n"
|
67
|
+
when :single_quote
|
68
|
+
@text_string << "\'#{block.content}\'"
|
69
|
+
when :double_quote
|
70
|
+
@text_string << "\"#{block.content}\""
|
71
|
+
|
72
|
+
when :note
|
73
|
+
@text_string << "Note: #{block.content}\n\n"
|
74
|
+
|
75
|
+
when :command
|
76
|
+
@text_string << "#{block.content.strip.indent(5)}\n\n"
|
77
|
+
|
78
|
+
when :code_language
|
79
|
+
@code_language = block.content
|
80
|
+
when :code_start_number
|
81
|
+
@code_start_number = block.content
|
82
|
+
|
83
|
+
when :file
|
84
|
+
@text_string << "#{block.content}\n\n"
|
85
|
+
when :output
|
86
|
+
70.downto(0){|index|
|
87
|
+
@text_string << "-"
|
88
|
+
}
|
89
|
+
@text_string << "\n#{block.content.strip}\n"
|
90
|
+
70.downto(0){|index|
|
91
|
+
@text_string << "-"
|
92
|
+
}
|
93
|
+
@text_string << "\n\n"
|
94
|
+
|
95
|
+
# Special Characters
|
96
|
+
when :em_dash
|
97
|
+
@text_string << " - "
|
98
|
+
when :en_dash
|
99
|
+
@text_string << "-"
|
100
|
+
when :elipses
|
101
|
+
@text_string << "..."
|
102
|
+
when :elipses_stop
|
103
|
+
@text_string << "...."
|
104
|
+
|
105
|
+
# Links
|
106
|
+
when :link_target
|
107
|
+
@link_target = block.content
|
108
|
+
when :link_text
|
109
|
+
@link_text = block.content
|
110
|
+
|
111
|
+
# Lists
|
112
|
+
when :item
|
113
|
+
@text_string << " * #{block.content}"
|
114
|
+
|
115
|
+
when :dl_header
|
116
|
+
@text_string << "#{block.content}: "
|
117
|
+
when :dl_text
|
118
|
+
@text_string << "#{block.content}"
|
119
|
+
|
120
|
+
# Tags
|
121
|
+
when :ac
|
122
|
+
# Do we know anything about this acronymn?
|
123
|
+
if $reference.acronym_list.include?(block.content) then
|
124
|
+
|
125
|
+
# Assemble from the reference list
|
126
|
+
if $reference.acronym_list[block.content].include?('text_text') then
|
127
|
+
acronym = $reference.acronym_list[block.content]['text_text']
|
128
|
+
else
|
129
|
+
acronym = $reference.acronym_list[block.content]['text']
|
130
|
+
end
|
131
|
+
|
132
|
+
definition = $reference.acronym_list[block.content]['def']
|
133
|
+
|
134
|
+
@text_string << "#{acronym}"
|
135
|
+
else
|
136
|
+
# Do what we can
|
137
|
+
@text_string << "#{block.content}"
|
138
|
+
end
|
139
|
+
|
140
|
+
when :emph
|
141
|
+
@text_string << "#{block.content}"
|
142
|
+
|
143
|
+
when :tt
|
144
|
+
@text_string << "#{block.content}"
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Output only the start of a node
|
150
|
+
def generate_node_start(block)
|
151
|
+
|
152
|
+
# Check if we need to add a space
|
153
|
+
if not block.content[0] =~ /\s[:;.,?!]/
|
154
|
+
@text << " "
|
155
|
+
end
|
156
|
+
|
157
|
+
case block.type
|
158
|
+
|
159
|
+
# Headers
|
160
|
+
when :h1, :h2, :h3, :h4, :h5, :h6
|
161
|
+
@text_string << "#{block.content.strip}"
|
162
|
+
|
163
|
+
# Ordinary paragraphs
|
164
|
+
when :paragraph
|
165
|
+
@text << "#{block.content}"
|
166
|
+
|
167
|
+
when :none
|
168
|
+
@text << "#{block.content}"
|
169
|
+
|
170
|
+
# Special paragraphs
|
171
|
+
when :block_quote
|
172
|
+
@text << "#{block.content}"
|
173
|
+
when :single_quote
|
174
|
+
@text << "'#{block.content}"
|
175
|
+
when :double_quote
|
176
|
+
@text << "\"#{block.content}"
|
177
|
+
|
178
|
+
when :note
|
179
|
+
@text << "Note: #{block.content}"
|
180
|
+
|
181
|
+
when :command
|
182
|
+
@text_string << "#{block.content.lstrip.indent(5)}\n"
|
183
|
+
|
184
|
+
when :code_language
|
185
|
+
@code_language = block.content
|
186
|
+
when :code_start_number
|
187
|
+
@code_start_number = block.content
|
188
|
+
|
189
|
+
# Special Characters
|
190
|
+
when :em_dash
|
191
|
+
@text << " - "
|
192
|
+
when :en_dash
|
193
|
+
@text << "-"
|
194
|
+
when :elipses
|
195
|
+
@text << "..."
|
196
|
+
when :elipses_stop
|
197
|
+
@text << "...."
|
198
|
+
|
199
|
+
# Links
|
200
|
+
when :link_target
|
201
|
+
@link_target = block.content
|
202
|
+
when :link_text
|
203
|
+
@link_text = block.content
|
204
|
+
|
205
|
+
# Lists
|
206
|
+
when :item
|
207
|
+
@text << " * #{block.content}"
|
208
|
+
|
209
|
+
when :dl_header
|
210
|
+
@text << "#{block.content}: "
|
211
|
+
when :dl_text
|
212
|
+
@text << "#{block.content}"
|
213
|
+
|
214
|
+
# Tags
|
215
|
+
when :ac
|
216
|
+
# Do we know anything about this acronymn?
|
217
|
+
if $reference.acronym_list.include?(block.content) then
|
218
|
+
|
219
|
+
# Assemble from the reference list
|
220
|
+
if $reference.acronym_list[block.content].include?('text_text') then
|
221
|
+
acronym = $reference.acronym_list[block.content]['text_text']
|
222
|
+
else
|
223
|
+
acronym = $reference.acronym_list[block.content]['text']
|
224
|
+
end
|
225
|
+
|
226
|
+
definition = $reference.acronym_list[block.content]['def']
|
227
|
+
|
228
|
+
@text_string << "#{acronym}"
|
229
|
+
else
|
230
|
+
# Do what we can
|
231
|
+
@text_string << "#{block.content}"
|
232
|
+
end
|
233
|
+
|
234
|
+
when :emph
|
235
|
+
@text << "#{block.content}"
|
236
|
+
|
237
|
+
when :tt
|
238
|
+
@text << "#{block.content}"
|
239
|
+
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def generate_node_end(block)
|
244
|
+
|
245
|
+
case block.type
|
246
|
+
|
247
|
+
# Headers
|
248
|
+
when :h1, :h2, :h3, :h4, :h5, :h6
|
249
|
+
@text_string << @text.word_wrap(70)
|
250
|
+
@text = ""
|
251
|
+
|
252
|
+
# Ordinary paragraphs
|
253
|
+
when :paragraph
|
254
|
+
@text_string << @text.indent(2).word_wrap(70) + "\n"
|
255
|
+
@text = ""
|
256
|
+
|
257
|
+
# Special paragraphs
|
258
|
+
when :block_quote
|
259
|
+
@text_string << @text.indent(5).word_wrap(60) + "\n"
|
260
|
+
@text = ""
|
261
|
+
when :single_quote
|
262
|
+
@text_string << "'"
|
263
|
+
when :double_quote
|
264
|
+
@text_string << "\""
|
265
|
+
|
266
|
+
when :note
|
267
|
+
@text_string << @text.indent(2).word_wrap(70) + "\n"
|
268
|
+
@text = ""
|
269
|
+
|
270
|
+
# Special Characters
|
271
|
+
when :em_dash
|
272
|
+
@text << " - "
|
273
|
+
when :en_dash
|
274
|
+
@text << "-"
|
275
|
+
when :elipses
|
276
|
+
@text << "..."
|
277
|
+
when :elipses_stop
|
278
|
+
@text << "...."
|
279
|
+
|
280
|
+
# Links
|
281
|
+
when :link
|
282
|
+
# Assemble the link from the sub-tree nodes
|
283
|
+
@text << "#{@link_text}"
|
284
|
+
when :link_target
|
285
|
+
@link_target = block.content
|
286
|
+
when :link_text
|
287
|
+
@link_text = block.content
|
288
|
+
|
289
|
+
# Lists
|
290
|
+
when :item
|
291
|
+
@text_string << @text.indent(2).word_wrap(70) + "\n"
|
292
|
+
@text = ""
|
293
|
+
|
294
|
+
when :dl
|
295
|
+
@text_string << "\n"
|
296
|
+
@text = ""
|
297
|
+
when :dl_text
|
298
|
+
@text_string << @text.indent(2).word_wrap(70) + "\n"
|
299
|
+
@text = ""
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
###
|
304
|
+
### Helper functions
|
305
|
+
###
|
306
|
+
|
307
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
####
|
2
|
+
#### Defines a stack based tree walker, used by the Bayeux generators
|
3
|
+
####
|
4
|
+
####
|
5
|
+
|
6
|
+
class TreeWalker
|
7
|
+
|
8
|
+
###
|
9
|
+
### Accessors
|
10
|
+
###
|
11
|
+
|
12
|
+
attr_accessor :on_before_down, :on_after_down, :on_before_sideways, :on_after_sideways, :on_before_up, :on_after_up, :on_no_siblings, :on_no_children
|
13
|
+
|
14
|
+
###
|
15
|
+
### Class Methods
|
16
|
+
###
|
17
|
+
|
18
|
+
def walk_tree(tree_root)
|
19
|
+
|
20
|
+
# Start walking from the tree root
|
21
|
+
current_node = tree_root
|
22
|
+
|
23
|
+
# Stack of node to visit
|
24
|
+
visit_list = Array.new
|
25
|
+
|
26
|
+
# Points to the last 'virtual vist' we have mode. We
|
27
|
+
# Need to complete this path at the end of our vists
|
28
|
+
last_virtual = nil
|
29
|
+
|
30
|
+
# Dump the vist list
|
31
|
+
dump_visit_list = -> {
|
32
|
+
dump_str = ""
|
33
|
+
visit_list.each{|node|
|
34
|
+
unless node.nil? then
|
35
|
+
dump_str << node.name.to_s + ","
|
36
|
+
else
|
37
|
+
dump_str << "nil,"
|
38
|
+
end
|
39
|
+
}
|
40
|
+
puts "visit list contents: #{dump_str}"
|
41
|
+
}
|
42
|
+
|
43
|
+
# Do the 'virtual visits'. That is, keep moving up
|
44
|
+
# the tree, visiting the parents at each nil, until
|
45
|
+
# we manage to find something useful
|
46
|
+
do_virtual_visits = -> {
|
47
|
+
next_virtual = current_node
|
48
|
+
next_node = nil
|
49
|
+
|
50
|
+
# Keep removing nil, moving up the parent list
|
51
|
+
# until we find something worth keeping
|
52
|
+
until ((not next_node.nil?) or visit_list.empty?) do
|
53
|
+
next_node = visit_list.pop
|
54
|
+
next_virtual = next_virtual.parent
|
55
|
+
|
56
|
+
if next_node.nil? then
|
57
|
+
unless next_virtual.nil? then
|
58
|
+
#puts "^^^ v_visiting: #{next_virtual.name} from #{current_node.name} as #{next_virtual.content.to_debug_s}"
|
59
|
+
unless @on_after_up.nil? then
|
60
|
+
unless next_virtual.nil? then
|
61
|
+
@on_after_up.call(next_virtual.content)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
#puts "^^^ nil visit"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
current_node = next_node
|
71
|
+
}
|
72
|
+
|
73
|
+
# Start walking
|
74
|
+
until current_node.nil? do
|
75
|
+
#unless current_node.nil? then
|
76
|
+
# puts "^^^ visiting: #{current_node.name} as #{current_node.content.to_debug_s}"
|
77
|
+
# dump_visit_list.call
|
78
|
+
#end
|
79
|
+
|
80
|
+
# Do we have any children?
|
81
|
+
if current_node.has_children? then
|
82
|
+
|
83
|
+
unless @on_before_down.nil? then
|
84
|
+
unless current_node.nil? then
|
85
|
+
@on_before_down.call(current_node.content)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Add the children visit list
|
90
|
+
child_list = current_node.children
|
91
|
+
unless child_list.nil? then
|
92
|
+
visit_list.push(nil)
|
93
|
+
visit_list.concat(child_list.reverse)
|
94
|
+
end
|
95
|
+
|
96
|
+
#puts " adding children"
|
97
|
+
#dump_visit_list.call
|
98
|
+
current_node = visit_list.pop
|
99
|
+
|
100
|
+
unless @on_after_down.nil? then
|
101
|
+
unless current_node.nil? then
|
102
|
+
@on_after_down.call(current_node.content)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
else
|
107
|
+
|
108
|
+
# Tell the caller we have no children
|
109
|
+
unless @on_no_children.nil? then
|
110
|
+
unless current_node.nil? then
|
111
|
+
@on_no_children.call(current_node.content)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# We can't go down, but can we go sideways?
|
116
|
+
unless visit_list.last.nil? then
|
117
|
+
|
118
|
+
unless @on_before_sideways.nil? then
|
119
|
+
unless current_node.nil? then
|
120
|
+
@on_before_sideways.call(current_node.content)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
current_node = visit_list.pop
|
125
|
+
|
126
|
+
unless @on_after_sideways.nil? then
|
127
|
+
unless current_node.nil? then
|
128
|
+
@on_after_sideways.call(current_node.content)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
else
|
133
|
+
|
134
|
+
# We can't go sideways, or down, so we will go up
|
135
|
+
|
136
|
+
unless @on_before_up.nil? then
|
137
|
+
unless current_node.nil? then
|
138
|
+
@on_before_up.call(current_node.content)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Do the virtual visits to the parents of this node,
|
143
|
+
# ready to move onto the next set of siblings
|
144
|
+
do_virtual_visits.call
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
# Finish the walk by going all the way back to the parent
|
153
|
+
current_node = last_virtual
|
154
|
+
until current_node == tree_root or current_node.nil? do
|
155
|
+
current_node = current_node.parent
|
156
|
+
|
157
|
+
unless @on_after_up.nil? then
|
158
|
+
unless current_node.nil? then
|
159
|
+
@on_after_up.call(current_node.content)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|