Class: PageTemplate::DefaultPreprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/PageTemplate/parser.rb

Class Method Summary collapse

Class Method Details

.escapeHTML(string) ⇒ Object

Escape all HTML


474
475
476
477
478
479
480
# File 'lib/PageTemplate/parser.rb', line 474

def escapeHTML(string)
  str = string.gsub(/&/n, '&')
  str.gsub!(/\"/n, '"')
  str.gsub!(/>/n, '>')
  str.gsub!(/</n, '&lt;')
  str
end

.escapeURI(string) ⇒ Object

escape URIs into %20-style escapes.


468
469
470
471
472
# File 'lib/PageTemplate/parser.rb', line 468

def escapeURI(string)
  string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
  '%' + $1.unpack('H2' * $1.size).join('%').upcase
  end.tr(' ', '+')
end

.reverse(str) ⇒ Object

Reverse the string. Don't see any use for this :D.


464
465
466
# File 'lib/PageTemplate/parser.rb', line 464

def reverse(str)
  str.reverse
end

.simple(str) ⇒ Object

Escape HTML, but also turn newlines into <br />s


482
483
484
# File 'lib/PageTemplate/parser.rb', line 482

def simple(str)
  escapeHTML(str).gsub(/\r\n|\n/,"<br />\n")
end

.unescaped(str) ⇒ Object Also known as: process

Default, unescaped string.


458
459
460
# File 'lib/PageTemplate/parser.rb', line 458

def unescaped(str)
  str
end