Skip to content

Commit

Permalink
Add a LiteralLine Erb type to avoid xml escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
juba authored and kremso committed Jul 5, 2010
1 parent cde2a6b commit 3e790b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/serenity/line.rb
Expand Up @@ -22,6 +22,10 @@ def self.string txt
StringLine.new txt
end

def self.literal txt
LiteralLine.new txt
end

end

class TextLine < Line
Expand Down Expand Up @@ -49,5 +53,12 @@ def to_buf
" _buf << (" << escape_code(@text) << ").to_s.escape_xml;"
end
end

class LiteralLine < CodeLine
def to_buf
" _buf << (" << escape_code(@text) << ").to_s;"
end
end

end

8 changes: 5 additions & 3 deletions lib/serenity/odteruby.rb
Expand Up @@ -2,7 +2,7 @@ module Serenity
class OdtEruby
include Debug

EMBEDDED_PATTERN = /\{%(=+)?(.*?)-?%\}/m
EMBEDDED_PATTERN = /\{%([=%]+)?(.*?)-?%\}/m

def initialize template
@src = convert template
Expand Down Expand Up @@ -61,10 +61,12 @@ def process_instruction text
pos = m.end(0)
src << Line.text(middle) unless middle.empty?

if !indicator # <% %>
if !indicator # <% %>
src << Line.code(code)
else # <%= %>
elsif indicator == '=' # <%= %>
src << Line.string(code)
elsif indicator == '%' # <%% %>
src << Line.literal(code)
end
end

Expand Down

0 comments on commit 3e790b3

Please sign in to comment.