From 196b7296666c12b0c04fa6b8dc42e46ed9331432 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 17 Jun 2013 12:51:49 +0200 Subject: bring back wrap! method, TODO: benchmark against String#sub --- lib/coderay/encoders/html/output.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/coderay/encoders') diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 3841f44..66ff0ba 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -17,6 +17,16 @@ module Encoders end.sub('<%CONTENT%>', string) end + def self.wrap! str, template, target + target = Regexp.new(Regexp.escape("<%#{target}%>")) + if template =~ target + str[0,0] = $` + str << $' + else + raise "Template target <%%%p%%> not found" % target + end + end + SPAN = '<%CONTENT%>' DIV = <<-DIV -- cgit v1.2.1