coderay 0.7.1.147 → 0.7.2.165

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/bin/coderay +54 -56
  2. data/demo/suite.rb +54 -54
  3. data/lib/coderay.rb +187 -187
  4. data/lib/coderay/duo.rb +29 -29
  5. data/lib/coderay/encoder.rb +173 -173
  6. data/lib/coderay/encoders/_map.rb +8 -8
  7. data/lib/coderay/encoders/count.rb +21 -21
  8. data/lib/coderay/encoders/debug.rb +46 -46
  9. data/lib/coderay/encoders/div.rb +20 -20
  10. data/lib/coderay/encoders/html.rb +249 -245
  11. data/lib/coderay/encoders/html/classes.rb +73 -73
  12. data/lib/coderay/encoders/html/css.rb +65 -65
  13. data/lib/coderay/encoders/html/numerization.rb +122 -122
  14. data/lib/coderay/encoders/html/output.rb +195 -195
  15. data/lib/coderay/encoders/null.rb +26 -26
  16. data/lib/coderay/encoders/page.rb +21 -21
  17. data/lib/coderay/encoders/span.rb +20 -20
  18. data/lib/coderay/encoders/statistic.rb +81 -81
  19. data/lib/coderay/encoders/text.rb +33 -33
  20. data/lib/coderay/encoders/tokens.rb +44 -44
  21. data/lib/coderay/encoders/xml.rb +71 -71
  22. data/lib/coderay/encoders/yaml.rb +22 -22
  23. data/lib/coderay/helpers/filetype.rb +152 -153
  24. data/lib/coderay/helpers/gzip_simple.rb +67 -68
  25. data/lib/coderay/helpers/plugin.rb +297 -297
  26. data/lib/coderay/helpers/word_list.rb +46 -47
  27. data/lib/coderay/scanner.rb +238 -238
  28. data/lib/coderay/scanners/_map.rb +15 -14
  29. data/lib/coderay/scanners/c.rb +163 -155
  30. data/lib/coderay/scanners/delphi.rb +131 -129
  31. data/lib/coderay/scanners/html.rb +174 -167
  32. data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
  33. data/lib/coderay/scanners/plaintext.rb +15 -15
  34. data/lib/coderay/scanners/rhtml.rb +73 -65
  35. data/lib/coderay/scanners/ruby.rb +404 -397
  36. data/lib/coderay/scanners/ruby/patterns.rb +216 -216
  37. data/lib/coderay/scanners/xml.rb +18 -18
  38. data/lib/coderay/style.rb +20 -20
  39. data/lib/coderay/styles/_map.rb +3 -3
  40. data/lib/coderay/styles/cycnus.rb +18 -18
  41. data/lib/coderay/styles/murphy.rb +18 -18
  42. data/lib/coderay/tokens.rb +322 -322
  43. metadata +86 -86
  44. data/lib/coderay/scanners/nitro_html.rb +0 -125
  45. data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,195 +1,195 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- class HTML
