diff options
author | murphy <murphy@rubychan.de> | 2011-03-01 00:18:02 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2011-03-01 00:18:02 +0000 |
commit | 4d3fd15d2d5c72db3356d6485032c811aaa5f03c (patch) | |
tree | ea4cf51f9192032a7a665c789810d75963a41354 /lib/coderay/encoders | |
parent | 7ce54ac0f614be36b40da2537fe3aab4acbd7da2 (diff) | |
download | coderay-4d3fd15d2d5c72db3356d6485032c811aaa5f03c.tar.gz |
Use autoload in HTML encoder; speedup for :css => :class mode.
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r-- | lib/coderay/encoders/html.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 1120a44..4c5695d 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -110,8 +110,8 @@ module Encoders :hint => false, } - # TODO: Make Plugin use autoload, too. - helper :output, :css + autoload :Output, 'coderay/encoders/html/output' + autoload :CSS, 'coderay/encoders/html/css' autoload :Numbering, 'coderay/encoders/html/numbering' attr_reader :css @@ -138,7 +138,7 @@ module Encoders TOKEN_KIND_TO_INFO = Hash.new do |h, kind| h[kind] = case kind - when :pre_constant + when :pre_constant # FIXME: rename to :predefined_constant 'Predefined constant' else kind.to_s.gsub(/_/, ' ').gsub(/\b\w/) { $&.capitalize } @@ -187,17 +187,23 @@ module Encoders expected :info, :debug, false, or nil." % hint end - css_classes = Tokens::AbbreviationForKind + css_classes = TokenKinds case options[:css] when :class @span_for_kind = Hash.new do |h, k| - kind = k.is_a?(Symbol) ? k : k.first - h[k.is_a?(Symbol) ? k : k.dup] = - if kind != :space && (hint || css_classes[kind]) - title = HTML.token_path_to_hint hint, k if hint - css_class = css_classes[k] - "<span#{title}#{" class=\"#{css_class}\"" if css_class}>" - end + if k.is_a? ::Symbol + kind = k_dup = k + else + kind = k.first + k_dup = k.dup + end + if kind != :space && (hint || css_class = css_classes[kind]) + title = HTML.token_path_to_hint hint, k if hint + css_class ||= css_classes[kind] + h[k_dup] = "<span#{title}#{" class=\"#{css_class}\"" if css_class}>" + else + h[k_dup] = nil + end end when :style @span_for_kind = Hash.new do |h, k| |