coderay 0.7.4.215 → 0.8.260

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/LICENSE +421 -257
  2. data/README +24 -13
  3. data/bin/coderay +9 -4
  4. data/lib/coderay.rb +19 -17
  5. data/lib/coderay/duo.rb +67 -9
  6. data/lib/coderay/encoder.rb +18 -9
  7. data/lib/coderay/encoders/_map.rb +2 -1
  8. data/lib/coderay/encoders/debug.rb +14 -11
  9. data/lib/coderay/encoders/html.rb +44 -17
  10. data/lib/coderay/encoders/html/css.rb +13 -8
  11. data/lib/coderay/encoders/html/numerization.rb +8 -6
  12. data/lib/coderay/encoders/html/output.rb +3 -1
  13. data/lib/coderay/encoders/statistic.rb +2 -6
  14. data/lib/coderay/encoders/text.rb +2 -3
  15. data/lib/coderay/encoders/tokens.rb +3 -3
  16. data/lib/coderay/encoders/xml.rb +1 -2
  17. data/lib/coderay/for_redcloth.rb +72 -0
  18. data/lib/coderay/helpers/file_type.rb +38 -9
  19. data/lib/coderay/helpers/gzip_simple.rb +1 -0
  20. data/lib/coderay/helpers/plugin.rb +15 -8
  21. data/lib/coderay/helpers/word_list.rb +4 -0
  22. data/lib/coderay/scanner.rb +30 -13
  23. data/lib/coderay/scanners/_map.rb +1 -1
  24. data/lib/coderay/scanners/c.rb +3 -1
  25. data/lib/coderay/scanners/css.rb +181 -0
  26. data/lib/coderay/scanners/debug.rb +1 -0
  27. data/lib/coderay/scanners/delphi.rb +1 -0
  28. data/lib/coderay/scanners/diff.rb +104 -0
  29. data/lib/coderay/scanners/java.rb +179 -0
  30. data/lib/coderay/scanners/java/builtin_types.rb +419 -0
  31. data/lib/coderay/scanners/java_script.rb +187 -0
  32. data/lib/coderay/scanners/json.rb +106 -0
  33. data/lib/coderay/scanners/nitro_xhtml.rb +5 -4
  34. data/lib/coderay/scanners/plaintext.rb +2 -0
  35. data/lib/coderay/scanners/rhtml.rb +2 -2
  36. data/lib/coderay/scanners/ruby.rb +64 -50
  37. data/lib/coderay/scanners/ruby/patterns.rb +15 -19
  38. data/lib/coderay/scanners/scheme.rb +142 -0
  39. data/lib/coderay/scanners/sql.Keith.rb +143 -0
  40. data/lib/coderay/scanners/sql.rb +154 -0
  41. data/lib/coderay/scanners/xml.rb +1 -0
  42. data/lib/coderay/styles/cycnus.rb +30 -9
  43. data/lib/coderay/styles/murphy.rb +15 -2
  44. data/lib/coderay/{encoders/html/classes.rb → token_classes.rb} +14 -9
  45. data/lib/coderay/tokens.rb +33 -14
  46. data/lib/term/ansicolor.rb +220 -0
  47. metadata +62 -44
@@ -115,7 +115,7 @@ module CodeRay
115
115
  # tokens.each_text_token { |text, kind| text.replace html_escape(text) }
116
116
  def each_text_token
117
117
  each do |text, kind|
118
- next unless text.respond_to? :to_str
118
+ next unless text.is_a? ::String
119
119
  yield text, kind
120
120
  end
121
121
  end
@@ -200,25 +200,29 @@ module CodeRay
200
200
  #
201
201
  # TODO: Test this!
202
202
  def fix
203
+ tokens = self.class.new
203
204
  # Check token nesting using a stack of kinds.
204
205
  opened = []
205
- for token, kind in self
206
- if token == :open
207
- opened.push kind
208
- elsif token == :close
206
+ for type, kind in self
207
+ case type
208
+ when :open
209
+ opened.push [:close, kind]
210
+ when :begin_line
211
+ opened.push [:end_line, kind]
212
+ when :close, :end_line
209
213
  expected = opened.pop
210
- if kind != expected
214
+ if [type, kind] != expected
211
215
  # Unexpected :close; decide what to do based on the kind:
