# File lib/termcolor.rb, line 60 def colorize(text, color) parse("<#{color}>#{escape(text)}</#{color}>") end
# File lib/termcolor.rb, line 19 def escape(text) escape_or_unescape(:escape, text) end
# File lib/termcolor.rb, line 13 def parse(text) listener = MyListener.new REXML::Parsers::StreamParser.new(prepare_parse(text), listener).parse listener.result end
# File lib/termcolor.rb, line 34 def prepare_parse(text) tag_separate text.gsub(/<(\/?)(\d+)>/, '<\1_\2>') end
# File lib/termcolor.rb, line 38 def tag_separate(text) re = /<(\/*)([^\W_]+)(?:_(on_[^\W_]+))*(?:_with_([^\W_]+))*(?:_and_([^\W_]+))*>/ text.gsub(re) do matchs = $~.captures if matchs.shift.empty? tag = ->t{ "<#{t}>" } else matchs.reverse! tag = ->t{ "</#{t}>" } end matchs.compact.map { |word| tag[word] }.join end end
Generated with the Darkfish Rdoc Generator 2.