Sha256: 2e6e9e3cc4ebfadd851f56f23afb33c94f91d30f03deb1882762829eecc13ba2

Contents?: true

Size: 941 Bytes

Versions: 19

Compression:

Stored size: 941 Bytes

Contents

class String
  # Returns a-string-with-dashes when passed 'a string with dashes'.
  # All special chars are stripped in the process
  def to_url
    return if self.nil?

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

  # A quick and dirty fix to add 'nofollow' to any urls in a string.
  # Decidedly unsafe, but will have to do for now.
  def nofollowify
    self.gsub(/<a(.*?)>/i, '<a\1 rel="nofollow">')
  end

  # Strips any html markup from a string
  TYPO_TAG_KEY = 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*(?:[!/?\]]+|--)?>}
  def strip_html
    self.gsub(TAG, '').gsub(/\s+/, ' ').strip
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
typo-5.5 lib/transforms.rb
typo-5.4.4 lib/transforms.rb
typo-5.4.3 lib/transforms.rb
typo-5.4.2 lib/transforms.rb
typo-5.4.1 lib/transforms.rb
typo-5.4 lib/transforms.rb
typo-5.0.2 lib/transforms.rb
typo-5.0.1 lib/transforms.rb
typo-5.0.3.98.1 lib/transforms.rb
typo-5.0.3.98 lib/transforms.rb
typo-5.0 lib/transforms.rb
typo-5.1.1 lib/transforms.rb
typo-5.1.2 lib/transforms.rb
typo-5.1.3 lib/transforms.rb
typo-5.1.98 lib/transforms.rb
typo-5.1 lib/transforms.rb
typo-5.2 lib/transforms.rb
typo-5.2.98 lib/transforms.rb
typo-5.3 lib/transforms.rb