Bayeux 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/.hgrc +2 -0
  2. data/.rvmrc +27 -0
  3. data/Gemfile +42 -0
  4. data/Gemfile.lock +42 -0
  5. data/HISTORY +63 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +89 -0
  8. data/VERSION +1 -0
  9. data/bib/Modules.bib +21 -0
  10. data/code/render/latex/active4d.render +132 -0
  11. data/code/render/latex/all_hallows_eve.render +96 -0
  12. data/code/render/latex/amy.render +171 -0
  13. data/code/render/latex/blackboard.render +111 -0
  14. data/code/render/latex/brilliance_black.render +552 -0
  15. data/code/render/latex/brilliance_dull.render +561 -0
  16. data/code/render/latex/cobalt.render +162 -0
  17. data/code/render/latex/dawn.render +126 -0
  18. data/code/render/latex/eiffel.render +132 -0
  19. data/code/render/latex/espresso_libre.render +123 -0
  20. data/code/render/latex/idle.render +93 -0
  21. data/code/render/latex/iplastic.render +99 -0
  22. data/code/render/latex/lazy.render +96 -0
  23. data/code/render/latex/mac_classic.render +135 -0
  24. data/code/render/latex/magicwb_amiga.render +117 -0
  25. data/code/render/latex/pastels_on_dark.render +204 -0
  26. data/code/render/latex/slush_poppies.render +123 -0
  27. data/code/render/latex/spacecadet.render +81 -0
  28. data/code/render/latex/sunburst.render +186 -0
  29. data/code/render/latex/twilight.render +153 -0
  30. data/code/render/latex/zenburnesque.render +126 -0
  31. data/code/render/old/txt2tags.render +131 -0
  32. data/code/render/xhtml/active4d.render +140 -0
  33. data/code/render/xhtml/all_hallows_eve.render +104 -0
  34. data/code/render/xhtml/amy.render +179 -0
  35. data/code/render/xhtml/blackboard.render +119 -0
  36. data/code/render/xhtml/brilliance_black.render +560 -0
  37. data/code/render/xhtml/brilliance_dull.render +569 -0
  38. data/code/render/xhtml/cobalt.render +170 -0
  39. data/code/render/xhtml/dawn.render +134 -0
  40. data/code/render/xhtml/eiffel.render +140 -0
  41. data/code/render/xhtml/espresso_libre.render +131 -0
  42. data/code/render/xhtml/files/css/active4d.css +114 -0
  43. data/code/render/xhtml/files/css/all_hallows_eve.css +72 -0
  44. data/code/render/xhtml/files/css/amy.css +147 -0
  45. data/code/render/xhtml/files/css/blackboard.css +88 -0
  46. data/code/render/xhtml/files/css/brilliance_black.css +605 -0
  47. data/code/render/xhtml/files/css/brilliance_dull.css +599 -0
  48. data/code/render/xhtml/files/css/cobalt.css +149 -0
  49. data/code/render/xhtml/files/css/dawn.css +121 -0
  50. data/code/render/xhtml/files/css/eiffel.css +121 -0
  51. data/code/render/xhtml/files/css/espresso_libre.css +109 -0
  52. data/code/render/xhtml/files/css/idle.css +62 -0
  53. data/code/render/xhtml/files/css/iplastic.css +80 -0
  54. data/code/render/xhtml/files/css/lazy.css +73 -0
  55. data/code/render/xhtml/files/css/mac_classic.css +123 -0
  56. data/code/render/xhtml/files/css/magicwb_amiga.css +104 -0
  57. data/code/render/xhtml/files/css/pastels_on_dark.css +188 -0
  58. data/code/render/xhtml/files/css/slush_poppies.css +85 -0
  59. data/code/render/xhtml/files/css/spacecadet.css +51 -0
  60. data/code/render/xhtml/files/css/sunburst.css +180 -0
  61. data/code/render/xhtml/files/css/twilight.css +137 -0
  62. data/code/render/xhtml/files/css/zenburnesque.css +91 -0
  63. data/code/render/xhtml/idle.render +101 -0
  64. data/code/render/xhtml/iplastic.render +107 -0
  65. data/code/render/xhtml/lazy.render +104 -0
  66. data/code/render/xhtml/mac_classic.render +143 -0
  67. data/code/render/xhtml/magicwb_amiga.render +125 -0
  68. data/code/render/xhtml/pastels_on_dark.render +212 -0
  69. data/code/render/xhtml/slush_poppies.render +131 -0
  70. data/code/render/xhtml/spacecadet.render +89 -0
  71. data/code/render/xhtml/sunburst.render +194 -0
  72. data/code/render/xhtml/twilight.render +161 -0
  73. data/code/render/xhtml/zenburnesque.render +134 -0
  74. data/code/syntax/actionscript.syntax +97 -0
  75. data/code/syntax/active4d.syntax +276 -0
  76. data/code/syntax/active4d_html.syntax +311 -0
  77. data/code/syntax/active4d_ini.syntax +50 -0
  78. data/code/syntax/active4d_library.syntax +21 -0
  79. data/code/syntax/ada.syntax +33 -0
  80. data/code/syntax/antlr.syntax +151 -0
  81. data/code/syntax/apache.syntax +191 -0
  82. data/code/syntax/applescript.syntax +384 -0
  83. data/code/syntax/asp.syntax +70 -0
  84. data/code/syntax/asp_vb.net.syntax +129 -0
  85. data/code/syntax/bibtex.syntax +151 -0
  86. data/code/syntax/blog_html.syntax +41 -0
  87. data/code/syntax/blog_markdown.syntax +42 -0
  88. data/code/syntax/blog_text.syntax +27 -0
  89. data/code/syntax/blog_textile.syntax +27 -0
  90. data/code/syntax/build.syntax +53 -0
  91. data/code/syntax/bulletin_board.syntax +287 -0
  92. data/code/syntax/cake.syntax +55 -0
  93. data/code/syntax/camlp4.syntax +36 -0
  94. data/code/syntax/cm.syntax +32 -0
  95. data/code/syntax/coldfusion.syntax +119 -0
  96. data/code/syntax/context_free.syntax +176 -0
  97. data/code/syntax/cs.syntax +59 -0
  98. data/code/syntax/css.syntax +195 -0
  99. data/code/syntax/css_experimental.syntax +1925 -0
  100. data/code/syntax/csv.syntax +68 -0
  101. data/code/syntax/d.syntax +142 -0
  102. data/code/syntax/diff.syntax +81 -0
  103. data/code/syntax/dokuwiki.syntax +204 -0
  104. data/code/syntax/dot.syntax +47 -0
  105. data/code/syntax/doxygen.syntax +43 -0
  106. data/code/syntax/dylan.syntax +62 -0
  107. data/code/syntax/eiffel.syntax +78 -0
  108. data/code/syntax/erlang.syntax +922 -0
  109. data/code/syntax/f-script.syntax +80 -0
  110. data/code/syntax/fortran.syntax +141 -0
  111. data/code/syntax/fxscript.syntax +142 -0
  112. data/code/syntax/greasemonkey.syntax +34 -0
  113. data/code/syntax/gri.syntax +83 -0
  114. data/code/syntax/groovy.syntax +191 -0
  115. data/code/syntax/gtd.syntax +22 -0
  116. data/code/syntax/gtdalt.syntax +143 -0
  117. data/code/syntax/haml.syntax +88 -0
  118. data/code/syntax/haskell.syntax +88 -0
  119. data/code/syntax/html-asp.syntax +27 -0
  120. data/code/syntax/html.syntax +362 -0
  121. data/code/syntax/html_django.syntax +36 -0
  122. data/code/syntax/html_for_asp.net.syntax +424 -0
  123. data/code/syntax/html_mason.syntax +119 -0
  124. data/code/syntax/html_rails.syntax +40 -0
  125. data/code/syntax/html_tcl.syntax +26 -0
  126. data/code/syntax/icalendar.syntax +32 -0
  127. data/code/syntax/inform.syntax +48 -0
  128. data/code/syntax/ini.syntax +55 -0
  129. data/code/syntax/installer_distribution_script.syntax +77 -0
  130. data/code/syntax/io.syntax +81 -0
  131. data/code/syntax/java.syntax +211 -0
  132. data/code/syntax/javaproperties.syntax +20 -0
  133. data/code/syntax/javascript.syntax +256 -0
  134. data/code/syntax/javascript_+_prototype.syntax +72 -0
  135. data/code/syntax/javascript_+_prototype_bracketed.syntax +140 -0
  136. data/code/syntax/jquery_javascript.syntax +114 -0
  137. data/code/syntax/json.syntax +136 -0
  138. data/code/syntax/languagedefinition.syntax +708 -0
  139. data/code/syntax/latex.syntax +566 -0
  140. data/code/syntax/latex_beamer.syntax +41 -0
  141. data/code/syntax/latex_log.syntax +50 -0
  142. data/code/syntax/latex_memoir.syntax +64 -0
  143. data/code/syntax/lexflex.syntax +219 -0
  144. data/code/syntax/lighttpd.syntax +54 -0
  145. data/code/syntax/lilypond.syntax +492 -0
  146. data/code/syntax/lisp.syntax +61 -0
  147. data/code/syntax/literate_haskell.syntax +24 -0
  148. data/code/syntax/logo.syntax +29 -0
  149. data/code/syntax/logtalk.syntax +152 -0
  150. data/code/syntax/lua.syntax +86 -0
  151. data/code/syntax/m.syntax +142 -0
  152. data/code/syntax/macports_portfile.syntax +163 -0
  153. data/code/syntax/makefile.syntax +36 -0
  154. data/code/syntax/man.syntax +17 -0
  155. data/code/syntax/mediawiki.syntax +567 -0
  156. data/code/syntax/mips.syntax +66 -0
  157. data/code/syntax/mod_perl.syntax +50 -0
  158. data/code/syntax/modula-3.syntax +47 -0
  159. data/code/syntax/moinmoin.syntax +189 -0
  160. data/code/syntax/mootools.syntax +572 -0
  161. data/code/syntax/movable_type.syntax +162 -0
  162. data/code/syntax/multimarkdown.syntax +39 -0
  163. data/code/syntax/objective-c++.syntax +18 -0
  164. data/code/syntax/objective-c.syntax +233 -0
  165. data/code/syntax/ocaml.syntax +764 -0
  166. data/code/syntax/ocamllex.syntax +167 -0
  167. data/code/syntax/ocamlyacc.syntax +184 -0
  168. data/code/syntax/opengl.syntax +14 -0
  169. data/code/syntax/pascal.syntax +77 -0
  170. data/code/syntax/perl.syntax +1115 -0
  171. data/code/syntax/plain_text.syntax +32 -0
  172. data/code/syntax/postscript.syntax +114 -0
  173. data/code/syntax/processing.syntax +106 -0
  174. data/code/syntax/prolog.syntax +40 -0
  175. data/code/syntax/property_list.syntax +635 -0
  176. data/code/syntax/python.syntax +868 -0
  177. data/code/syntax/python_django.syntax +21 -0
  178. data/code/syntax/qmake_project.syntax +114 -0
  179. data/code/syntax/qt_c++.syntax +26 -0
  180. data/code/syntax/quake3_config.syntax +32 -0
  181. data/code/syntax/r.syntax +81 -0
  182. data/code/syntax/r_console.syntax +16 -0
  183. data/code/syntax/ragel.syntax +201 -0
  184. data/code/syntax/rd_r_documentation.syntax +91 -0
  185. data/code/syntax/regexp.syntax +50 -0
  186. data/code/syntax/release_notes.syntax +46 -0
  187. data/code/syntax/remind.syntax +253 -0
  188. data/code/syntax/restructuredtext.syntax +250 -0
  189. data/code/syntax/rez.syntax +80 -0
  190. data/code/syntax/ruby.syntax +1035 -0
  191. data/code/syntax/ruby_experimental.syntax +145 -0
  192. data/code/syntax/ruby_on_rails.syntax +88 -0
  193. data/code/syntax/s5.syntax +69 -0
  194. data/code/syntax/scheme.syntax +347 -0
  195. data/code/syntax/scilab.syntax +41 -0
  196. data/code/syntax/setext.syntax +147 -0
  197. data/code/syntax/shell-unix-generic.syntax +384 -0
  198. data/code/syntax/slate.syntax +149 -0
  199. data/code/syntax/sql.syntax +237 -0
  200. data/code/syntax/sql_rails.syntax +18 -0
  201. data/code/syntax/ssh-config.syntax +33 -0
  202. data/code/syntax/standard_ml.syntax +121 -0
  203. data/code/syntax/strings_file.syntax +39 -0
  204. data/code/syntax/subversion_commit_message.syntax +36 -0
  205. data/code/syntax/sweave.syntax +84 -0
  206. data/code/syntax/swig.syntax +57 -0
  207. data/code/syntax/tcl.syntax +152 -0
  208. data/code/syntax/template_toolkit.syntax +121 -0
  209. data/code/syntax/tex.syntax +86 -0
  210. data/code/syntax/tex_math.syntax +49 -0
  211. data/code/syntax/textile.syntax +215 -0
  212. data/code/syntax/tsv.syntax +50 -0
  213. data/code/syntax/twiki.syntax +241 -0
  214. data/code/syntax/txt2tags.syntax +79 -0
  215. data/code/syntax/vectorscript.syntax +57 -0
  216. data/code/syntax/xhtml_1.0.syntax +4027 -0
  217. data/code/syntax/xml.syntax +180 -0
  218. data/code/syntax/xml_strict.syntax +92 -0
  219. data/code/syntax/xsl.syntax +60 -0
  220. data/code/syntax/yaml.syntax +160 -0
  221. data/code/syntax/yui_javascript.syntax +176 -0
  222. data/lib/bayeux/bayeux.rb +727 -0
  223. data/lib/bayeux/html_gen.rb +506 -0
  224. data/lib/bayeux/latex_gen.rb +333 -0
  225. data/lib/bayeux/para_block.rb +201 -0
  226. data/lib/bayeux/text_gen.rb +307 -0
  227. data/lib/bayeux/tree_walker.rb +166 -0
  228. data/lib/filters/bayeux.rb +44 -0
  229. data/lib/filters/pandoc.rb +23 -0
  230. data/lib/filters/section_id.rb +105 -0
  231. data/lib/helpers/breadcrumbs.rb +64 -0
  232. data/lib/helpers/site_toc.rb +11 -0
  233. data/lib/lib/uv.rb +92 -0
  234. data/lib/lib/uv/render_processor.rb +146 -0
  235. data/lib/lib/uv/utility.rb +67 -0
  236. data/lib/refs/Doc_Blocks.rb +2 -0
  237. data/lib/refs/References.rb +104 -0
  238. metadata +415 -0
