coderay-beta 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/FOLDERS +53 -0
  2. data/LICENSE +504 -0
  3. data/bin/coderay +82 -0
  4. data/bin/coderay_stylesheet +4 -0
  5. data/lib/README +129 -0
  6. data/lib/coderay.rb +320 -0
  7. data/lib/coderay/duo.rb +85 -0
  8. data/lib/coderay/encoder.rb +213 -0
  9. data/lib/coderay/encoders/_map.rb +11 -0
  10. data/lib/coderay/encoders/comment_filter.rb +43 -0
  11. data/lib/coderay/encoders/count.rb +21 -0
  12. data/lib/coderay/encoders/debug.rb +49 -0
  13. data/lib/coderay/encoders/div.rb +19 -0
  14. data/lib/coderay/encoders/filter.rb +75 -0
  15. data/lib/coderay/encoders/html.rb +305 -0
  16. data/lib/coderay/encoders/html/css.rb +70 -0
  17. data/lib/coderay/encoders/html/numerization.rb +133 -0
  18. data/lib/coderay/encoders/html/output.rb +206 -0
  19. data/lib/coderay/encoders/json.rb +69 -0
  20. data/lib/coderay/encoders/lines_of_code.rb +90 -0
  21. data/lib/coderay/encoders/null.rb +26 -0
  22. data/lib/coderay/encoders/page.rb +20 -0
  23. data/lib/coderay/encoders/span.rb +19 -0
  24. data/lib/coderay/encoders/statistic.rb +77 -0
  25. data/lib/coderay/encoders/term.rb +137 -0
  26. data/lib/coderay/encoders/text.rb +32 -0
  27. data/lib/coderay/encoders/token_class_filter.rb +84 -0
  28. data/lib/coderay/encoders/xml.rb +71 -0
  29. data/lib/coderay/encoders/yaml.rb +22 -0
  30. data/lib/coderay/for_redcloth.rb +85 -0
  31. data/lib/coderay/helpers/file_type.rb +240 -0
  32. data/lib/coderay/helpers/gzip_simple.rb +123 -0
  33. data/lib/coderay/helpers/plugin.rb +349 -0
  34. data/lib/coderay/helpers/word_list.rb +138 -0
  35. data/lib/coderay/scanner.rb +284 -0
  36. data/lib/coderay/scanners/_map.rb +23 -0
  37. data/lib/coderay/scanners/c.rb +203 -0
  38. data/lib/coderay/scanners/cpp.rb +228 -0
  39. data/lib/coderay/scanners/css.rb +210 -0
  40. data/lib/coderay/scanners/debug.rb +62 -0
  41. data/lib/coderay/scanners/delphi.rb +150 -0
  42. data/lib/coderay/scanners/diff.rb +105 -0
  43. data/lib/coderay/scanners/groovy.rb +263 -0
  44. data/lib/coderay/scanners/html.rb +182 -0
  45. data/lib/coderay/scanners/java.rb +176 -0
  46. data/lib/coderay/scanners/java/builtin_types.rb +419 -0
  47. data/lib/coderay/scanners/java_script.rb +224 -0
  48. data/lib/coderay/scanners/json.rb +112 -0
  49. data/lib/coderay/scanners/nitro_xhtml.rb +136 -0
  50. data/lib/coderay/scanners/php.rb +526 -0
  51. data/lib/coderay/scanners/plaintext.rb +21 -0
  52. data/lib/coderay/scanners/python.rb +285 -0
  53. data/lib/coderay/scanners/rhtml.rb +74 -0
  54. data/lib/coderay/scanners/ruby.rb +404 -0
  55. data/lib/coderay/scanners/ruby/patterns.rb +238 -0
  56. data/lib/coderay/scanners/scheme.rb +145 -0
  57. data/lib/coderay/scanners/sql.rb +162 -0
  58. data/lib/coderay/scanners/xml.rb +17 -0
  59. data/lib/coderay/scanners/yaml.rb +144 -0
  60. data/lib/coderay/style.rb +20 -0
  61. data/lib/coderay/styles/_map.rb +7 -0
  62. data/lib/coderay/styles/cycnus.rb +151 -0
  63. data/lib/coderay/styles/murphy.rb +132 -0
  64. data/lib/coderay/token_classes.rb +86 -0
  65. data/lib/coderay/tokens.rb +391 -0
  66. data/lib/term/ansicolor.rb +220 -0
  67. metadata +123 -0
