diff options
author | murphy <murphy@rubychan.de> | 2006-03-21 14:46:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-03-21 14:46:34 +0000 |
commit | a3b4ad06b992bd418a1d34bfb271c09fd9bedf11 (patch) | |
tree | 722d341f4065b4614b2cfc55cee6ccd3c66fb69a /lib/coderay/encoders | |
parent | 13255135d7539fd542cf831d6a98f1ba8a5d43ae (diff) | |
download | coderay-a3b4ad06b992bd418a1d34bfb271c09fd9bedf11.tar.gz |
CodeRay::Duo added for cool caching!
bench/caching.rb added t“for demonstrating this.
HTML Encoder: creates unwrapped output by default (still problems with that.)
Numerizing changed (doesn't try to prevent nesting errors)
Speedup: "::String" is faster.
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r-- | lib/coderay/encoders/html.rb | 13 | ||||
-rw-r--r-- | lib/coderay/encoders/html/numerization.rb | 30 | ||||
-rw-r--r-- | lib/coderay/encoders/html/output.rb | 4 |
3 files changed, 22 insertions, 25 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index b75f9e5..11fa84c 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -36,7 +36,7 @@ module Encoders #
# You can also use Encoders::Div and Encoders::Span.
#
- # Default: :page
+ # Default: nil
#
# === :line_numbers
# Include line numbers in :table, :inline, :list or nil (no line numbers)
@@ -73,7 +73,7 @@ module Encoders :style => :cycnus,
- :wrap => :page,
+ :wrap => nil,
:line_numbers => nil,
:line_number_start => 1,
@@ -208,17 +208,14 @@ module Encoders @out.extend Output
@out.css = @css
- @out.numerize! options[:line_numbers], options # if options[:line_numbers]
- @out.wrap! options[:wrap] # if options[:wrap]
-
- #require 'pp'
- #pp @css_style, @css_style.size
+ @out.numerize! options[:line_numbers], options
+ @out.wrap! options[:wrap]
super
end
def token text, type
- if text.is_a? String
+ if text.is_a? ::String
if text =~ /#{HTML_ESCAPE_PATTERN}/o
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end
diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb index edce9eb..c5d96f3 100644 --- a/lib/coderay/encoders/html/numerization.rb +++ b/lib/coderay/encoders/html/numerization.rb @@ -1,5 +1,5 @@ module CodeRay
- module Encoders
+module Encoders
class HTML
@@ -9,13 +9,13 @@ module CodeRay clone.numerize!(*args)
end
- NUMERIZABLE_WRAPPINGS = {
- :table => [:div, :page],
+=begin NUMERIZABLE_WRAPPINGS = {
+ :table => [:div, :page, nil],
:inline => :all,
- :list => [:div, :page]
+ :list => [:div, :page, nil]
}
NUMERIZABLE_WRAPPINGS.default = :all
-
+=end
def numerize! mode = :table, options = {}
return self unless mode
@@ -26,16 +26,17 @@ module CodeRay raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
end
- allowed_wrappings = NUMERIZABLE_WRAPPINGS[mode]
- unless allowed_wrappings == :all or allowed_wrappings.include? options[:wrap]
- raise ArgumentError, "Can't numerize, :wrap must be in %p, but is %p" % [NUMERIZABLE_WRAPPINGS, options[:wrap]]
- end
+ #allowed_wrappings = NUMERIZABLE_WRAPPINGS[mode]
+ #unless allowed_wrappings == :all or allowed_wrappings.include? options[:wrap]
+ # raise ArgumentError, "Can't numerize, :wrap must be in %p, but is %p" % [NUMERIZABLE_WRAPPINGS, options[:wrap]]
+ #end
bold_every = options[:bold_every]
bolding =
- if bold_every == :no_bolding or bold_every == 0
+ if bold_every == false
proc { |line| line.to_s }
elsif bold_every.is_a? Integer
+ raise ArgumentError, ":bolding can't be 0." if bold_every == 0
proc do |line|
if line % bold_every == 0
"<strong>#{line}</strong>" # every bold_every-th number in bold
@@ -44,11 +45,11 @@ module CodeRay end
end
else
- raise ArgumentError, "Invalid value %p for :bolding; :no_bolding or Integer expected." % bolding
+ raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every
end
line_count = count("\n")
- line_count += 1 if self[-1] != ?\n
+ line_count += 1 unless self[-1] == ?\n
case mode
when :inline
@@ -59,7 +60,6 @@ module CodeRay line += 1
"<span class=\"no\">#{ line_number.rjust(max_width) }</span> "
end
- #wrap! :div
when :table
# This is really ugly.
@@ -97,8 +97,8 @@ module CodeRay @wrapped_in = :div
else
- raise ArgumentError, "Unknown value %p for mode: expected one of %p" %
- [mode, NUMERIZABLE_WRAPPINGS.keys - [:all]]
+ raise ArgumentError, 'Unknown value %p for mode: expected one of %p' %
+ [mode, [:table, :list, :inline]]
end
self
diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 8096dc8..80ab4f1 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -158,10 +158,10 @@ module CodeRay DIV
TABLE = <<-`TABLE`
-<table class="CodeRay"> <tr>
+<table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><%LINE_NUMBERS%></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><%CONTENT%></pre></td>
-</tr> </table>
+</tr></table>
TABLE
# title="double click to expand"
|