@@ -0,0 +1,44 @@
1
+ ###
2
+ ### Converts input in Bayeux to HTML
3
+ ###
4
+
5
+ require 'json'
6
+
7
+ class BayeuxFilter < Nanoc3::Filter
8
+ identifier :bayeux
9
+ type :text
10
+
11
+ def run(content, params={})
12
+ syntax_tree = Bayeux.new
13
+ syntax_tree.parse(content)
14
+
15
+ # Update the master reference list
16
+ # using the data in the 'new' AST
17
+ $reference.update(syntax_tree)
18
+
19
+ #puts syntax_tree.to_s
20
+ #text_gen = BayeuxTextGen.new(syntax_tree)
21
+ #puts "---"
22
+ #puts syntax_tree.to_s
23
+ #puts "---"
24
+
25
+ puts "---"
26
+ puts JSON.pretty_generate(syntax_tree)
27
+ puts "---"
28
+
29
+
30
+ #latex_gen = BayeuxLatexGen.new(syntax_tree)
31
+ #puts "---"
32
+ #puts latex_gen.generate
33
+ #puts "---"
34
+
35
+
36
+ html_gen = BayeuxHTMLGen.new(syntax_tree)
37
+
38
+ # Get the document ToC from the AST (as HTML)
39
+ @item[:toc] = html_gen.doc_toc
40
+
41
+ # Return the AST rendered in HTML
42
+ return html_gen.generate
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ ###
2
+ ### Converts input in Markdown (extended) to HTML, using
3
+ ### Pandoc
4
+ ###
5
+
6
+ require 'tempfile'
7
+
8
+ class PandocFilter < Nanoc3::Filter
9
+ identifier :pandoc
10
+ type :text
11
+
12
+ def run(content, params={})
13
+ input_file = Tempfile.new('input')
14
+
15
+ input_file << content
16
+ input_file.close
17
+
18
+ output = `pandoc -f markdown -t textile -5 #{input_file.path}`
19
+
20
+ return output
21
+
22
+ end
23
+ end
@@ -0,0 +1,105 @@
1
+ ###
2
+ ### Adds section ID's to the HTML output
3
+ ###
4
+
5
+ require "haml"
6
+
7
+ class SectionIDFilter < Nanoc3::Filter
8
+ identifier :section_id
9
+ type :text
10
+
11
+ def run(content, params={})
12
+ parser = HTMLTokenizer.new(content)
13
+
14
+ # Table of Contents: Saved for use in the layout
15
+ toc = ""
16
+
17
+ # Last level of the ToC seen
18
+ last_toc_level = 0
19
+
20
+ # Final HTML returned for viewing in the browser
21
+ output = ""
22
+
23
+ begin
24
+ # Get a chunk of text, up to the next tag
25
+ output << parser.getText
26
+
27
+ # Process the header tags
28
+ next_tag = parser.getNextToken
29
+ if next_tag.kind_of?(HTMLTag)
30
+ case next_tag.tag_name
31
+ when "h1"
32
+ # Assemble the new header
33
+ header_text = parser.getTextAndTags("/h1")
34
+ output << "<h1 id=\"#{header_id(header_text)}\">"
35
+
36
+ last_toc_level = 1
37
+
38
+ when "h2"
39
+ # Assemble the new header
40
+ header_text = parser.getTextAndTags("/h2")
41
+ output << "<h2 id=\"#{header_id(header_text)}\">"
42
+
43
+ # Add to the Table of Contents
44
+ if last_toc_level != 2 then
45
+ toc << "%ul\n"
46
+ end
47
+
48
+ toc << "%li\n"
49
+ toc << " %a{:href => \"##{header_id(header_text)}\"}= \"" << header_text << "\"\n"
50
+
51
+ last_toc_level = 2
52
+
53
+ when "h3"
54
+ # Assemble the new header
55
+ header_text = parser.getTextAndTags("/h3")
56
+ output << "<h3 id=\"#{header_id(header_text)}\">"
57
+
58
+ # Add to the Table of Contents
59
+ if last_toc_level != 3 then
60
+ toc << " %ul\n"
61
+ end
62
+
63
+ toc << " %li\n"
64
+ toc << " %a{:href => \"##{header_id(header_text)}\"}= \"" << header_text << "\"\n"
65
+
66
+ last_toc_level = 3
67
+
68
+ when "h4"
69
+ # Assemble the new header
70
+ header_text = parser.getTextAndTags("/h4")
71
+ output << "<h4 id=\"#{header_id(header_text)}\">"
72
+
73
+ when "h5"
74
+ # Assemble the new header
75
+ header_text = parser.getTextAndTags("/h5")
76
+ output << "<h5 id=\"#{header_id(header_text)}\">"
77
+
78
+ when "h6"
79
+ # Assemble the new header
80
+ header_text = parser.getTextAndTags("/h6")
81
+ output << "<h6 id=\"#{header_id(header_text)}\">"
82
+
83
+ else
84
+ output << next_tag.raw
85
+ end
86
+ end
87
+
88
+ end until (parser.peekNextToken.nil?)
89
+
90
+ engine = Haml::Engine.new(toc)
91
+
92
+ @item[:toc] = engine.render
93
+
94
+ return output
95
+ end
96
+ end
97
+
98
+ # Return the header id, given a string of text
99
+ def header_id(header_text)
100
+ return header_text.gsub(" ", "_").downcase
101
+ end
102
+
103
+
104
+
105
+
@@ -0,0 +1,64 @@
1
+ include Nanoc3::Helpers::Breadcrumbs
2
+
3
+ def breadcrumbs_list
4
+ page_path = breadcrumbs_trail
5
+
6
+ puts "==="
7
+ @site.items.each{|item|
8
+ puts "found: #{item.identifier}"
9
+ }
10
+ puts "==="
11
+
12
+ # Walk the list of parent items
13
+ puts "---"
14
+ item = @item
15
+ until item.nil? do
16
+ puts "found: #{item.identifier}"
17
+ item = item.parent
18
+ end
19
+ puts "---"
20
+
21
+ html_list = Array.new
22
+ html_item = String.new
23
+ first_item = true
24
+
25
+ # Work out the page path
26
+ page_path.reverse_each{|path_item|
27
+ if not path_item.nil? then
28
+ if first_item then
29
+ html_item = "<a href=\"#{path_to_url(path_item.attributes[:filename])}\" class=\"current\">" + path_item.attributes[:title] + "</a>"
30
+ html_list << html_item
31
+
32
+ first_item = false
33
+ else
34
+ html_item = "<a href=\"#{path_to_url(path_item.attributes[:filename])}\">" + path_item.attributes[:title] + "</a>"
35
+ html_list << html_item
36
+ end
37
+ end
38
+ }
39
+
40
+ # Return the path
41
+ return page_path(html_list)
42
+ end
43
+
44
+ def path_to_url(path)
45
+ page_dir = File.dirname(path)
46
+ return page_dir[13..page_dir.length] + "/" + "index.html"
47
+ end
48
+
49
+ def page_path(element_list)
50
+ path = ""
51
+ first_item = true
52
+
53
+ element_list.reverse_each{|element|
54
+ if first_item then
55
+ path << element
56
+
57
+ first_item = false
58
+ else
59
+ path << " &raquo; " << element
60
+ end
61
+ }
62
+
63
+ return path
64
+ end
@@ -0,0 +1,11 @@
1
+ ###
2
+ ### Returns the site Table of Contents
3
+ ###
4
+
5
+ require "haml"
6
+
7
+ def site_toc
8
+ engine = Haml::Engine.new(@site.config[:site_toc])
9
+
10
+ return engine.render
11
+ end
@@ -0,0 +1,92 @@
1
+ #encoding: ascii-8bit
2
+ require 'fileutils'
3
+ require 'textpow'
4
+ require 'uv/render_processor.rb'
5
+
6
+
7
+ module Uv
8
+ class << self
9
+ attr_accessor :render_path, :theme_path, :syntax_path, :default_style, :syntaxes
10
+ end
11
+
12
+ self.theme_path = File.join(render_path, 'xhtml', 'files', 'css')
13
+ self.default_style = 'mac_classic'
14
+ self.syntaxes = {}
15
+
16
+ def Uv.path
17
+ result = []
18
+ result << File.join(File.dirname(__FILE__), ".." )
19
+ end
20
+
21
+ def self.syntax_node_for(syntax)
22
+ if !@syntaxes.key?(syntax)
23
+ filename = File.join(@syntax_path, "#{syntax}.syntax")
24
+ @syntaxes[syntax] = if File.exist?(filename)
25
+ Textpow::SyntaxNode.load(filename)
26
+ else
27
+ false
28
+ end
29
+ end
30
+ if !@syntaxes[syntax]
31
+ raise ArgumentError, "No #{syntax}.syntax file in #{@syntax_path}"
32
+ end
33
+ @syntaxes[syntax]
34
+ end
35
+
36
+ def Uv.copy_files output, output_dir
37
+ Uv.path.each do |dir|
38
+ dir_name = File.join( dir, "render", output, "files" )
39
+ FileUtils.cp_r( Dir.glob(File.join( dir_name, "." )), output_dir ) if File.exists?( dir_name )
40
+ end
41
+ end
42
+
43
+ def Uv.syntaxes
44
+ Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
45
+ File.basename(f, '.syntax')
46
+ end
47
+ end
48
+
49
+ def Uv.themes
50
+ Dir.glob( File.join(@theme_path, '*.css') ).collect do |f|
51
+ File.basename(f, '.css')
52
+ end
53
+ end
54
+
55
+ def Uv.syntax_for_file file_name
56
+ init_syntaxes unless @syntaxes
57
+ first_line = ""
58
+ File.open( file_name, 'r' ) { |f|
59
+ while (first_line = f.readline).strip.size == 0; end
60
+ }
61
+ result = []
62
+ @syntaxes.each do |key, value|
63
+ assigned = false
64
+ if value.fileTypes
65
+ value.fileTypes.each do |t|
66
+ if t == File.basename( file_name ) || t == File.extname( file_name )[1..-1]
67
+ result << [key, value]
68
+ assigned = true
69
+ break
70
+ end
71
+ end
72
+ end
73
+ unless assigned
74
+ if value.firstLineMatch && value.firstLineMatch =~ first_line
75
+ result << [key, value]
76
+ end
77
+ end
78
+ end
79
+ result
80
+ end
81
+
82
+ def Uv.parse text, output = "xhtml", syntax_name = nil, line_number = 0, render_style = nil, headers = false
83
+ RenderProcessor.load(output, render_style, line_number, headers) do |processor|
84
+ syntax_node_for(syntax_name).parse(text, processor)
85
+ end.string
86
+ end
87
+
88
+ def Uv.debug text, syntax_name
89
+ syntax_node_for(syntax_name).parse(text, Textpow::DebugProcessor.new)
90
+ end
91
+
92
+ end
@@ -0,0 +1,146 @@
1
+ require 'cgi'
2
+
3
+ module Uv
4
+
5
+ class RenderProcessor
6
+ @@score_manager = Textpow::ScoreManager.new
7
+
8
+ attr_reader :string
9
+ attr_accessor :escapeHTML
10
+
11
+ def self.load(output, style = nil, line_number = 0, headers = false)
12
+ style ||= Uv.default_style
13
+ renderer = File.join( Uv.render_path, output,"#{style}.render")
14
+ raise( ArgumentError, "Output for #{output} in #{style} style is not yet implemented" ) unless File.exists?(renderer)
15
+ options = YAML.load_file(renderer)
16
+ processor = RenderProcessor.new(options, line_number, headers)
17
+ yield processor if block_given?
18
+ processor
19
+ end
20
+
21
+ def initialize render_options, line_number = 0, headers = true, score_manager = nil
22
+ @score_manager = score_manager || @@score_manager
23
+ @render_options = render_options
24
+ @options = {}
25
+ @headers = headers
26
+ @escapeHTML = true
27
+
28
+ @line_numbers = !(line_number.nil? or (line_number == 0))
29
+ unless @line_numbers then
30
+ @line_number = 0
31
+ else
32
+ @line_number = line_number - 1
33
+ end
34
+
35
+ end
36
+
37
+ def start_parsing name
38
+ @stack = [name]
39
+ @string = ""
40
+ @line = nil
41
+ print @render_options["document"]["begin"] if @headers
42
+ print @render_options["listing"]["begin"]
43
+ # opt = options @stack
44
+ # print opt["begin"] if opt
45
+ end
46
+
47
+ def print string
48
+ @string << string
49
+ end
50
+
51
+ def escape string
52
+ if @render_options["filter"]
53
+ @escaped = string
54
+ @escaped = self.instance_eval( @render_options["filter"] )
55
+ @escaped
56
+ else
57
+ string
58
+ end
59
+ end
60
+
61
+ def open_tag name, position
62
+ @stack << name
63
+ print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
64
+ @position = position
65
+ opt = options @stack
66
+ print opt["begin"] if opt
67
+ end
68
+
69
+ def close_tag name, position
70
+ print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
71
+ @position = position
72
+ opt = options @stack
73
+ print opt["end"] if opt
74
+ @stack.pop
75
+ end
76
+
77
+ def close_line
78
+ stack = @stack[0..-1]
79
+ while stack.size > 1
80
+ opt = options stack
81
+ print opt["end"] if opt
82
+ stack.pop
83
+ end
84
+ end
85
+
86
+ def open_line
87
+ stack = [@stack.first]
88
+ clone = @stack[1..-1]
89
+ while stack.size < @stack.size
90
+ stack << clone.shift
91
+ opt = options stack
92
+ print opt["begin"] if opt
93
+ end
94
+ end
95
+
96
+ def new_line line
97
+ if @line
98
+ print escape(@line[@position..-1].gsub(/\n|\r/, ''))
99
+ close_line
100
+ print @render_options["line"]["end"]
101
+ print "\n"
102
+ end
103
+ @position = 0
104
+ @line_number += 1
105
+ @line = line
106
+ print @render_options["line"]["begin"]
107
+ if @line_numbers
108
+ print @render_options["line-numbers"]["begin"]
109
+ print @line_number.to_s.rjust(4).ljust(5)
110
+ print @render_options["line-numbers"]["end"]
111
+ print " "
112
+ end
113
+ open_line
114
+ end
115
+
116
+ def end_parsing name
117
+ if @line
118
+ print escape(@line[@position..-1].gsub(/\n|\r/, ''))
119
+ while @stack.size > 1
120
+ opt = options @stack
121
+ print opt["end"] if opt
122
+ @stack.pop
123
+ end
124
+ print @render_options["line"]["end"]
125
+ print "\n"
126
+ end
127
+ # opt = options @stack
128
+ # print opt["end"] if opt
129
+ @stack.pop
130
+ print @render_options["listing"]["end"]
131
+ print @render_options["document"]["end"] if @headers
132
+ end
133
+
134
+ def options stack
135
+ ref = stack.join ' '
136
+ return @options[ref] if @options.has_key? ref
137
+
138
+ result = @render_options['tags'].max do |a, b|
139
+ @score_manager.score( a['selector'], ref ) <=> @score_manager.score( b['selector'], ref )
140
+ end
141
+ result = nil if @score_manager.score( result['selector'], ref ) == 0
142
+ @options[ref] = result
143
+ end
144
+ end
145
+ end
146
+