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.
- data/bin/coderay +54 -56
- data/demo/suite.rb +54 -54
- data/lib/coderay.rb +187 -187
- data/lib/coderay/duo.rb +29 -29
- data/lib/coderay/encoder.rb +173 -173
- data/lib/coderay/encoders/_map.rb +8 -8
- data/lib/coderay/encoders/count.rb +21 -21
- data/lib/coderay/encoders/debug.rb +46 -46
- data/lib/coderay/encoders/div.rb +20 -20
- data/lib/coderay/encoders/html.rb +249 -245
- data/lib/coderay/encoders/html/classes.rb +73 -73
- data/lib/coderay/encoders/html/css.rb +65 -65
- data/lib/coderay/encoders/html/numerization.rb +122 -122
- data/lib/coderay/encoders/html/output.rb +195 -195
- data/lib/coderay/encoders/null.rb +26 -26
- data/lib/coderay/encoders/page.rb +21 -21
- data/lib/coderay/encoders/span.rb +20 -20
- data/lib/coderay/encoders/statistic.rb +81 -81
- data/lib/coderay/encoders/text.rb +33 -33
- data/lib/coderay/encoders/tokens.rb +44 -44
- data/lib/coderay/encoders/xml.rb +71 -71
- data/lib/coderay/encoders/yaml.rb +22 -22
- data/lib/coderay/helpers/filetype.rb +152 -153
- data/lib/coderay/helpers/gzip_simple.rb +67 -68
- data/lib/coderay/helpers/plugin.rb +297 -297
- data/lib/coderay/helpers/word_list.rb +46 -47
- data/lib/coderay/scanner.rb +238 -238
- data/lib/coderay/scanners/_map.rb +15 -14
- data/lib/coderay/scanners/c.rb +163 -155
- data/lib/coderay/scanners/delphi.rb +131 -129
- data/lib/coderay/scanners/html.rb +174 -167
- data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
- data/lib/coderay/scanners/plaintext.rb +15 -15
- data/lib/coderay/scanners/rhtml.rb +73 -65
- data/lib/coderay/scanners/ruby.rb +404 -397
- data/lib/coderay/scanners/ruby/patterns.rb +216 -216
- data/lib/coderay/scanners/xml.rb +18 -18
- data/lib/coderay/style.rb +20 -20
- data/lib/coderay/styles/_map.rb +3 -3
- data/lib/coderay/styles/cycnus.rb +18 -18
- data/lib/coderay/styles/murphy.rb +18 -18
- data/lib/coderay/tokens.rb +322 -322
- metadata +86 -86
- data/lib/coderay/scanners/nitro_html.rb +0 -125
- data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,195 +1,195 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
<style type="text/css">
|
45
|
-
#{sheet}
|
46
|
-
</style>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
#-- don't include the templates in docu
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
<div class="CodeRay">
|
156
|
-
|
157
|
-
</div>
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
<table class="CodeRay"><tr>
|
162
|
-
|
163
|
-
|
164
|
-
</tr></table>
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
<ol class="CodeRay"><%CONTENT%></ol>
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
174
|
-
|
175
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">
|
176
|
-
<head>
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
<%CSS%>
|
181
|
-
|
182
|
-
</head>
|
183
|
-
<body style="background-color: white;">
|
184
|
-
|
185
|
-
<%CONTENT%>
|
186
|
-
</body>
|
187
|
-
</html>
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|