devver-ultraviolet 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. data/History.txt +25 -0
  2. data/Manifest.txt +233 -0
  3. data/README.txt +52 -0
  4. data/bin/theme2latexrender +122 -0
  5. data/bin/theme2xhtmlrender +156 -0
  6. data/bin/uv +140 -0
  7. data/lib/uv.rb +94 -0
  8. data/lib/uv/render_processor.rb +146 -0
  9. data/lib/uv/utility.rb +67 -0
  10. data/render/latex/active4d.render +132 -0
  11. data/render/latex/all_hallows_eve.render +96 -0
  12. data/render/latex/amy.render +171 -0
  13. data/render/latex/blackboard.render +111 -0
  14. data/render/latex/brilliance_black.render +552 -0
  15. data/render/latex/brilliance_dull.render +561 -0
  16. data/render/latex/cobalt.render +162 -0
  17. data/render/latex/dawn.render +126 -0
  18. data/render/latex/eiffel.render +132 -0
  19. data/render/latex/espresso_libre.render +123 -0
  20. data/render/latex/idle.render +93 -0
  21. data/render/latex/iplastic.render +99 -0
  22. data/render/latex/lazy.render +96 -0
  23. data/render/latex/mac_classic.render +135 -0
  24. data/render/latex/magicwb_amiga.render +117 -0
  25. data/render/latex/pastels_on_dark.render +204 -0
  26. data/render/latex/slush_poppies.render +123 -0
  27. data/render/latex/spacecadet.render +81 -0
  28. data/render/latex/sunburst.render +186 -0
  29. data/render/latex/twilight.render +153 -0
  30. data/render/latex/zenburnesque.render +126 -0
  31. data/render/old/txt2tags.render +131 -0
  32. data/render/xhtml/active4d.render +140 -0
  33. data/render/xhtml/all_hallows_eve.render +104 -0
  34. data/render/xhtml/amy.render +179 -0
  35. data/render/xhtml/blackboard.render +119 -0
  36. data/render/xhtml/brilliance_black.render +560 -0
  37. data/render/xhtml/brilliance_dull.render +569 -0
  38. data/render/xhtml/cobalt.render +170 -0
  39. data/render/xhtml/dawn.render +134 -0
  40. data/render/xhtml/eiffel.render +140 -0
  41. data/render/xhtml/espresso_libre.render +131 -0
  42. data/render/xhtml/files/css/active4d.css +114 -0
  43. data/render/xhtml/files/css/all_hallows_eve.css +72 -0
  44. data/render/xhtml/files/css/amy.css +147 -0
  45. data/render/xhtml/files/css/blackboard.css +88 -0
  46. data/render/xhtml/files/css/brilliance_black.css +605 -0
  47. data/render/xhtml/files/css/brilliance_dull.css +599 -0
  48. data/render/xhtml/files/css/cobalt.css +149 -0
  49. data/render/xhtml/files/css/dawn.css +121 -0
  50. data/render/xhtml/files/css/eiffel.css +121 -0
  51. data/render/xhtml/files/css/espresso_libre.css +109 -0
  52. data/render/xhtml/files/css/idle.css +62 -0
  53. data/render/xhtml/files/css/iplastic.css +80 -0
  54. data/render/xhtml/files/css/lazy.css +73 -0
  55. data/render/xhtml/files/css/mac_classic.css +123 -0
  56. data/render/xhtml/files/css/magicwb_amiga.css +104 -0
  57. data/render/xhtml/files/css/pastels_on_dark.css +188 -0
  58. data/render/xhtml/files/css/slush_poppies.css +85 -0
  59. data/render/xhtml/files/css/spacecadet.css +51 -0
  60. data/render/xhtml/files/css/sunburst.css +180 -0
  61. data/render/xhtml/files/css/twilight.css +137 -0
  62. data/render/xhtml/files/css/zenburnesque.css +91 -0
  63. data/render/xhtml/idle.render +101 -0
  64. data/render/xhtml/iplastic.render +107 -0
  65. data/render/xhtml/lazy.render +104 -0
  66. data/render/xhtml/mac_classic.render +143 -0
  67. data/render/xhtml/magicwb_amiga.render +125 -0
  68. data/render/xhtml/pastels_on_dark.render +212 -0
  69. data/render/xhtml/slush_poppies.render +131 -0
  70. data/render/xhtml/spacecadet.render +89 -0
  71. data/render/xhtml/sunburst.render +194 -0
  72. data/render/xhtml/twilight.render +161 -0
  73. data/render/xhtml/zenburnesque.render +134 -0
  74. data/syntax/actionscript.syntax +97 -0
  75. data/syntax/active4d.syntax +276 -0
  76. data/syntax/active4d_html.syntax +311 -0
  77. data/syntax/active4d_ini.syntax +50 -0
  78. data/syntax/active4d_library.syntax +21 -0
  79. data/syntax/ada.syntax +33 -0
  80. data/syntax/antlr.syntax +151 -0
  81. data/syntax/apache.syntax +191 -0
  82. data/syntax/applescript.syntax +384 -0
  83. data/syntax/asp.syntax +70 -0
  84. data/syntax/asp_vb.net.syntax +129 -0
  85. data/syntax/bibtex.syntax +151 -0
  86. data/syntax/blog_html.syntax +41 -0
  87. data/syntax/blog_markdown.syntax +42 -0
  88. data/syntax/blog_text.syntax +27 -0
  89. data/syntax/blog_textile.syntax +27 -0
  90. data/syntax/build.syntax +53 -0
  91. data/syntax/bulletin_board.syntax +287 -0
  92. data/syntax/cake.syntax +55 -0
  93. data/syntax/camlp4.syntax +36 -0
  94. data/syntax/cm.syntax +32 -0
  95. data/syntax/coldfusion.syntax +119 -0
  96. data/syntax/context_free.syntax +176 -0
  97. data/syntax/cs.syntax +59 -0
  98. data/syntax/css.syntax +195 -0
  99. data/syntax/css_experimental.syntax +1925 -0
  100. data/syntax/csv.syntax +68 -0
  101. data/syntax/d.syntax +142 -0
  102. data/syntax/diff.syntax +81 -0
  103. data/syntax/dokuwiki.syntax +204 -0
  104. data/syntax/dot.syntax +47 -0
  105. data/syntax/doxygen.syntax +43 -0
  106. data/syntax/dylan.syntax +62 -0
  107. data/syntax/eiffel.syntax +78 -0
  108. data/syntax/erlang.syntax +922 -0
  109. data/syntax/f-script.syntax +80 -0
  110. data/syntax/fortran.syntax +141 -0
  111. data/syntax/fxscript.syntax +142 -0
  112. data/syntax/greasemonkey.syntax +34 -0
  113. data/syntax/gri.syntax +83 -0
  114. data/syntax/groovy.syntax +191 -0
  115. data/syntax/gtd.syntax +22 -0
  116. data/syntax/gtdalt.syntax +143 -0
  117. data/syntax/haml.syntax +88 -0
  118. data/syntax/haskell.syntax +88 -0
  119. data/syntax/html-asp.syntax +27 -0
  120. data/syntax/html.syntax +362 -0
  121. data/syntax/html_django.syntax +36 -0
  122. data/syntax/html_for_asp.net.syntax +424 -0
  123. data/syntax/html_mason.syntax +119 -0
  124. data/syntax/html_rails.syntax +40 -0
  125. data/syntax/html_tcl.syntax +26 -0
  126. data/syntax/icalendar.syntax +32 -0
  127. data/syntax/inform.syntax +48 -0
  128. data/syntax/ini.syntax +55 -0
  129. data/syntax/installer_distribution_script.syntax +77 -0
  130. data/syntax/io.syntax +81 -0
  131. data/syntax/java.syntax +211 -0
  132. data/syntax/javaproperties.syntax +20 -0
  133. data/syntax/javascript.syntax +256 -0
  134. data/syntax/javascript_+_prototype.syntax +72 -0
  135. data/syntax/javascript_+_prototype_bracketed.syntax +140 -0
  136. data/syntax/jquery_javascript.syntax +114 -0
  137. data/syntax/json.syntax +136 -0
  138. data/syntax/languagedefinition.syntax +708 -0
  139. data/syntax/latex.syntax +566 -0
  140. data/syntax/latex_beamer.syntax +41 -0
  141. data/syntax/latex_log.syntax +50 -0
  142. data/syntax/latex_memoir.syntax +64 -0
  143. data/syntax/lexflex.syntax +219 -0
  144. data/syntax/lighttpd.syntax +54 -0
  145. data/syntax/lilypond.syntax +492 -0
  146. data/syntax/lisp.syntax +61 -0
  147. data/syntax/literate_haskell.syntax +24 -0
  148. data/syntax/logo.syntax +29 -0
  149. data/syntax/logtalk.syntax +152 -0
  150. data/syntax/lua.syntax +86 -0
  151. data/syntax/m.syntax +142 -0
  152. data/syntax/macports_portfile.syntax +163 -0
  153. data/syntax/makefile.syntax +36 -0
  154. data/syntax/man.syntax +17 -0
  155. data/syntax/mediawiki.syntax +567 -0
  156. data/syntax/mips.syntax +66 -0
  157. data/syntax/mod_perl.syntax +50 -0
  158. data/syntax/modula-3.syntax +47 -0
  159. data/syntax/moinmoin.syntax +189 -0
  160. data/syntax/mootools.syntax +572 -0
  161. data/syntax/movable_type.syntax +162 -0
  162. data/syntax/multimarkdown.syntax +39 -0
  163. data/syntax/objective-c++.syntax +18 -0
  164. data/syntax/objective-c.syntax +233 -0
  165. data/syntax/ocaml.syntax +764 -0
  166. data/syntax/ocamllex.syntax +167 -0
  167. data/syntax/ocamlyacc.syntax +184 -0
  168. data/syntax/opengl.syntax +14 -0
  169. data/syntax/pascal.syntax +77 -0
  170. data/syntax/perl.syntax +1115 -0
  171. data/syntax/plain_text.syntax +32 -0
  172. data/syntax/postscript.syntax +114 -0
  173. data/syntax/processing.syntax +106 -0
  174. data/syntax/prolog.syntax +40 -0
  175. data/syntax/property_list.syntax +635 -0
  176. data/syntax/python.syntax +868 -0
  177. data/syntax/python_django.syntax +21 -0
  178. data/syntax/qmake_project.syntax +114 -0
  179. data/syntax/qt_c++.syntax +26 -0
  180. data/syntax/quake3_config.syntax +32 -0
  181. data/syntax/r.syntax +81 -0
  182. data/syntax/r_console.syntax +16 -0
  183. data/syntax/ragel.syntax +201 -0
  184. data/syntax/rd_r_documentation.syntax +91 -0
  185. data/syntax/regexp.syntax +50 -0
  186. data/syntax/release_notes.syntax +46 -0
  187. data/syntax/remind.syntax +253 -0
  188. data/syntax/restructuredtext.syntax +250 -0
  189. data/syntax/rez.syntax +80 -0
  190. data/syntax/ruby.syntax +1035 -0
  191. data/syntax/ruby_experimental.syntax +145 -0
  192. data/syntax/ruby_on_rails.syntax +88 -0
  193. data/syntax/s5.syntax +69 -0
  194. data/syntax/scheme.syntax +347 -0
  195. data/syntax/scilab.syntax +41 -0
  196. data/syntax/setext.syntax +147 -0
  197. data/syntax/shell-unix-generic.syntax +384 -0
  198. data/syntax/slate.syntax +149 -0
  199. data/syntax/sql.syntax +237 -0
  200. data/syntax/sql_rails.syntax +18 -0
  201. data/syntax/ssh-config.syntax +33 -0
  202. data/syntax/standard_ml.syntax +121 -0
  203. data/syntax/strings_file.syntax +39 -0
  204. data/syntax/subversion_commit_message.syntax +36 -0
  205. data/syntax/sweave.syntax +84 -0
  206. data/syntax/swig.syntax +57 -0
  207. data/syntax/tcl.syntax +152 -0
  208. data/syntax/template_toolkit.syntax +121 -0
  209. data/syntax/tex.syntax +86 -0
  210. data/syntax/tex_math.syntax +49 -0
  211. data/syntax/textile.syntax +215 -0
  212. data/syntax/tsv.syntax +50 -0
  213. data/syntax/twiki.syntax +241 -0
  214. data/syntax/txt2tags.syntax +79 -0
  215. data/syntax/vectorscript.syntax +57 -0
  216. data/syntax/xhtml_1.0.syntax +4027 -0
  217. data/syntax/xml.syntax +180 -0
  218. data/syntax/xml_strict.syntax +92 -0
  219. data/syntax/xsl.syntax +60 -0
  220. data/syntax/yaml.syntax +160 -0
  221. data/syntax/yui_javascript.syntax +176 -0
  222. metadata +310 -0
