coderay 0.9.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{lib/README → README_INDEX.rdoc} +10 -21
- data/Rakefile +6 -6
- data/bin/coderay +193 -64
- data/lib/coderay.rb +61 -105
- data/lib/coderay/duo.rb +17 -21
- data/lib/coderay/encoder.rb +100 -112
- data/lib/coderay/encoders/_map.rb +12 -7
- data/lib/coderay/encoders/comment_filter.rb +12 -30
- data/lib/coderay/encoders/count.rb +29 -11
- data/lib/coderay/encoders/debug.rb +32 -20
- data/lib/coderay/encoders/div.rb +13 -9
- data/lib/coderay/encoders/filter.rb +34 -51
- data/lib/coderay/encoders/html.rb +155 -161
- data/lib/coderay/encoders/html/css.rb +4 -9
- data/lib/coderay/encoders/html/numbering.rb +115 -0
- data/lib/coderay/encoders/html/output.rb +22 -70
- data/lib/coderay/encoders/json.rb +59 -45
- data/lib/coderay/encoders/lines_of_code.rb +12 -57
- data/lib/coderay/encoders/null.rb +6 -14
- data/lib/coderay/encoders/page.rb +13 -9
- data/lib/coderay/encoders/span.rb +13 -9
- data/lib/coderay/encoders/statistic.rb +58 -39
- data/lib/coderay/encoders/terminal.rb +179 -0
- data/lib/coderay/encoders/text.rb +31 -17
- data/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/lib/coderay/encoders/xml.rb +19 -18
- data/lib/coderay/encoders/yaml.rb +37 -9
- data/lib/coderay/for_redcloth.rb +4 -4
- data/lib/coderay/helpers/file_type.rb +127 -246
- data/lib/coderay/helpers/gzip.rb +41 -0
- data/lib/coderay/helpers/plugin.rb +241 -306
- data/lib/coderay/helpers/word_list.rb +65 -126
- data/lib/coderay/scanner.rb +173 -156
- data/lib/coderay/scanners/_map.rb +18 -17
- data/lib/coderay/scanners/c.rb +63 -77
- data/lib/coderay/scanners/clojure.rb +217 -0
- data/lib/coderay/scanners/cpp.rb +71 -84
- data/lib/coderay/scanners/css.rb +103 -120
- data/lib/coderay/scanners/debug.rb +47 -44
- data/lib/coderay/scanners/delphi.rb +70 -76
- data/lib/coderay/scanners/diff.rb +141 -50
- data/lib/coderay/scanners/erb.rb +81 -0
- data/lib/coderay/scanners/groovy.rb +104 -113
- data/lib/coderay/scanners/haml.rb +168 -0
- data/lib/coderay/scanners/html.rb +181 -110
- data/lib/coderay/scanners/java.rb +73 -75
- data/lib/coderay/scanners/java/builtin_types.rb +2 -0
- data/lib/coderay/scanners/java_script.rb +90 -101
- data/lib/coderay/scanners/json.rb +40 -53
- data/lib/coderay/scanners/php.rb +123 -147
- data/lib/coderay/scanners/python.rb +93 -91
- data/lib/coderay/scanners/raydebug.rb +66 -0
- data/lib/coderay/scanners/ruby.rb +343 -326
- data/lib/coderay/scanners/ruby/patterns.rb +40 -106
- data/lib/coderay/scanners/ruby/string_state.rb +71 -0
- data/lib/coderay/scanners/sql.rb +80 -66
- data/lib/coderay/scanners/text.rb +26 -0
- data/lib/coderay/scanners/xml.rb +1 -1
- data/lib/coderay/scanners/yaml.rb +74 -73
- data/lib/coderay/style.rb +10 -7
- data/lib/coderay/styles/_map.rb +3 -3
- data/lib/coderay/styles/alpha.rb +143 -0
- data/lib/coderay/token_kinds.rb +90 -0
- data/lib/coderay/tokens.rb +102 -277
- data/lib/coderay/tokens_proxy.rb +55 -0
- data/lib/coderay/version.rb +3 -0
- data/test/functional/basic.rb +200 -18
- data/test/functional/examples.rb +130 -0
- data/test/functional/for_redcloth.rb +15 -8
- data/test/functional/suite.rb +9 -6
- metadata +103 -123
- data/FOLDERS +0 -53
- data/bin/coderay_stylesheet +0 -4
- data/lib/coderay/encoders/html/numerization.rb +0 -133
- data/lib/coderay/encoders/term.rb +0 -158
- data/lib/coderay/encoders/token_class_filter.rb +0 -84
- data/lib/coderay/helpers/gzip_simple.rb +0 -123
- data/lib/coderay/scanners/nitro_xhtml.rb +0 -136
- data/lib/coderay/scanners/plaintext.rb +0 -20
- data/lib/coderay/scanners/rhtml.rb +0 -78
- data/lib/coderay/scanners/scheme.rb +0 -145
- data/lib/coderay/styles/cycnus.rb +0 -152
- data/lib/coderay/styles/murphy.rb +0 -134
- data/lib/coderay/token_classes.rb +0 -86
- data/test/functional/load_plugin_scanner.rb +0 -11
- data/test/functional/vhdl.rb +0 -126
- data/test/functional/word_list.rb +0 -79
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
|
2
|
+
require File.expand_path('../../lib/assert_warning', __FILE__)
|
3
|
+
|
4
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
3
5
|
require 'coderay'
|
4
6
|
|
5
7
|
begin
|
@@ -8,17 +10,18 @@ begin
|
|
8
10
|
require 'redcloth'
|
9
11
|
rescue LoadError
|
10
12
|
warn 'RedCloth not found - skipping for_redcloth tests.'
|
13
|
+
undef RedCloth if defined? RedCloth
|
11
14
|
end
|
12
15
|
|
13
16
|
class BasicTest < Test::Unit::TestCase
|
14
17
|
|
15
18
|
def test_for_redcloth
|
16
19
|
require 'coderay/for_redcloth'
|
17
|
-
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color
|
20
|
+
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:hsla(0,100%,50%,0.05)\"><span style=\"color:#710\">"</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">"</span></span></span></p>",
|
18
21
|
RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
|
19
22
|
assert_equal <<-BLOCKCODE.chomp,
|
20
23
|
<div lang="ruby" class="CodeRay">
|
21
|
-
<div class="code"><pre>puts <span style="background-color
|
24
|
+
<div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Hello, World!</span><span style="color:#710">"</span></span></pre></div>
|
22
25
|
</div>
|
23
26
|
BLOCKCODE
|
24
27
|
RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
|
@@ -63,15 +66,19 @@ class BasicTest < Test::Unit::TestCase
|
|
63
66
|
# See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
|
64
67
|
def test_for_redcloth_false_positive
|
65
68
|
require 'coderay/for_redcloth'
|
66
|
-
|
67
|
-
|
69
|
+
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
|
70
|
+
assert_equal '<p><code>[project]_dff.skjd</code></p>',
|
71
|
+
RedCloth.new('@[project]_dff.skjd@').to_html
|
72
|
+
end
|
68
73
|
# false positive, but expected behavior / known issue
|
69
74
|
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
|
70
75
|
RedCloth.new('@[ruby]_dff.skjd@').to_html
|
71
|
-
|
76
|
+
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
|
77
|
+
assert_equal <<-BLOCKCODE.chomp,
|
72
78
|
<pre><code>[project]_dff.skjd</code></pre>
|
73
|
-
|
74
|
-
|
79
|
+
BLOCKCODE
|
80
|
+
RedCloth.new('bc. [project]_dff.skjd').to_html
|
81
|
+
end
|
75
82
|
end
|
76
83
|
|
77
84
|
end if defined? RedCloth
|
data/test/functional/suite.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
$:.unshift 'lib'
|
3
|
+
$VERBOSE = $CODERAY_DEBUG = true
|
4
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
6
5
|
require 'coderay'
|
7
|
-
puts "Running basic CodeRay #{CodeRay::VERSION} tests..."
|
8
6
|
|
9
|
-
|
7
|
+
mydir = File.dirname(__FILE__)
|
8
|
+
suite = Dir[File.join(mydir, '*.rb')].
|
9
|
+
map { |tc| File.basename(tc).sub(/\.rb$/, '') } - %w'suite for_redcloth'
|
10
|
+
|
11
|
+
puts "Running basic CodeRay #{CodeRay::VERSION} tests: #{suite.join(', ')}"
|
12
|
+
|
10
13
|
for test_case in suite
|
11
|
-
load File.join(
|
14
|
+
load File.join(mydir, test_case + '.rb')
|
12
15
|
end
|
metadata
CHANGED
@@ -1,146 +1,126 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 8
|
10
|
-
version: 0.9.8
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Kornelius Kalnbach
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-05-01 00:00:00 Z
|
12
|
+
date: 2011-09-21 00:00:00.000000000Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
email: murphy@rubychan.de
|
26
|
-
executables:
|
14
|
+
description: Fast and easy syntax highlighting for selected languages, written in
|
15
|
+
Ruby. Comes with RedCloth integration and LOC counter.
|
16
|
+
email:
|
17
|
+
- murphy@rubychan.de
|
18
|
+
executables:
|
27
19
|
- coderay
|
28
|
-
- coderay_stylesheet
|
29
20
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
-
|
34
|
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
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
|
-
- ./LICENSE
|
104
|
-
- lib/README
|
105
|
-
- FOLDERS
|
21
|
+
extra_rdoc_files:
|
22
|
+
- README_INDEX.rdoc
|
23
|
+
files:
|
24
|
+
- LICENSE
|
25
|
+
- README_INDEX.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/coderay.rb
|
28
|
+
- lib/coderay/duo.rb
|
29
|
+
- lib/coderay/encoder.rb
|
30
|
+
- lib/coderay/encoders/_map.rb
|
31
|
+
- lib/coderay/encoders/comment_filter.rb
|
32
|
+
- lib/coderay/encoders/count.rb
|
33
|
+
- lib/coderay/encoders/debug.rb
|
34
|
+
- lib/coderay/encoders/div.rb
|
35
|
+
- lib/coderay/encoders/filter.rb
|
36
|
+
- lib/coderay/encoders/html.rb
|
37
|
+
- lib/coderay/encoders/html/css.rb
|
38
|
+
- lib/coderay/encoders/html/numbering.rb
|
39
|
+
- lib/coderay/encoders/html/output.rb
|
40
|
+
- lib/coderay/encoders/json.rb
|
41
|
+
- lib/coderay/encoders/lines_of_code.rb
|
42
|
+
- lib/coderay/encoders/null.rb
|
43
|
+
- lib/coderay/encoders/page.rb
|
44
|
+
- lib/coderay/encoders/span.rb
|
45
|
+
- lib/coderay/encoders/statistic.rb
|
46
|
+
- lib/coderay/encoders/terminal.rb
|
47
|
+
- lib/coderay/encoders/text.rb
|
48
|
+
- lib/coderay/encoders/token_kind_filter.rb
|
49
|
+
- lib/coderay/encoders/xml.rb
|
50
|
+
- lib/coderay/encoders/yaml.rb
|
51
|
+
- lib/coderay/for_redcloth.rb
|
52
|
+
- lib/coderay/helpers/file_type.rb
|
53
|
+
- lib/coderay/helpers/gzip.rb
|
54
|
+
- lib/coderay/helpers/plugin.rb
|
55
|
+
- lib/coderay/helpers/word_list.rb
|
56
|
+
- lib/coderay/scanner.rb
|
57
|
+
- lib/coderay/scanners/_map.rb
|
58
|
+
- lib/coderay/scanners/c.rb
|
59
|
+
- lib/coderay/scanners/clojure.rb
|
60
|
+
- lib/coderay/scanners/cpp.rb
|
61
|
+
- lib/coderay/scanners/css.rb
|
62
|
+
- lib/coderay/scanners/debug.rb
|
63
|
+
- lib/coderay/scanners/delphi.rb
|
64
|
+
- lib/coderay/scanners/diff.rb
|
65
|
+
- lib/coderay/scanners/erb.rb
|
66
|
+
- lib/coderay/scanners/groovy.rb
|
67
|
+
- lib/coderay/scanners/haml.rb
|
68
|
+
- lib/coderay/scanners/html.rb
|
69
|
+
- lib/coderay/scanners/java.rb
|
70
|
+
- lib/coderay/scanners/java/builtin_types.rb
|
71
|
+
- lib/coderay/scanners/java_script.rb
|
72
|
+
- lib/coderay/scanners/json.rb
|
73
|
+
- lib/coderay/scanners/php.rb
|
74
|
+
- lib/coderay/scanners/python.rb
|
75
|
+
- lib/coderay/scanners/raydebug.rb
|
76
|
+
- lib/coderay/scanners/ruby.rb
|
77
|
+
- lib/coderay/scanners/ruby/patterns.rb
|
78
|
+
- lib/coderay/scanners/ruby/string_state.rb
|
79
|
+
- lib/coderay/scanners/sql.rb
|
80
|
+
- lib/coderay/scanners/text.rb
|
81
|
+
- lib/coderay/scanners/xml.rb
|
82
|
+
- lib/coderay/scanners/yaml.rb
|
83
|
+
- lib/coderay/style.rb
|
84
|
+
- lib/coderay/styles/_map.rb
|
85
|
+
- lib/coderay/styles/alpha.rb
|
86
|
+
- lib/coderay/token_kinds.rb
|
87
|
+
- lib/coderay/tokens.rb
|
88
|
+
- lib/coderay/tokens_proxy.rb
|
89
|
+
- lib/coderay/version.rb
|
90
|
+
- test/functional/basic.rb
|
91
|
+
- test/functional/examples.rb
|
92
|
+
- test/functional/for_redcloth.rb
|
93
|
+
- test/functional/suite.rb
|
106
94
|
- bin/coderay
|
107
|
-
- bin/coderay_stylesheet
|
108
95
|
homepage: http://coderay.rubychan.de
|
109
96
|
licenses: []
|
110
|
-
|
111
97
|
post_install_message:
|
112
|
-
rdoc_options:
|
98
|
+
rdoc_options:
|
113
99
|
- -SNw2
|
114
|
-
- -
|
100
|
+
- -mREADME_INDEX.rdoc
|
115
101
|
- -t CodeRay Documentation
|
116
|
-
require_paths:
|
102
|
+
require_paths:
|
117
103
|
- lib
|
118
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
105
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
|
124
|
-
|
125
|
-
- 1
|
126
|
-
- 8
|
127
|
-
- 2
|
128
|
-
version: 1.8.2
|
129
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.6
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
111
|
none: false
|
131
|
-
requirements:
|
132
|
-
- -
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
|
135
|
-
segments:
|
136
|
-
- 0
|
137
|
-
version: "0"
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
138
116
|
requirements: []
|
139
|
-
|
140
117
|
rubyforge_project: coderay
|
141
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.8.10
|
142
119
|
signing_key:
|
143
120
|
specification_version: 3
|
144
121
|
summary: Fast syntax highlighting for selected languages.
|
145
|
-
test_files:
|
146
|
-
-
|
122
|
+
test_files:
|
123
|
+
- test/functional/basic.rb
|
124
|
+
- test/functional/examples.rb
|
125
|
+
- test/functional/for_redcloth.rb
|
126
|
+
- test/functional/suite.rb
|
data/FOLDERS
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
= CodeRay - Trunk folder structure
|
2
|
-
|
3
|
-
== bench - Benchmarking system
|
4
|
-
|
5
|
-
All benchmarking stuff goes here.
|
6
|
-
|
7
|
-
Test inputs are stored in files named <code>example.<lang></code>.
|
8
|
-
Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
|
9
|
-
|
10
|
-
Run <code>bench/bench.rb</code> to get a usage description.
|
11
|
-
|
12
|
-
Run <code>rake bench</code> to perform an example benchmark.
|
13
|
-
|
14
|
-
|
15
|
-
== bin - Scripts
|
16
|
-
|
17
|
-
Executional files for CodeRay.
|
18
|
-
|
19
|
-
|
20
|
-
== demo - Demos and functional tests
|
21
|
-
|
22
|
-
Demonstrational scripts to show of CodeRay's features.
|
23
|
-
|
24
|
-
Run them as functional tests with <code>rake test:demos</code>.
|
25
|
-
|
26
|
-
|
27
|
-
== etc - Lots of stuff
|
28
|
-
|
29
|
-
Some addidtional files for CodeRay, mainly graphics and Vim scripts.
|
30
|
-
|
31
|
-
|
32
|
-
== gem_server - Gem output folder
|
33
|
-
|
34
|
-
For <code>rake gem</code>.
|
35
|
-
|
36
|
-
|
37
|
-
== lib - CodeRay library code
|
38
|
-
|
39
|
-
This is the base directory for the CodeRay library.
|
40
|
-
|
41
|
-
|
42
|
-
== rake_helpers - Rake helper libraries
|
43
|
-
|
44
|
-
Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
|
45
|
-
|
46
|
-
|
47
|
-
== test - Tests
|
48
|
-
|
49
|
-
Tests for the scanners.
|
50
|
-
|
51
|
-
Each language has its own subfolder and sub-suite.
|
52
|
-
|
53
|
-
Run with <code>rake test</code>.
|
data/bin/coderay_stylesheet
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Encoders
|
3
|
-
|
4
|
-
class HTML
|
5
|
-
|
6
|
-
module Output
|
7
|
-
|
8
|
-
def numerize *args
|
9
|
-
clone.numerize!(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
=begin NUMERIZABLE_WRAPPINGS = {
|
13
|
-
:table => [:div, :page, nil],
|
14
|
-
:inline => :all,
|
15
|
-
:list => [:div, :page, nil]
|
16
|
-
}
|
17
|
-
NUMERIZABLE_WRAPPINGS.default = :all
|
18
|
-
=end
|
19
|
-
def numerize! mode = :table, options = {}
|
20
|
-
return self unless mode
|
21
|
-
|
22
|
-
options = DEFAULT_OPTIONS.merge options
|
23
|
-
|
24
|
-
start = options[:line_number_start]
|
25
|
-
unless start.is_a? Integer
|
26
|
-
raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
|
27
|
-
end
|
28
|
-
|
29
|
-
#allowed_wrappings = NUMERIZABLE_WRAPPINGS[mode]
|
30
|
-
#unless allowed_wrappings == :all or allowed_wrappings.include? options[:wrap]
|
31
|
-
# raise ArgumentError, "Can't numerize, :wrap must be in %p, but is %p" % [NUMERIZABLE_WRAPPINGS, options[:wrap]]
|
32
|
-
#end
|
33
|
-
|
34
|
-
bold_every = options[:bold_every]
|
35
|
-
highlight_lines = options[:highlight_lines]
|
36
|
-
bolding =
|
37
|
-
if bold_every == false && highlight_lines == nil
|
38
|
-
proc { |line| line.to_s }
|
39
|
-
elsif highlight_lines.is_a? Enumerable
|
40
|
-
highlight_lines = highlight_lines.to_set
|
41
|
-
proc do |line|
|
42
|
-
if highlight_lines.include? line
|
43
|
-
"<strong class=\"highlighted\">#{line}</strong>" # highlighted line numbers in bold
|
44
|
-
else
|
45
|
-
line.to_s
|
46
|
-
end
|
47
|
-
end
|
48
|
-
elsif bold_every.is_a? Integer
|
49
|
-
raise ArgumentError, ":bolding can't be 0." if bold_every == 0
|
50
|
-
proc do |line|
|
51
|
-
if line % bold_every == 0
|
52
|
-
"<strong>#{line}</strong>" # every bold_every-th number in bold
|
53
|
-
else
|
54
|
-
line.to_s
|
55
|
-
end
|
56
|
-
end
|
57
|
-
else
|
58
|
-
raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every
|
59
|
-
end
|
60
|
-
|
61
|
-
case mode
|
62
|
-
when :inline
|
63
|
-
max_width = (start + line_count).to_s.size
|
64
|
-
line_number = start
|
65
|
-
gsub!(/^/) do
|
66
|
-
line_number_text = bolding.call line_number
|
67
|
-
indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x)
|
68
|
-
res = "<span class=\"no\">#{indent}#{line_number_text}</span> "
|
69
|
-
line_number += 1
|
70
|
-
res
|
71
|
-
end
|
72
|
-
|
73
|
-
when :table
|
74
|
-
# This is really ugly.
|
75
|
-
# Because even monospace fonts seem to have different heights when bold,
|
76
|
-
# I make the newline bold, both in the code and the line numbers.
|
77
|
-
# FIXME Still not working perfect for Mr. Internet Exploder
|
78
|
-
line_numbers = (start ... start + line_count).to_a.map(&bolding).join("\n")
|
79
|
-
line_numbers << "\n" # also for Mr. MS Internet Exploder :-/
|
80
|
-
line_numbers.gsub!(/\n/) { "<tt>\n</tt>" }
|
81
|
-
|
82
|
-
line_numbers_table_tpl = TABLE.apply('LINE_NUMBERS', line_numbers)
|
83
|
-
gsub!("</div>\n", '</div>')
|
84
|
-
gsub!("\n", "<tt>\n</tt>")
|
85
|
-
wrap_in! line_numbers_table_tpl
|
86
|
-
@wrapped_in = :div
|
87
|
-
|
88
|
-
when :list
|
89
|
-
opened_tags = []
|
90
|
-
gsub!(/^.*$\n?/) do |line|
|
91
|
-
line.chomp!
|
92
|
-
|
93
|
-
open = opened_tags.join
|
94
|
-
line.scan(%r!<(/)?span[^>]*>?!) do |close,|
|
95
|
-
if close
|
96
|
-
opened_tags.pop
|
97
|
-
else
|
98
|
-
opened_tags << $&
|
99
|
-
end
|
100
|
-
end
|
101
|
-
close = '</span>' * opened_tags.size
|
102
|
-
|
103
|
-
"<li>#{open}#{line}#{close}</li>\n"
|
104
|
-
end
|
105
|
-
chomp!("\n")
|
106
|
-
wrap_in! LIST
|
107
|
-
@wrapped_in = :div
|
108
|
-
|
109
|
-
else
|
110
|
-
raise ArgumentError, 'Unknown value %p for mode: expected one of %p' %
|
111
|
-
[mode, [:table, :list, :inline]]
|
112
|
-
end
|
113
|
-
|
114
|
-
self
|
115
|
-
end
|
116
|
-
|
117
|
-
def line_count
|
118
|
-
line_count = count("\n")
|
119
|
-
position_of_last_newline = rindex(?\n)
|
120
|
-
if position_of_last_newline
|
121
|
-
after_last_newline = self[position_of_last_newline + 1 .. -1]
|
122
|
-
ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/]
|
123
|
-
line_count += 1 if not ends_with_newline
|
124
|
-
end
|
125
|
-
line_count
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|