public
Description: Ruby text filters ( phrase, profanity, email / uri to anchor tags, etc )
Homepage:
Clone URL: git://github.com/visionmedia/filters.git
name age message
file History.rdoc Mon Nov 23 13:31:57 -0800 2009 Release 1.1.1 [visionmedia]
file Manifest Mon Nov 23 12:34:26 -0800 2009 Release 1.1.0 [visionmedia]
file README.rdoc Mon Nov 23 12:34:08 -0800 2009 Docs for mutative filters [visionmedia]
file Rakefile Mon Nov 23 11:47:13 -0800 2009 Removed rake tasks Rake kinda sucks, I rarely ... [visionmedia]
file filters.gemspec Mon Nov 23 13:31:57 -0800 2009 Release 1.1.1 [visionmedia]
directory lib/ Mon Nov 23 13:31:57 -0800 2009 Release 1.1.1 [visionmedia]
directory spec/ Mon Nov 23 13:04:21 -0800 2009 Fix email addresses regex according to RFC [marcandre]
README.rdoc

Filters

Ruby text filters consisting of the following core filters:

  • phrase
  • profanity (uses phrase)
  • email (converts emails to mailto: anchor tags)
  • uri (converts uris to anchor tags)
  • markup (mini-markup language)

Mutative

All filters return a new string by default, however when you bang! it, the string object initially passed will be modified. This method is often ideal, as it is easier to chain filters together.

  Filter::Profanity!(text)
  Filter::Email!(text)
  ...

Filter::Phrase

  Filter::Phrase('bad word!', :phrases => ['bad'])
  # => 'word!'

  Filter::Phrase('bad word!', :phrases => ['bad'], :mask => '*')
  # => '*** word!'

  Filter::Phrase('bad word!', :phrases => ['bad'], :mask => '[removed]')
  # => '[removed] word!'

  Filter::Phrase('foobar', :phrases => ['foo(bar)?'])
  # => ''

  Filter::Phrase('foobar', :phrases => [/foo(bar)?/])
  # => ''

  Filter::Phrase('some foo bar', :phrases => [['foo', '*'], ['bar', '[removed]']])
  # => 'some *** [removed]'

Filter::Profanity < Filter::Phrase

  Filter::Profanity('fuck this shit is so awesome i cant fucking believe it')
  # => 'this is so awesome i cant believe it'

  Filter::Profanity('fuck this shit is so awesome i cant fucking believe it', :mask => '*')
  # => '**** this **** is so awesome i cant ******* believe it'

Filter::URI

  Filter::URI('hey checkout http://vision-media.ca sometime')
  # => 'hey checkout <a href="http://vision-media.ca">http://vision-media.ca</a> sometime'

Filter::Email

  Filter::Email('hey email me@foo.com sometime')
  # => 'hey email <a href="mailto:me@foo.com">me@foo.com</a> sometime'

Filter::Markup

  Filter::Markup <<-EOF
    = Welcome

    == Article

    This article is meant to show how a simple *markup* language
    can be generated using the filter gem.

    === Source

    @@@ javascript
      foo = function(){
        bar()
      }
    @@@
  EOF

Would output:

  <h1>Welcome</h1>

  <h2>Article</h2>

  <p> This article is meant to show how a simple <strong>markup</strong> language
  can be generated using the filter gem. </p>

  <h3>Source</h3>

  <code class="javascript">
    foo = function(){
      bar()
    }
  </code>

License:

(The MIT License)

Copyright © 2009 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, an d/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.