data/bin/uv ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ require 'uv'
6
+ rescue LoadError
7
+ $:.unshift File.join( File.dirname(__FILE__), '..', 'lib' )
8
+ require 'uv'
9
+ end
10
+
11
+ require 'optparse'
12
+ require 'ostruct'
13
+
14
+ o = OpenStruct.new
15
+ o.copy_files = false
16
+ o.output = "xhtml"
17
+ o.headers = false
18
+ o.theme = "espresso_libre"
19
+ o.lines = true
20
+
21
+ options = OptionParser.new
22
+
23
+ options.banner =<<END
24
+
25
+ Usage: uv [options] input_file
26
+
27
+ Parses input_file (or stdin, if no input_file is given) and
28
+ outputs the coresponding HTML to stdout. If no syntax is specified,
29
+ it tries to guess the best one. If no theme is specified, defaults
30
+ to espresso_libre.
31
+
32
+ Example:
33
+
34
+ uv -t amy -h ~/.bashrc > bashrc.html
35
+
36
+ Renders the contents of ~/.bashrc to file bashrc.html
37
+ as a standalone web page.
38
+
39
+ All options are non-mandatory
40
+
41
+ Options:
42
+
43
+ END
44
+
45
+ options.on( "-c DIR", "--copy-files DIR", <<DESCRIPTION ) {|val| o.copy_files = val}
46
+ Copy the required files to the specified output directory (css, images, etc).
47
+ DESCRIPTION
48
+
49
+ options.on( "-s SYNTAX", "--syntax SYNTAX", <<DESCRIPTION, Uv.syntaxes) {|val| o.syntax = val}
50
+ The file's syntax (e.g. ruby, c++, etc.)
51
+ DESCRIPTION
52
+
53
+ options.on( "-o OUTPUT", "--output OUTPUT", <<DESCRIPTION) {|val| o.output = val}
54
+ The output format (xhtml, latex, etc.) default to xhtml
55
+ DESCRIPTION
56
+
57
+ options.on( "-t THEME", "--theme THEME", <<DESCRIPTION, Uv.themes) {|val| o.theme = val}
58
+ The theme to be used (e.g. amy, espresso_libre, etc.)
59
+ DESCRIPTION
60
+
61
+ options.on( "-n", "--no-lines", <<DESCRIPTION ) {|val| o.lines = false}
62
+ Produces output without line numbers
63
+ DESCRIPTION
64
+
65
+
66
+ options.on( "-h", "--headers", <<DESCRIPTION ) {|val| o.headers = val}
67
+ Include headers, outputs a self-contained web page/document
68
+ DESCRIPTION
69
+
70
+ options.on( "-d", "--debug", <<DESCRIPTION ) {|val| o.debug = val}
71
+ Outputs debug information instead of normal page rendering
72
+ DESCRIPTION
73
+
74
+ options.on( "-l [syntaxes|themes]", "--list [syntaxes|themes]", ['syntaxes', 'themes'], <<DESCRIPTION ) {|val| o.list = val}
75
+ Lists all the available syntaxes/themes
76
+ DESCRIPTION
77
+
78
+
79
+ options.on( "-?", "--help", <<DESCRIPTION ) {|val| o.help = val}
80
+ Show this message
81
+ DESCRIPTION
82
+
83
+ rest = options.parse( ARGV )
84
+
85
+
86
+ if o.help
87
+ puts options
88
+ exit
89
+ elsif o.list
90
+ if o.list == 'syntaxes'
91
+ puts "Available syntaxes:\n"
92
+ Uv.syntaxes.sort.each{ |s| puts " - #{s}"}
93
+ elsif o.list == 'themes'
94
+ puts "Available themes:\n"
95
+ Uv.themes.sort.each{ |t| puts " - #{t}"}
96
+ else
97
+ STDERR.puts "Option #{o.list} is not valid should be one of [syntaxes, themes]"
98
+ end
99
+ exit
100
+ end
101
+
102
+ if o.copy_files
103
+ unless File.exists?(o.copy_files)
104
+ STDERR.puts "The specified output directory: #{o.copy_files} does not exist."
105
+ exit -1
106
+ end
107
+ Uv.copy_files o.output, o.copy_files
108
+ end
109
+
110
+ o.filename = rest[0]
111
+
112
+ if o.filename && ! o.syntax
113
+ candidates = Uv.syntax_for_file o.filename
114
+ if candidates.size > 1
115
+ STDERR.puts "Many syntaxes match, please specify"
116
+ STDERR.puts "\nMatching syntaxes:"
117
+ candidates.sort.each { |name, syntax| STDERR.puts "\t - " + name}
118
+ exit -1
119
+ end
120
+ o.syntax = candidates.first.first unless candidates.size == 0
121
+ end
122
+
123
+ unless o.syntax
124
+ STDERR.puts "No default syntax found, please specify"
125
+ exit -1
126
+ end
127
+
128
+ if o.filename
129
+ o.text = File.read(o.filename)
130
+ else
131
+ o.text = STDIN
132
+ end
133
+
134
+ if o.debug
135
+ Uv.debug( o.text, o.syntax )
136
+ exit
137
+ end
138
+
139
+ puts Uv.parse( o.text, o.output, o.syntax, o.lines, o.theme, o.headers )
140
+
@@ -0,0 +1,94 @@
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.syntax_path = File.join(File.dirname(__FILE__), '..', 'syntax')
13
+ self.render_path = File.join(File.dirname(__FILE__), '..', 'render')
14
+ self.theme_path = File.join(render_path, 'xhtml', 'files', 'css')
15
+ self.default_style = 'mac_classic'
16
+ self.syntaxes = {}
17
+
18
+ def Uv.path
19
+ result = []
20
+ result << File.join(File.dirname(__FILE__), ".." )
21
+ end
22
+
23
+ def self.syntax_node_for(syntax)
24
+ if !@syntaxes.key?(syntax)
25
+ filename = File.join(@syntax_path, "#{syntax}.syntax")
26
+ @syntaxes[syntax] = if File.exist?(filename)
27
+ Textpow::SyntaxNode.load(filename)
28
+ else
29
+ false
30
+ end
31
+ end
32
+ if !@syntaxes[syntax]
33
+ raise ArgumentError, "No #{syntax}.syntax file in #{@syntax_path}"
34
+ end
35
+ @syntaxes[syntax]
36
+ end
37
+
38
+ def Uv.copy_files output, output_dir
39
+ Uv.path.each do |dir|
40
+ dir_name = File.join( dir, "render", output, "files" )
41
+ FileUtils.cp_r( Dir.glob(File.join( dir_name, "." )), output_dir ) if File.exists?( dir_name )
42
+ end
43
+ end
44
+
45
+ def Uv.syntaxes
46
+ Dir.glob( File.join(@syntax_path, '*.syntax') ).collect do |f|
47
+ File.basename(f, '.syntax')
48
+ end
49
+ end
50
+
51
+ def Uv.themes
52
+ Dir.glob( File.join(@theme_path, '*.css') ).collect do |f|
53
+ File.basename(f, '.css')
54
+ end
55
+ end
56
+
57
+ def Uv.syntax_for_file file_name
58
+ init_syntaxes unless @syntaxes
59
+ first_line = ""
60
+ File.open( file_name, 'r' ) { |f|
61
+ while (first_line = f.readline).strip.size == 0; end
62
+ }
63
+ result = []
64
+ @syntaxes.each do |key, value|
65
+ assigned = false
66
+ if value.fileTypes
67
+ value.fileTypes.each do |t|
68
+ if t == File.basename( file_name ) || t == File.extname( file_name )[1..-1]
69
+ result << [key, value]
70
+ assigned = true
71
+ break
72
+ end
73
+ end
74
+ end
75
+ unless assigned
76
+ if value.firstLineMatch && value.firstLineMatch =~ first_line
77
+ result << [key, value]
78
+ end
79
+ end
80
+ end
81
+ result
82
+ end
83
+
84
+ def Uv.parse text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false
85
+ RenderProcessor.load(output, render_style, line_numbers, headers) do |processor|
86
+ syntax_node_for(syntax_name).parse(text, processor)
87
+ end.string
88
+ end
89
+
90
+ def Uv.debug text, syntax_name
91
+ syntax_node_for(syntax_name).parse(text, Textpow::DebugProcessor.new)
92
+ end
93
+
94
+ 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_numbers = false, 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_numbers, headers)
17
+ yield processor if block_given?
18
+ processor
19
+ end
20
+
21
+ def initialize render_options, line_numbers = false, headers = true, score_manager = nil
22
+ @score_manager = score_manager || @@score_manager
23
+ @render_options = render_options
24
+ @options = {}
25
+ @headers = headers
26
+ @line_numbers = line_numbers
27
+ @escapeHTML = true
28
+ end
29
+
30
+ def start_parsing name
31
+ @stack = [name]
32
+ @string = ""
33
+ @line = nil
34
+ @line_number = 0
35
+ print @render_options["document"]["begin"] if @headers
36
+ print @render_options["listing"]["begin"]
37
+ # opt = options @stack
38
+ # print opt["begin"] if opt
39
+ end
40
+
41
+ def print string
42
+ @string << string
43
+ end
44
+
45
+ def escape string
46
+ if @render_options["filter"]
47
+ @escaped = string
48
+ @escaped = self.instance_eval( @render_options["filter"] )
49
+ @escaped
50
+ else
51
+ string
52
+ end
53
+ end
54
+
55
+ def open_tag name, position
56
+ @stack << name
57
+ print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
58
+ @position = position
59
+ opt = options @stack
60
+ print opt["begin"] if opt
61
+ end
62
+
63
+ def close_tag name, position
64
+ print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
65
+ @position = position
66
+ opt = options @stack
67
+ print opt["end"] if opt
68
+ @stack.pop
69
+ end
70
+
71
+ def close_line
72
+ stack = @stack[0..-1]
73
+ while stack.size > 1
74
+ opt = options stack
75
+ print opt["end"] if opt
76
+ stack.pop
77
+ end
78
+ print "</span>" #end code span
79
+ end
80
+
81
+ def open_line
82
+ stack = [@stack.first]
83
+ clone = @stack[1..-1]
84
+ while stack.size < @stack.size
85
+ stack << clone.shift
86
+ opt = options stack
87
+ print opt["begin"] if opt
88
+ end
89
+ end
90
+
91
+ def new_line line
92
+ if @line
93
+ print escape(@line[@position..-1].gsub(/\n|\r/, ''))
94
+ close_line
95
+ print @render_options["line"]["end"]
96
+ print "</span>" #end whole line span
97
+ print "\n"
98
+ end
99
+ @position = 0
100
+ @line_number += 1
101
+ @line = line
102
+ print "<span id='whole-code-line-#{@line_number}'>"
103
+ print @render_options["line"]["begin"]
104
+ if @line_numbers
105
+ print @render_options["line-numbers"]["begin"]
106
+ print @line_number.to_s.rjust(4).ljust(5)
107
+ print @render_options["line-numbers"]["end"]
108
+ print " "
109
+ end
110
+ print "<span id='only-code-line-#{@line_number}'>"
111
+ open_line
112
+ end
113
+
114
+ def end_parsing name
115
+ if @line
116
+ print escape(@line[@position..-1].gsub(/\n|\r/, ''))
117
+ while @stack.size > 1
118
+ opt = options @stack
119
+ print opt["end"] if opt
120
+ @stack.pop
121
+ end
122
+ print @render_options["line"]["end"]
123
+ print "</span>" #end code span
124
+ print "</span>" #end whole line span
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
+
@@ -0,0 +1,67 @@
1
+ module Uv
2
+ def Uv.foreground bg
3
+ fg = "#FFFFFF"
4
+ 3.times do |i|
5
+ fg = "#000000" if bg[i*2+1, 2].hex > 0xFF / 2
6
+ end
7
+ fg
8
+ end
9
+
10
+ def Uv.alpha_blend bg, fg
11
+ unless bg =~ /^#((\d|[ABCDEF]){3}|(\d|[ABCDEF]){6}|(\d|[ABCDEF]){8})$/i
12
+ raise(ArgumentError, "Malformed background color '#{bg}'" )
13
+ end
14
+ unless fg =~ /^#((\d|[ABCDEF]){3}|(\d|[ABCDEF]){6}|(\d|[ABCDEF]){8})$/i
15
+ raise(ArgumentError, "Malformed foreground color '#{fg}'" )
16
+ end
17
+
18
+ if bg.size == 4
19
+ tbg = (fg[1,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
20
+ tbg += (fg[2,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
21
+ tbg += (fg[3,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
22
+ bg = "##{tbg}"
23
+ end
24
+
25
+ result = ""
26
+ if fg.size == 4
27
+ result += (fg[1,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
28
+ result += (fg[2,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
29
+ result += (fg[3,1].hex * 0xff / 0xf).to_s(16).upcase.rjust(2, '0')
30
+ elsif fg.size == 9
31
+ if bg.size == 7
32
+ div0 = bg[1..-1].hex
33
+ div1, alpha = fg[1..-1].hex.divmod( 0x100 )
34
+ 3.times {
35
+ div0, mod0 = div0.divmod( 0x100 )
36
+ div1, mod1 = div1.divmod( 0x100 )
37
+ result = ((mod0 * alpha + mod1 * ( 0x100 - alpha ) ) / 0x100).to_s(16).upcase.rjust(2, '0') + result
38
+ }
39
+ else
40
+ div_a, alpha_a = bg[1..-1].hex.divmod( 0x100 )
41
+ div_b, alpha_b = fg[1..-1].hex.divmod( 0x100 )
42
+ alpha = alpha_a + alpha_b * (0x100 - alpha_a)
43
+ 3.times {
44
+ div_b, c_b = div_b.divmod( 0x100 )
45
+ div_a, c_a = div_a.divmod( 0x100 )
46
+ result = ((c_a * alpha_a + ( 0x100 - alpha_a ) * alpha_b * c_b ) / alpha).to_s(16).upcase.rjust(2, '0') + result
47
+ }
48
+ end
49
+ #result = "FF00FF"
50
+ else
51
+ result = fg[1..-1]
52
+ end
53
+ "##{result}"
54
+ end
55
+
56
+ def Uv.normalize_color settings, color, fg = false
57
+ if color
58
+ if fg
59
+ alpha_blend( settings["foreground"] ? settings["foreground"] : "#000000FF", color )
60
+ else
61
+ alpha_blend( settings["background"] ? settings["background"] : "#000000FF", color )
62
+ end
63
+ else
64
+ color
65
+ end
66
+ end
67
+ end