Class: Ape::Escaper

Inherits:
Object
  • Object
show all
Defined in:
lib/ape/escaper.rb

Class Method Summary collapse

Class Method Details

.escape(text) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ape/escaper.rb', line 5

def Escaper.escape(text)
  text.gsub(/([&<'">])/) do
    case $1
    when '&' then '&amp;'
    when '<' then '&lt;'
    when "'" then '&apos;'
    when '"' then '&quot;'
    when '>' then '&gt;'
    end
  end
end

.unescape(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ape/escaper.rb', line 17

def Escaper.unescape(text)
  text.gsub(/&([^;]*);/) do
    case $1
    when 'lt' then '<'
    when 'amp' then '&'
    when 'gt' then '>'
    when 'apos' then "'"
    when 'quot' then '"'
    end
  end
end