Module: CustomERB::Util

Defined in:
lib/ontomde-core/customERB.rb

Overview

A utility module for conversion routines, often handy in HTML generation.

Class Method Summary collapse

Class Method Details

.hObject

A utility method for escaping HTML tag characters in s.

require “erb” include CustomERB::Util

puts html_escape(“is a > 0 & a < 10?”)

Generates

is a &gt; 0 &amp; a &lt; 10?



800
801
802
# File 'lib/ontomde-core/customERB.rb', line 800

def html_escape(s)
  s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end

.html_escape(s) ⇒ Object

A utility method for escaping HTML tag characters in s.

require “erb” include CustomERB::Util

puts html_escape(“is a > 0 & a < 10?”)

Generates

is a &gt; 0 &amp; a &lt; 10?



797
798
799
# File 'lib/ontomde-core/customERB.rb', line 797

def html_escape(s)
  s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end

.uObject

A utility method for encoding the String s as a URL.

require “erb” include CustomERB::Util

puts url_encode(“Programming Ruby: The Pragmatic Programmer’s Guide”)

Generates

Programming@20Ruby@3A@20@20The@20Pragmatic@20Programmer@27s@20Guide



819
820
821
# File 'lib/ontomde-core/customERB.rb', line 819

def url_encode(s)
  s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("@@@02X", $&.unpack("C")[0]) }
end

.url_encode(s) ⇒ Object

A utility method for encoding the String s as a URL.

require “erb” include CustomERB::Util

puts url_encode(“Programming Ruby: The Pragmatic Programmer’s Guide”)

Generates

Programming@20Ruby@3A@20@20The@20Pragmatic@20Programmer@27s@20Guide



816
817
818
# File 'lib/ontomde-core/customERB.rb', line 816

def url_encode(s)
  s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("@@@02X", $&.unpack("C")[0]) }
end