212
- # - token was opened earlier: also close tokens in between
213
- # - token was never opened: delete the :close (skip with next)
216
+ # - token was never opened: delete the :close (just skip it)
214
217
  next unless opened.rindex expected
215
- tokens << [:close, kind] until (kind = opened.pop) == expected
218
+ # - token was opened earlier: also close tokens in between
219
+ tokens << token until (token = opened.pop) == expected
216
220
  end
217
221
  end
218
- tokens << [token, kind]
222
+ tokens << [type, kind]
219
223
  end
220
224
  # Close remaining opened tokens
221
- tokens << [:close, kind] while kind = opened.pop
225
+ tokens << token while token = opened.pop
222
226
  tokens
223
227
  end
224
228
 
@@ -252,7 +256,7 @@ module CodeRay
252
256
  #
253
257
  # You can configure the level of compression,
254
258
  # but the default value 7 should be what you want
255
- # in most cases as it is a good comprimise between
259
+ # in most cases as it is a good compromise between
256
260
  # speed and compression rate.
257
261
  #
258
262
  # See GZip module.
@@ -267,7 +271,18 @@ module CodeRay
267
271
  # Should be equal to the input size before
268
272
  # scanning.
269
273
  def text_size
270
- map { |t, k| t }.join.size
274
+ size = 0
275
+ each_text_token do |t, k|
276
+ size + t.size
277
+ end
278
+ size
279
+ end
280
+
281
+ # The total size of the tokens.
282
+ # Should be equal to the input size before
283
+ # scanning.
284
+ def text
285
+ map { |t, k| t if t.is_a? ::String }.join
271
286
  end
272
287
 
273
288
  # Include this module to give an object an #undump
@@ -342,7 +357,7 @@ module CodeRay
342
357
  #
343
358
  # Returns self.
344
359
  def << token
345
- @callback.call token
360
+ @callback.call(*token)
346
361
  @size += 1
347
362
  self
348
363
  end
@@ -365,4 +380,8 @@ module CodeRay
365
380
 
366
381
  end
367
382
 
383
+
384
+ # Token name abbreviations
385
+ require 'coderay/token_classes'
386
+
368
387
  end
