Class: String

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

Direct Known Subclasses

ActionWebService::Base64

Constant Summary

TYPO_TAG_KEY =

Strips any html markup from a string

TYPO_ATTRIBUTE_KEY = /[\w:_-]+/
TYPO_ATTRIBUTE_VALUE =
/(?:[A-Za-z0-9]+|(?:'[^']*?'|"[^"]*?"))/
TYPO_ATTRIBUTE =
/(?:#{TYPO_ATTRIBUTE_KEY}(?:\s*=\s*#{TYPO_ATTRIBUTE_VALUE})?)/
TYPO_ATTRIBUTES =
/(?:#{TYPO_ATTRIBUTE}(?:\s+#{TYPO_ATTRIBUTE})*)/
TAG =
%r{<[!/?\[]?(?:#{TYPO_TAG_KEY}|--)(?:\s+#{TYPO_ATTRIBUTES})?\s*(?:[!/?\]]+|--)?>}

Instance Method Summary (collapse)

Instance Method Details

- (Object) nofollowify

A quick and dirty fix to add 'nofollow' to any urls in a string. Decidedly unsafe, but will have to do for now.



12
13
14
15
# File 'lib/transforms.rb', line 12

def nofollowify
  return self.gsub(/<a(.*?)>/i, '<a\1 rel="nofollow">') if Blog.default.nofollowify
  self
end

- (Object) strip_html



23
24
25
# File 'lib/transforms.rb', line 23

def strip_html
  self.gsub(TAG, '').gsub(/\s+/, ' ').strip
end

- (Object) to_url

Returns a-string-with-dashes when passed 'a string with dashes'. All special chars are stripped in the process



4
5
6
7
8
# File 'lib/transforms.rb', line 4

def to_url
  return if self.nil?

  self.downcase.tr("\"'", '').gsub(/\W/, ' ').strip.tr_s(' ', '-').tr(' ', '-').sub(/^$/, "-")
end