@@ -0,0 +1,17 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :html
5
+
6
+ # XML Scanner
7
+ #
8
+ # Currently this is the same scanner as Scanners::HTML.
9
+ class XML < HTML
10
+
11
+ register_for :xml
12
+ file_extension 'xml'
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,144 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # YAML Scanner
5
+ #
6
+ # Based on the YAML scanner from Syntax by Jamis Buck.
7
+ class YAML < Scanner
8
+
9
+ register_for :yaml
10
+ file_extension 'yml'
11
+
12
+ KINDS_NOT_LOC = :all
13
+
14
+ def scan_tokens tokens, options
15
+
16
+ value_expected = nil
17
+ state = :initial
18
+ key_indent = indent = 0
19
+
20
+ until eos?
21
+
22
+ kind = nil
23
+ match = nil
24
+
25
+ if bol?
26
+ key_indent = nil
27
+ if $DEBUG
28
+ indent = check(/ +/) ? matched.size : 0
29
+ tokens << [indent.to_s, :debug]
30
+ end
31
+ end
32
+
33
+ if match = scan(/ +[\t ]*/)
34
+ kind = :space
35
+
36
+ elsif match = scan(/\n+/)
37
+ kind = :space
38
+ state = :initial if match.index(?\n)
39
+
40
+ elsif match = scan(/#.*/)
41
+ kind = :comment
42
+
43
+ elsif bol? and case
44
+ when match = scan(/---|\.\.\./)
45
+ tokens << [:open, :head]
46
+ tokens << [match, :head]
47
+ tokens << [:close, :head]
48
+ next
49
+ when match = scan(/%.*/)
50
+ tokens << [match, :doctype]
51
+ next
52
+ end
53
+
54
+ elsif state == :value and case
55
+ when !check(/(?:"[^"]*")(?=: |:$)/) && scan(/"/)
56
+ tokens << [:open, :string]
57
+ tokens << [matched, :delimiter]
58
+ tokens << [matched, :content] if scan(/ [^"\\]* (?: \\. [^"\\]* )* /mx)
59
+ tokens << [matched, :delimiter] if scan(/"/)
60
+ tokens << [:close, :string]
61
+ next
62
+ when match = scan(/[|>][-+]?/)
63
+ tokens << [:open, :string]
64
+ tokens << [match, :delimiter]
65
+ string_indent = key_indent || column(pos - match.size - 1)
66
+ tokens << [matched, :content] if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
67
+ tokens << [:close, :string]
68
+ next
69
+ when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
70
+ tokens << [match, :string]
71
+ string_indent = key_indent || column(pos - match.size - 1)
72
+ tokens << [matched, :string] if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
73
+ next
74
+ end
75
+
76
+ elsif case
77
+ when match = scan(/[-:](?= |$)/)
78
+ state = :value if state == :colon && (match == ':' || match == '-')
79
+ state = :value if state == :initial && match == '-'
80
+ kind = :operator
81
+ when match = scan(/[,{}\[\]]/)
82
+ kind = :operator
83
+ when state == :initial && match = scan(/[\w.() ]*\S(?=: |:$)/)
84
+ kind = :key
85
+ key_indent = column(pos - match.size - 1)
86
+ # tokens << [key_indent.inspect, :debug]
87
+ state = :colon
88
+ when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?=: |:$)/)
89
+ tokens << [:open, :key]
90
+ tokens << [match[0,1], :delimiter]
91
+ tokens << [match[1..-2], :content]
92
+ tokens << [match[-1,1], :delimiter]
93
+ tokens << [:close, :key]
94
+ key_indent = column(pos - match.size - 1)
95
+ # tokens << [key_indent.inspect, :debug]
96
+ state = :colon
97
+ next
98
+ when scan(/(![\w\/]+)(:([\w:]+))?/)
99
+ tokens << [self[1], :type]
100
+ if self[2]
101
+ tokens << [':', :operator]
102
+ tokens << [self[3], :class]
103
+ end
104
+ next
105
+ when scan(/&\S+/)
106
+ kind = :variable
107
+ when scan(/\*\w+/)
108
+ kind = :global_variable
109
+ when scan(/<</)
110
+ kind = :class_variable
111
+ when scan(/\d\d:\d\d:\d\d/)
112
+ kind = :oct
113
+ when scan(/\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d+)? [-+]\d\d:\d\d/)
114
+ kind = :oct
115
+ when scan(/:\w+/)
116
+ kind = :symbol
117
+ when scan(/[^:\s]+(:(?! |$)[^:\s]*)* .*/)
118
+ kind = :error
119
+ when scan(/[^:\s]+(:(?! |$)[^:\s]*)*/)
120
+ kind = :error
121
+ end
122
+
123
+ else
124
+ getch
125
+ kind = :error
126
+
127
+ end
128
+
129
+ match ||= matched
130
+
131
+ raise_inspect 'Error token %p in line %d' % [[match, kind], line], tokens if $DEBUG && !kind
132
+ raise_inspect 'Empty token', tokens unless match
133
+
134
+ tokens << [match, kind]
135
+
136
+ end
137
+
138
+ tokens
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+ end
@@ -0,0 +1,20 @@
1
+ module CodeRay
2
+
3
+ # This module holds the Style class and its subclasses.
4
+ #
5
+ # See Plugin.
6
+ module Styles
7
+ extend PluginHost
8
+ plugin_path File.dirname(__FILE__), 'styles'
9
+
10
+ class Style
11
+ extend Plugin
12
+ plugin_host Styles
13
+
14
+ DEFAULT_OPTIONS = { }
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,7 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ default :cycnus
5
+
6
+ end
7
+ end
@@ -0,0 +1,151 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ class Cycnus < Style
5
+
6
+ register_for :cycnus
7
+
8
+ code_background = '#f8f8f8'
9
+ numbers_background = '#def'
10
+ border_color = 'silver'
11
+ normal_color = '#000'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
+ .CodeRay {
15
+ background-color: #{code_background};
16
+ border: 1px solid #{border_color};
17
+ font-family: 'Courier New', 'Terminal', monospace;
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre { margin: 0px }
21
+
22
+ div.CodeRay { }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top }
28
+
29
+ .CodeRay .line_numbers, .CodeRay .no {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
33
+ }
34
+ .CodeRay .line_numbers tt { font-weight: bold }
35
+ .CodeRay .line_numbers .highlighted { color: red }
36
+ .CodeRay .no { padding: 0px 4px }
37
+ .CodeRay .code { width: 100% }
38
+
39
+ ol.CodeRay { font-size: 10pt }
40
+ ol.CodeRay li { white-space: pre }
41
+
42
+ .CodeRay .code pre { overflow: auto }
43
+ MAIN
44
+
45
+ TOKEN_COLORS = <<-'TOKENS'
46
+ .debug { color:white ! important; background:blue ! important; }
47
+
48
+ .af { color:#00C }
49
+ .an { color:#007 }
50
+ .at { color:#f08 }
51
+ .av { color:#700 }
52
+ .aw { color:#C00 }
53
+ .bi { color:#509; font-weight:bold }
54
+ .c { color:#888; }
55
+
56
+ .ch { color:#04D }
57
+ .ch .k { color:#04D }
58
+ .ch .dl { color:#039 }
59
+
60
+ .cl { color:#B06; font-weight:bold }
61
+ .cm { color:#A08; font-weight:bold }
62
+ .co { color:#036; font-weight:bold }
63
+ .cr { color:#0A0 }
64
+ .cv { color:#369 }
65
+ .de { color:#B0B; }
66
+ .df { color:#099; font-weight:bold }
67
+ .di { color:#088; font-weight:bold }
68
+ .dl { color:black }
69
+ .do { color:#970 }
70
+ .dt { color:#34b }
71
+ .ds { color:#D42; font-weight:bold }
72
+ .e { color:#666; font-weight:bold }
73
+ .en { color:#800; font-weight:bold }
74
+ .er { color:#F00; background-color:#FAA }
75
+ .ex { color:#C00; font-weight:bold }
76
+ .fl { color:#60E; font-weight:bold }
77
+ .fu { color:#06B; font-weight:bold }
78
+ .gv { color:#d70; font-weight:bold }
79
+ .hx { color:#058; font-weight:bold }
80
+ .i { color:#00D; font-weight:bold }
81
+ .ic { color:#B44; font-weight:bold }
82
+
83
+ .il { background: #ddd; color: black }
84
+ .il .il { background: #ccc }
85
+ .il .il .il { background: #bbb }
86
+ .il .idl { background: #ddd; font-weight: bold; color: #666 }
87
+ .idl { background-color: #bbb; font-weight: bold; color: #666; }
88
+
89
+ .im { color:#f00; }
90
+ .in { color:#B2B; font-weight:bold }
91
+ .iv { color:#33B }
92
+ .la { color:#970; font-weight:bold }
93
+ .lv { color:#963 }
94
+ .oc { color:#40E; font-weight:bold }
95
+ .of { color:#000; font-weight:bold }
96
+ .op { }
97
+ .pc { color:#038; font-weight:bold }
98
+ .pd { color:#369; font-weight:bold }
99
+ .pp { color:#579; }
100
+ .ps { color:#00C; font-weight:bold }
101
+ .pt { color:#074; font-weight:bold }
102
+ .r, .kw { color:#080; font-weight:bold }
103
+
104
+ .ke { color: #808; }
105
+ .ke .dl { color: #606; }
106
+ .ke .ch { color: #80f; }
107
+ .vl { color: #088; }
108
+
109
+ .rx { background-color:#fff0ff }
110
+ .rx .k { color:#808 }
111
+ .rx .dl { color:#404 }
112
+ .rx .mod { color:#C2C }
113
+ .rx .fu { color:#404; font-weight: bold }
114
+
115
+ .s { background-color:#fff0f0; color: #D20; }
116
+ .s .s { background-color:#ffe0e0 }
117
+ .s .s .s { background-color:#ffd0d0 }
118
+ .s .k { }
119
+ .s .ch { color: #b0b; }
120
+ .s .dl { color: #710; }
121
+
122
+ .sh { background-color:#f0fff0; color:#2B2 }
123
+ .sh .k { }
124
+ .sh .dl { color:#161 }
125
+
126
+ .sy { color:#A60 }
127
+ .sy .k { color:#A60 }
128
+ .sy .dl { color:#630 }
129
+
130
+ .ta { color:#070 }
131
+ .tf { color:#070; font-weight:bold }
132
+ .ts { color:#D70; font-weight:bold }
133
+ .ty { color:#339; font-weight:bold }
134
+ .v { color:#036 }
135
+ .xt { color:#444 }
136
+
137
+ .ins { background: #afa; }
138
+ .del { background: #faa; }
139
+ .chg { color: #aaf; background: #007; }
140
+ .head { color: #f8f; background: #505 }
141
+
142
+ .ins .ins { color: #080; font-weight:bold }
143
+ .del .del { color: #800; font-weight:bold }
144
+ .chg .chg { color: #66f; }
145
+ .head .head { color: #f4f; }
146
+ TOKENS
147
+
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,132 @@
1
+ module CodeRay
2
+ module Styles
3
+
4
+ class Murphy < Style
5
+
6
+ register_for :murphy
7
+
8
+ code_background = '#001129'
9
+ numbers_background = code_background
10
+ border_color = 'silver'
11
+ normal_color = '#C0C0C0'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
+ .CodeRay {
15
+ background-color: #{code_background};
16
+ border: 1px solid #{border_color};
17
+ font-family: 'Courier New', 'Terminal', monospace;
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre { margin: 0px; }
21
+
22
+ div.CodeRay { }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
28
+
29
+ .CodeRay .line_numbers, .CodeRay .no {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
33
+ }
34
+ .CodeRay .line_numbers tt { font-weight: bold; }
35
+ .CodeRay .no { padding: 0px 4px; }
36
+ .CodeRay .code { width: 100%; }
37
+
38
+ ol.CodeRay { font-size: 10pt; }
39
+ ol.CodeRay li { white-space: pre; }
40
+
41
+ .CodeRay .code pre { overflow: auto; }
42
+ MAIN
43
+
44
+ TOKEN_COLORS = <<-'TOKENS'
45
+ .af { color:#00C; }
46
+ .an { color:#007; }
47
+ .av { color:#700; }
48
+ .aw { color:#C00; }
49
+ .bi { color:#509; font-weight:bold; }
50
+ .c { color:#555; background-color: black; }
51
+
52
+ .ch { color:#88F; }
53
+ .ch .k { color:#04D; }
54
+ .ch .dl { color:#039; }
55
+
56
+ .cl { color:#e9e; font-weight:bold; }
57
+ .co { color:#5ED; font-weight:bold; }
58
+ .cr { color:#0A0; }
59
+ .cv { color:#ccf; }
60
+ .df { color:#099; font-weight:bold; }
61
+ .di { color:#088; font-weight:bold; }
62
+ .dl { color:black; }
63
+ .do { color:#970; }
64
+ .ds { color:#D42; font-weight:bold; }
65
+ .e { color:#666; font-weight:bold; }
66
+ .er { color:#F00; background-color:#FAA; }
67
+ .ex { color:#F00; font-weight:bold; }
68
+ .fl { color:#60E; font-weight:bold; }
69
+ .fu { color:#5ed; font-weight:bold; }
70
+ .gv { color:#f84; }
71
+ .hx { color:#058; font-weight:bold; }
72
+ .i { color:#66f; font-weight:bold; }
73
+ .ic { color:#B44; font-weight:bold; }
74
+ .il { }
75
+ .in { color:#B2B; font-weight:bold; }
76
+ .iv { color:#aaf; }
77
+ .la { color:#970; font-weight:bold; }
78
+ .lv { color:#963; }
79
+ .oc { color:#40E; font-weight:bold; }
80
+ .of { color:#000; font-weight:bold; }
81
+ .op { }
82
+ .pc { color:#08f; font-weight:bold; }
83
+ .pd { color:#369; font-weight:bold; }
84
+ .pp { color:#579; }
85
+ .pt { color:#66f; font-weight:bold; }
86
+ .r { color:#5de; font-weight:bold; }
87
+ .r, .kw { color:#5de; font-weight:bold }
88
+
89
+ .ke { color: #808; }
90
+
91
+ .rx { background-color:#221133; }
92
+ .rx .k { color:#f8f; }
93
+ .rx .dl { color:#f0f; }
94
+ .rx .mod { color:#f0b; }
95
+ .rx .fu { color:#404; font-weight: bold; }
96
+
97
+ .s { background-color:#331122; }
98
+ .s .s { background-color:#ffe0e0; }
99
+ .s .s .s { background-color:#ffd0d0; }
100
+ .s .k { color:#F88; }
101
+ .s .dl { color:#f55; }
102
+
103
+ .sh { background-color:#f0fff0; }
104
+ .sh .k { color:#2B2; }
105
+ .sh .dl { color:#161; }
106
+
107
+ .sy { color:#Fc8; }
108
+ .sy .k { color:#Fc8; }
109
+ .sy .dl { color:#F84; }
110
+
111
+ .ta { color:#070; }
112
+ .tf { color:#070; font-weight:bold; }
113
+ .ts { color:#D70; font-weight:bold; }
114
+ .ty { color:#339; font-weight:bold; }
115
+ .v { color:#036; }
116
+ .xt { color:#444; }
117
+
118
+ .ins { background: #afa; }
119
+ .del { background: #faa; }
120
+ .chg { color: #aaf; background: #007; }
121
+ .head { color: #f8f; background: #505 }
122
+
123
+ .ins .ins { color: #080; font-weight:bold }
124
+ .del .del { color: #800; font-weight:bold }
125
+ .chg .chg { color: #66f; }
126
+ .head .head { color: #f4f; }
127
+ TOKENS
128
+
129
+ end
130
+
131
+ end
132
+ end