Sha256: 0349105314c06b1ab582cbd679c3e4292505dc98acf6d5d5d455ee9d05e878a1

Contents?: true

Size: 606 Bytes

Versions: 12

Compression:

Stored size: 606 Bytes

Contents

#	This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3.
#	Copyright 2010 Samuel Williams. All rights reserved.
#	See <utopia.rb> for licensing details.

class String
	HTML_ESCAPE = {"&" => "&amp;", "<" => "&lt;", ">" => "&gt;", "\"" => "&quot;"}
	HTML_ESCAPE_PATTERN = Regexp.new("[" + Regexp.quote(HTML_ESCAPE.keys.join) + "]")

	def to_html
		gsub(HTML_ESCAPE_PATTERN){|c| HTML_ESCAPE[c]}
	end

	def to_title
		(" " + self).gsub(/[ \-_](.)/){" " + $1.upcase}.strip
	end

	def to_snake
		self.gsub("::", "").gsub(/([A-Z]+)/){"_" + $1.downcase}.sub(/^_+/, "")
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
utopia-0.9.43 lib/utopia/extensions/string.rb
utopia-0.9.42 lib/utopia/extensions/string.rb
utopia-0.9.41 lib/utopia/extensions/string.rb
utopia-0.9.40 lib/utopia/extensions/string.rb
utopia-0.9.39 lib/utopia/extensions/string.rb
utopia-0.9.38 lib/utopia/extensions/string.rb
utopia-0.9.37 lib/utopia/extensions/string.rb
utopia-0.9.36 lib/utopia/extensions/string.rb
utopia-0.9.35 lib/utopia/extensions/string.rb
utopia-0.9.34 lib/utopia/extensions/string.rb
utopia-0.9.33 lib/utopia/extensions/string.rb
utopia-0.9.32 lib/utopia/extensions/string.rb