@@ -0,0 +1,220 @@
1
+ # = Term::ANSIColor - ANSI escape sequences in Ruby
2
+ #
3
+ # == Description
4
+ #
5
+ # This library can be used to color/uncolor strings using ANSI escape sequences.
6
+ #
7
+ # == Author
8
+ #
9
+ # Florian Frank mailto:flori@ping.de
10
+ #
11
+ # == License
12
+ #
13
+ # This is free software; you can redistribute it and/or modify it under the
14
+ # terms of the GNU General Public License Version 2 as published by the Free
15
+ # Software Foundation: www.gnu.org/copyleft/gpl.html
16
+ #
17
+ # == Download
18
+ #
19
+ # The latest version of this library can be downloaded at
20
+ #
21
+ # * http://rubyforge.org/frs?group_id=391
22
+ #
23
+ # The homepage of this library is located at
24
+ #
25
+ # * http://term-ansicolor.rubyforge.org
26
+ #
27
+ # == Examples
28
+ #
29
+ # The file examples/example.rb in the source/gem-distribution shows how
30
+ # this library can be used:
31
+ # require 'term/ansicolor'
32
+ #
33
+ # # Use this trick to work around namespace cluttering that
34
+ # # happens if you just include Term::ANSIColor:
35
+ #
36
+ # class Color
37
+ # class << self
38
+ # include Term::ANSIColor
39
+ # end
40
+ # end
41
+ #
42
+ # print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
43
+ # print Color.green + "green" + Color.clear, "\n"
44
+ # print Color.on_red(Color.green("green")), "\n"
45
+ # print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
46
+ #
47
+ # # Or shortcut Term::ANSIColor by assignment:
48
+ # c = Term::ANSIColor
49
+ #
50
+ # print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
51
+ # print c.green + "green" + c.clear, "\n"
52
+ # print c.on_red(c.green("green")), "\n"
53
+ # print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
54
+ #
55
+ # # Anyway, I don't define any of Term::ANSIColor's methods in this example
56
+ # # and I want to keep it short:
57
+ # include Term::ANSIColor
58
+ #
59
+ # print red, bold, "Usage as constants:", reset, "\n"
60
+ # print clear, "clear", reset, reset, "reset", reset,
61
+ # bold, "bold", reset, dark, "dark", reset,
62
+ # underscore, "underscore", reset, blink, "blink", reset,
63
+ # negative, "negative", reset, concealed, "concealed", reset, "|\n",
64
+ # black, "black", reset, red, "red", reset, green, "green", reset,
65
+ # yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
66
+ # cyan, "cyan", reset, white, "white", reset, "|\n",
67
+ # on_black, "on_black", reset, on_red, "on_red", reset,
68
+ # on_green, "on_green", reset, on_yellow, "on_yellow", reset,
69
+ # on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
70
+ # on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
71
+ #
72
+ # print red, bold, "Usage as unary argument methods:", reset, "\n"
73
+ # print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
74
+ # underscore("underscore"), blink("blink"), negative("negative"),
75
+ # concealed("concealed"), "|\n",
76
+ # black("black"), red("red"), green("green"), yellow("yellow"),
77
+ # blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
78
+ # on_black("on_black"), on_red("on_red"), on_green("on_green"),#
79
+ # on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
80
+ # on_cyan("on_cyan"), on_white("on_white"), "|\n\n"
81
+ #
82
+ # print red { bold { "Usage as block forms:" } }, "\n"
83
+ # print clear { "clear" }, reset { "reset" }, bold { "bold" },
84
+ # dark { "dark" }, underscore { "underscore" }, blink { "blink" },
85
+ # negative { "negative" }, concealed { "concealed" }, "|\n",
86
+ # black { "black" }, red { "red" }, green { "green" },
87
+ # yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
88
+ # cyan { "cyan" }, white { "white" }, "|\n",
89
+ # on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
90
+ # on_yellow { "on_yellow" }, on_blue { "on_blue" },
91
+ # on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
92
+ # on_white { "on_white" }, "|\n\n"
93
+ #
94
+ # # Usage as Mixin into String or its Subclasses
95
+ # class String
96
+ # include Term::ANSIColor
97
+ # end
98
+ #
99
+ # print "Usage as String Mixins:".red.bold, "\n"
100
+ # print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
101
+ # "underscore".underscore, "blink".blink, "negative".negative,
102
+ # "concealed".concealed, "|\n",
103
+ # "black".black, "red".red, "green".green, "yellow".yellow,
104
+ # "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
105
+ # "on_black".on_black, "on_red".on_red, "on_green".on_green,
106
+ # "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
107
+ # "on_cyan".on_cyan, "on_white".on_white, "|\n\n"
108
+ #
109
+ # symbols = Term::ANSIColor::attributes
110
+ # print red { bold { "All supported attributes = " } },
111
+ # blue { symbols.inspect }, "\n\n"
112
+ #
113
+ # print "Send symbols to strings:".send(:red).send(:bold), "\n"
114
+ # print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
115
+ #
116
+ # print red { bold { "Make strings monochromatic again:" } }, "\n"
117
+ # print [ "red".red, "not red anymore".red.uncolored,
118
+ # uncolored { "not red anymore".red }, uncolored("not red anymore".red)
119
+ # ].map { |x| x + "\n" }
120
+ module Term
121
+ # The ANSIColor module can be used for namespacing and mixed into your own
122
+ # classes.
123
+ module ANSIColor
124
+ # :stopdoc:
125
+ ATTRIBUTES = [
126
+ [ :clear , 0 ],
127
+ [ :reset , 0 ], # synonym for :clear
128
+ [ :bold , 1 ],
129
+ [ :dark , 2 ],
130
+ [ :italic , 3 ], # not widely implemented
131
+ [ :underline , 4 ],
132
+ [ :underscore , 4 ], # synonym for :underline
133
+ [ :blink , 5 ],
134
+ [ :rapid_blink , 6 ], # not widely implemented
135
+ [ :negative , 7 ], # no reverse because of String#reverse
136
+ [ :concealed , 8 ],
137
+ [ :strikethrough, 9 ], # not widely implemented
138
+ [ :black , 30 ],
139
+ [ :red , 31 ],
140
+ [ :green , 32 ],
141
+ [ :yellow , 33 ],
142
+ [ :blue , 34 ],
143
+ [ :magenta , 35 ],
144
+ [ :cyan , 36 ],
145
+ [ :white , 37 ],
146
+ [ :on_black , 40 ],
147
+ [ :on_red , 41 ],
148
+ [ :on_green , 42 ],
149
+ [ :on_yellow , 43 ],
150
+ [ :on_blue , 44 ],
151
+ [ :on_magenta , 45 ],
152
+ [ :on_cyan , 46 ],
153
+ [ :on_white , 47 ],
154
+ ]
155
+
156
+ ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
157
+ # :startdoc:
158
+
159
+ # Returns true, if the coloring function of this module
160
+ # is switched on, false otherwise.
161
+ def self.coloring?
162
+ @coloring
163
+ end
164
+
165
+ # Turns the coloring on or off globally, so you can easily do
166
+ # this for example:
167
+ # Term::ANSIColor::coloring = STDOUT.isatty
168
+ def self.coloring=(val)
169
+ @coloring = val
170
+ end
171
+ self.coloring = true
172
+
173
+ ATTRIBUTES.each do |c, v|
174
+ eval %Q{
175
+ def #{c}(string = nil)
176
+ result = ''
177
+ result << "\e[#{v}m" if Term::ANSIColor.coloring?
178
+ if block_given?
179
+ result << yield
180
+ elsif string
181
+ result << string
182
+ elsif respond_to?(:to_str)
183
+ result << self
184
+ else
185
+ return result #only switch on
186
+ end
187
+ result << "\e[0m" if Term::ANSIColor.coloring?
188
+ result
189
+ end
190
+ }
191
+ end
192
+
193
+ # Regular expression that is used to scan for ANSI-sequences while
194
+ # uncoloring strings.
195
+ COLORED_REGEXP = /\e\[([34][0-7]|[0-9])m/
196
+
197
+ # Returns an uncolored version of the string, that is all
198
+ # ANSI-sequences are stripped from the string.
199
+ def uncolored(string = nil) # :yields:
200
+ if block_given?
201
+ yield.gsub(COLORED_REGEXP, '')
202
+ elsif string
203
+ string.gsub(COLORED_REGEXP, '')
204
+ elsif respond_to?(:to_str)
205
+ gsub(COLORED_REGEXP, '')
206
+ else
207
+ ''
208
+ end
209
+ end
210
+
211
+ module_function
212
+
213
+ # Returns an array of all Term::ANSIColor attributes as symbols.
214
+ def attributes
215
+ ATTRIBUTE_NAMES
216
+ end
217
+ extend self
218
+ end
219
+ end
220
+ # vim: set et sw=2 ts=2:
metadata CHANGED
@@ -1,44 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: coderay
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.7.4.215
7
- date: 2006-10-20 00:00:00 +02:00
8
- summary: CodeRay is a fast syntax highlighter engine for many languages.
9
- require_paths:
10
- - lib
11
- email: murphy@cYcnus.de
12
- homepage: http://coderay.rubychan.de
13
- rubyforge_project: coderay
14
- description: "CodeRay is a Ruby library for syntax highlighting. I try to make CodeRay easy to use and intuitive, but at the same time fully featured, complete, fast and efficient. Usage is simple: require 'coderay' code = 'some %q(weird (Ruby) can't shock) me!' puts CodeRay.scan(code, :ruby).html"
15
- autorequire: coderay
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 0.8.260
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - murphy
8
+ autorequire: coderay
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-08 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "CodeRay is a Ruby library for syntax highlighting. I try to make CodeRay easy to use and intuitive, but at the same time fully featured, complete, fast and efficient. Usage is simple: require 'coderay' code = 'some %q(weird (Ruby) can't shock) me!' puts CodeRay.scan(code, :ruby).html"
17
+ email: murphy@cYcnus.de
18
+ executables:
19
+ - coderay
20
+ - coderay_stylesheet
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - ./README
25
+ - ./FOLDERS
31
26
  files:
32
- - ./lib/coderay.rb
33
27
  - ./lib/coderay/duo.rb
34
28
  - ./lib/coderay/encoder.rb
35
- - ./lib/coderay/scanner.rb
36
- - ./lib/coderay/style.rb
37
- - ./lib/coderay/tokens.rb
38
29
  - ./lib/coderay/encoders/_map.rb
39
30
  - ./lib/coderay/encoders/count.rb
40
31
  - ./lib/coderay/encoders/debug.rb
41
32
  - ./lib/coderay/encoders/div.rb
33
+ - ./lib/coderay/encoders/html/css.rb
34
+ - ./lib/coderay/encoders/html/numerization.rb
35
+ - ./lib/coderay/encoders/html/output.rb
42
36
  - ./lib/coderay/encoders/html.rb
43
37
  - ./lib/coderay/encoders/null.rb
44
38
  - ./lib/coderay/encoders/page.rb
@@ -48,47 +42,71 @@ files:
48
42
  - ./lib/coderay/encoders/tokens.rb
49
43
  - ./lib/coderay/encoders/xml.rb
50
44
  - ./lib/coderay/encoders/yaml.rb
51
- - ./lib/coderay/encoders/html/classes.rb
52
- - ./lib/coderay/encoders/html/css.rb
53
- - ./lib/coderay/encoders/html/numerization.rb
54
- - ./lib/coderay/encoders/html/output.rb
45
+ - ./lib/coderay/for_redcloth.rb
55
46
  - ./lib/coderay/helpers/file_type.rb
56
47
  - ./lib/coderay/helpers/gzip_simple.rb
57
48
  - ./lib/coderay/helpers/plugin.rb
58
49
  - ./lib/coderay/helpers/word_list.rb
50
+ - ./lib/coderay/scanner.rb
59
51
  - ./lib/coderay/scanners/_map.rb
60
52
  - ./lib/coderay/scanners/c.rb
53
+ - ./lib/coderay/scanners/css.rb
61
54
  - ./lib/coderay/scanners/debug.rb
62
55
  - ./lib/coderay/scanners/delphi.rb
56
+ - ./lib/coderay/scanners/diff.rb
63
57
  - ./lib/coderay/scanners/html.rb
58
+ - ./lib/coderay/scanners/java/builtin_types.rb
59
+ - ./lib/coderay/scanners/java.rb
60
+ - ./lib/coderay/scanners/java_script.rb
61
+ - ./lib/coderay/scanners/json.rb
64
62
  - ./lib/coderay/scanners/nitro_xhtml.rb
65
63
  - ./lib/coderay/scanners/plaintext.rb
66
64
  - ./lib/coderay/scanners/rhtml.rb
65
+ - ./lib/coderay/scanners/ruby/patterns.rb
67
66
  - ./lib/coderay/scanners/ruby.rb
67
+ - ./lib/coderay/scanners/scheme.rb
68
+ - ./lib/coderay/scanners/sql.Keith.rb
69
+ - ./lib/coderay/scanners/sql.rb
68
70
  - ./lib/coderay/scanners/xml.rb
69
- - ./lib/coderay/scanners/ruby/patterns.rb
71
+ - ./lib/coderay/style.rb
70
72
  - ./lib/coderay/styles/_map.rb
71
73
  - ./lib/coderay/styles/cycnus.rb
72
74
  - ./lib/coderay/styles/murphy.rb
75
+ - ./lib/coderay/token_classes.rb
76
+ - ./lib/coderay/tokens.rb
77
+ - ./lib/coderay.rb
78
+ - ./lib/term/ansicolor.rb
73
79
  - ./README
74
80
  - ./LICENSE
75
81
  - ./FOLDERS
76
- test_files: []
77
-
82
+ has_rdoc: true
83
+ homepage: http://coderay.rubychan.de
84
+ post_install_message:
78
85
  rdoc_options:
79
86
  - -SNw2
80
87
  - -mREADME
81
88
  - -a
82
89
  - -t CodeRay Documentation
83
- extra_rdoc_files:
84
- - ./README
85
- - ./FOLDERS
86
- executables:
87
- - coderay
88
- - coderay_stylesheet
89
- extensions: []
90
-
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.2
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
91
104
  requirements:
92
105
  - strscan
93
- dependencies: []
106
+ rubyforge_project: coderay
107
+ rubygems_version: 1.3.0
108
+ signing_key:
109
+ specification_version: 2
110
+ summary: CodeRay is a fast syntax highlighter engine for many languages.
111
+ test_files: []
94
112