From a8a17fc78987bfd4236c929fd54c58f8014fe88d Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 10 Jun 2013 17:35:17 +0200 Subject: simplify more HTML encoder methods (#135) --- lib/coderay/encoders/html.rb | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index f0f5d62..a6c0a8e 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -171,18 +171,16 @@ module Encoders def setup options super - check_options options + check_options! options if options[:wrap] || options[:line_numbers] @real_out = @out @out = '' end - options[:break_lines] = true if options[:line_numbers] == :inline @break_lines = (options[:break_lines] == true) - @HTML_ESCAPE = HTML_ESCAPE.dup - @HTML_ESCAPE["\t"] = ' ' * options[:tab_width] + @HTML_ESCAPE = HTML_ESCAPE.merge("\t" => ' ' * options[:tab_width]) @opened = [] @last_opened = nil @@ -271,7 +269,7 @@ module Encoders protected - def check_options options + def check_options! options unless [false, nil, :debug, :info, :info_long].include? options[:hint] raise ArgumentError, "Unknown value %p for :hint; expected :info, :info_long, :debug, false, or nil." % [options[:hint]] end @@ -279,24 +277,23 @@ module Encoders unless [:class, :style].include? options[:css] raise ArgumentError, 'Unknown value %p for :css.' % [options[:css]] end + + options[:break_lines] = true if options[:line_numbers] == :inline end def make_span_for_kind method, hint, css - css_classes = TokenKinds - - Hash.new do |h, k| - kind = k.is_a?(Symbol) ? k : k.first - - h[k.is_a?(Symbol) ? k : k.dup] = - if kind != :space && ((css_class = css_classes[kind]) || hint) - title = HTML.token_path_to_hint hint, k if hint - if method == :class - "" - else - style = css.get_style k.is_a?(Array) ? k.map { |c| css_classes[c] } : [css_class] - "" - end - end + Hash.new do |h, kinds| + h[kinds.is_a?(Symbol) ? kinds : kinds.dup] = begin + css_class = TokenKinds[kinds.is_a?(Symbol) ? kinds : kinds.first] + title = HTML.token_path_to_hint hint, kinds if hint + + if method == :style + style = css.get_style(kinds.is_a?(Array) ? kinds.map { |c| TokenKinds[c] } : [TokenKinds[kinds]]) + "" + else + "" + end if css_class || title + end end end -- cgit v1.2.1