5
-
6
- # This module is included in the output String from thew HTML Encoder.
7
- #
8
- # It provides methods like wrap, div, page etc.
9
- #
10
- # Remember to use #clone instead of #dup to keep the modules the object was
11
- # extended with.
12
- #
13
- # TODO: more doc.
14
- module Output
15
-
16
- require 'coderay/encoders/html/numerization.rb'
17
-
18
- attr_accessor :css
19
-
20
- class << self
21
-
22
- # This makes Output look like a class.
23
- #
24
- # Example:
25
- #
26
- # a = Output.new '<span class="co">Code</span>'
27
- # a.wrap! :page
28
- def new string, css = CSS.new, element = nil
29
- output = string.clone.extend self
30
- output.wrapped_in = element
31
- output.css = css
32
- output
33
- end
34
-
35
- # Raises an exception if an object that doesn't respond to to_str is extended by Output,
36
- # to prevent users from misuse. Use Module#remove_method to disable.
37
- def extended o
38
- warn "The Output module is intended to extend instances of String, not #{o.class}." unless o.respond_to? :to_str
39
- end
40
-
41
- def make_stylesheet css, in_tag = false
42
- sheet = css.stylesheet
43
- sheet = <<-CSS if in_tag
44
- <style type="text/css">
45
- #{sheet}
46
- </style>
47
- CSS
48
- sheet
49
- end
50
-
51
- def page_template_for_css css
52
- sheet = make_stylesheet css
53
- PAGE.apply 'CSS', sheet
54
- end
55
-
56
- # Define a new wrapper. This is meta programming.
57
- def wrapper *wrappers
58
- wrappers.each do |wrapper|
59
- define_method wrapper do |*args|
60
- wrap wrapper, *args
61
- end
62
- define_method "#{wrapper}!".to_sym do |*args|
63
- wrap! wrapper, *args
64
- end
65
- end
66
- end
67
-
68
- end
69
-
70
- wrapper :div, :span, :page
71
-
72
- def wrapped_in? element
73
- wrapped_in == element
74
- end
75
-
76
- def wrapped_in
77
- @wrapped_in ||= nil
78
- end
79
- attr_writer :wrapped_in
80
-
81
- def wrap_in template
82
- clone.wrap_in! template
83
- end
84
-
85
- def wrap_in! template
86
- Template.wrap! self, template, 'CONTENT'
87
- self
88
- end
89
-
90
- def wrap! element, *args
91
- return self if not element or element == wrapped_in
92
- case element
93
- when :div
94
- raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
95
- wrap_in! DIV
96
- when :span
97
- raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
98
- wrap_in! SPAN
99
- when :page
100
- wrap! :div if wrapped_in? nil
101
- raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? :div
102
- wrap_in! Output.page_template_for_css(@css)
103
- when nil
104
- return self
105
- else
106
- raise "Unknown value %p for :wrap" % element
107
- end
108
- @wrapped_in = element
109
- self
110
- end
111
-
112
- def wrap *args
113
- clone.wrap!(*args)
114
- end
115
-
116
- def stylesheet in_tag = false
117
- Output.make_stylesheet @css, in_tag
118
- end
119
-
120
- class Template < String
121
-
122
- def self.wrap! str, template, target
123
- target = Regexp.new(Regexp.escape("<%#{target}%>"))
124
- if template =~ target
125
- str[0,0] = $`
126
- str << $'
127
- else
128
- raise "Template target <%%%p%%> not found" % target
129
- end
130
- end
131
-
132
- def apply target, replacement
133
- target = Regexp.new(Regexp.escape("<%#{target}%>"))
134
- if self =~ target
135
- Template.new($` + replacement + $')
136
- else
137
- raise "Template target <%%%p%%> not found" % target
138
- end
139
- end
140
-
141
- module Simple
142
- def ` str #`
143
- Template.new str
144
- end
145
- end
146
- end
147
-
148
- extend Template::Simple
149
-
150
- #-- don't include the templates in docu
151
-
152
- SPAN = `<span class="CodeRay"><%CONTENT%></span>`
153
-
154
- DIV = <<-`DIV`
155
- <div class="CodeRay">
156
- <div class="code"><pre><%CONTENT%></pre></div>
157
- </div>
158
- DIV
159
-
160
- TABLE = <<-`TABLE`
161
- <table class="CodeRay"><tr>
162
- <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><%LINE_NUMBERS%></pre></td>
163
- <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><%CONTENT%></pre></td>
164
- </tr></table>
165
- TABLE
166
- # title="double click to expand"
167
-
168
- LIST = <<-`LIST`
169
- <ol class="CodeRay"><%CONTENT%></ol>
170
- LIST
171
-
172
- PAGE = <<-`PAGE`
173
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
174
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
175
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">
176
- <head>
177
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
178
- <title>CodeRay HTML Encoder Example</title>
179
- <style type="text/css">
180
- <%CSS%>
181
- </style>
182
- </head>
183
- <body style="background-color: white;">
184
-
185
- <%CONTENT%>
186
- </body>
187
- </html>
188
- PAGE
189
-
190
- end
191
-
192
- end
193
-
194
- end
195
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ class HTML
5
+
6
+ # This module is included in the output String from thew HTML Encoder.
7
+ #
8
+ # It provides methods like wrap, div, page etc.
9
+ #
10
+ # Remember to use #clone instead of #dup to keep the modules the object was
11
+ # extended with.
12
+ #
13
+ # TODO: more doc.
14
+ module Output
15
+
16
+ require 'coderay/encoders/html/numerization.rb'
17
+
18
+ attr_accessor :css
19
+
20
+ class << self
21
+
22
+ # This makes Output look like a class.
23
+ #
24
+ # Example:
25
+ #
26
+ # a = Output.new '<span class="co">Code</span>'
27
+ # a.wrap! :page
28
+ def new string, css = CSS.new, element = nil
29
+ output = string.clone.extend self
30
+ output.wrapped_in = element
31
+ output.css = css
32
+ output
33
+ end
34
+
35
+ # Raises an exception if an object that doesn't respond to to_str is extended by Output,
36
+ # to prevent users from misuse. Use Module#remove_method to disable.
37
+ def extended o
38
+ warn "The Output module is intended to extend instances of String, not #{o.class}." unless o.respond_to? :to_str
39
+ end
40
+
41
+ def make_stylesheet css, in_tag = false
42
+ sheet = css.stylesheet
43
+ sheet = <<-CSS if in_tag
44
+ <style type="text/css">
45
+ #{sheet}
46
+ </style>
47
+ CSS
48
+ sheet
49
+ end
50
+
51
+ def page_template_for_css css
52
+ sheet = make_stylesheet css
53
+ PAGE.apply 'CSS', sheet
54
+ end
55
+
56
+ # Define a new wrapper. This is meta programming.
57
+ def wrapper *wrappers
58
+ wrappers.each do |wrapper|
59
+ define_method wrapper do |*args|
60
+ wrap wrapper, *args
61
+ end
62
+ define_method "#{wrapper}!".to_sym do |*args|
63
+ wrap! wrapper, *args
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ wrapper :div, :span, :page
71
+
72
+ def wrapped_in? element
73
+ wrapped_in == element
74
+ end
75
+
76
+ def wrapped_in
77
+ @wrapped_in ||= nil
78
+ end
79
+ attr_writer :wrapped_in
80
+
81
+ def wrap_in template
82
+ clone.wrap_in! template
83
+ end
84
+
85
+ def wrap_in! template
86
+ Template.wrap! self, template, 'CONTENT'
87
+ self
88
+ end
89
+
90
+ def wrap! element, *args
91
+ return self if not element or element == wrapped_in
92
+ case element
93
+ when :div
94
+ raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
95
+ wrap_in! DIV
96
+ when :span
97
+ raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
98
+ wrap_in! SPAN
99
+ when :page
100
+ wrap! :div if wrapped_in? nil
101
+ raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? :div
102
+ wrap_in! Output.page_template_for_css(@css)
103
+ when nil
104
+ return self
105
+ else
106
+ raise "Unknown value %p for :wrap" % element
107
+ end
108
+ @wrapped_in = element
109
+ self
110
+ end
111
+
112
+ def wrap *args
113
+ clone.wrap!(*args)
114
+ end
115
+
116
+ def stylesheet in_tag = false
117
+ Output.make_stylesheet @css, in_tag
118
+ end
119
+
120
+ class Template < String
121
+
122
+ def self.wrap! str, template, target
123
+ target = Regexp.new(Regexp.escape("<%#{target}%>"))
124
+ if template =~ target
125
+ str[0,0] = $`
126
+ str << $'
127
+ else
128
+ raise "Template target <%%%p%%> not found" % target
129
+ end
130
+ end
131
+
132
+ def apply target, replacement
133
+ target = Regexp.new(Regexp.escape("<%#{target}%>"))
134
+ if self =~ target
135
+ Template.new($` + replacement + $')
136
+ else
137
+ raise "Template target <%%%p%%> not found" % target
138
+ end
139
+ end
140
+
141
+ module Simple
142
+ def ` str #` <-- for stupid editors
143
+ Template.new str
144
+ end
145
+ end
146
+ end
147
+
148
+ extend Template::Simple
149
+
150
+ #-- don't include the templates in docu
151
+
152
+ SPAN = `<span class="CodeRay"><%CONTENT%></span>`
153
+
154
+ DIV = <<-`DIV`
155
+ <div class="CodeRay">
156
+ <div class="code"><pre><%CONTENT%></pre></div>
157
+ </div>
158
+ DIV
159
+
160
+ TABLE = <<-`TABLE`
161
+ <table class="CodeRay"><tr>
162
+ <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><%LINE_NUMBERS%></pre></td>
163
+ <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><%CONTENT%></pre></td>
164
+ </tr></table>
165
+ TABLE
166
+ # title="double click to expand"
167
+
168
+ LIST = <<-`LIST`
169
+ <ol class="CodeRay"><%CONTENT%></ol>
170
+ LIST
171
+
172
+ PAGE = <<-`PAGE`
173
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
174
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
175
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">
176
+ <head>
177
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
178
+ <title>CodeRay HTML Encoder Example</title>
179
+ <style type="text/css">
180
+ <%CSS%>
181
+ </style>
182
+ </head>
183
+ <body style="background-color: white;">
184
+
185
+ <%CONTENT%>
186
+ </body>
187
+ </html>
188
+ PAGE
189
+
190
+ end
191
+
192
+ end
193
+
194
+ end
195
+ end
@@ -1,26 +1,26 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- # = Null Encoder
5
- #
6
- # Does nothing and returns an empty string.
7
- class Null < Encoder
8
-
9
- include Streamable
10
- register_for :null
11
-
12
- # Defined for faster processing
13
- def to_proc
14
- proc {}
15
- end
16
-
17
- protected
18
-
19
- def token(*)
20
- # do nothing
21
- end
22
-
23
- end
24
-
25
- end
26
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # = Null Encoder
5
+ #
6
+ # Does nothing and returns an empty string.
7
+ class Null < Encoder
8
+
9
+ include Streamable
10
+ register_for :null
11
+
12
+ # Defined for faster processing
13
+ def to_proc
14
+ proc {}
15
+ end
16
+
17
+ protected
18
+
19
+ def token(*)
20
+ # do nothing
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -1,21 +1,21 @@
1
- module CodeRay
2
- module Encoders
3
-
4
- load :html
5
-
6
- class Page < HTML
7
-
8
- FILE_EXTENSION = 'html'
9
-
10
- register_for :page
11
-
12
- DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
13
- :css => :class,
14
- :wrap => :page,
15
- :line_numbers => :table
16
- })
17
-
18
- end
19
-
20
- end
21
- end
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ load :html
5
+
6
+ class Page < HTML
7
+
8
+ FILE_EXTENSION = 'html'
9
+
10
+ register_for :page
11
+
12
+ DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
13
+ :css => :class,
14
+ :wrap => :page,
15
+ :line_numbers => :table
16
+ })
17
+
18
+ end
19
+
20
+ end
21
+ end