filters 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +0 -3
- data/README.rdoc +12 -2
- data/Rakefile +1 -1
- data/filters.gemspec +4 -4
- data/lib/filters/all.rb +1 -5
- data/lib/filters/filter.rb +21 -1
- data/lib/filters/profanity.rb +5 -3
- data/lib/filters/uri.rb +5 -4
- data/lib/filters/version.rb +1 -1
- data/spec/filter_email_spec.rb +17 -2
- data/spec/filter_markup_spec.rb +16 -1
- data/spec/filter_phrase_spec.rb +13 -3
- data/spec/filter_profanity_spec.rb +16 -1
- data/spec/filter_uri_spec.rb +13 -2
- metadata +2 -8
- data/tasks/docs.rake +0 -13
- data/tasks/gemspec.rake +0 -3
- data/tasks/spec.rake +0 -25
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -9,6 +9,16 @@ Ruby text filters consisting of the following core filters:
|
|
9
9
|
* uri (converts uris to anchor tags)
|
10
10
|
* markup (mini-markup language)
|
11
11
|
|
12
|
+
== Mutative
|
13
|
+
|
14
|
+
All filters return a new string by default, however when you bang! it, the
|
15
|
+
string object initially passed will be modified. This method is often ideal,
|
16
|
+
as it is easier to chain filters together.
|
17
|
+
|
18
|
+
Filter::Profanity!(text)
|
19
|
+
Filter::Email!(text)
|
20
|
+
...
|
21
|
+
|
12
22
|
== Filter::Phrase
|
13
23
|
|
14
24
|
Filter::Phrase('bad word!', :phrases => ['bad'])
|
@@ -40,12 +50,12 @@ Ruby text filters consisting of the following core filters:
|
|
40
50
|
== Filter::URI
|
41
51
|
|
42
52
|
Filter::URI('hey checkout http://vision-media.ca sometime')
|
43
|
-
# => 'hey checkout <a href="http://vision-media.ca">
|
53
|
+
# => 'hey checkout <a href="http://vision-media.ca">http://vision-media.ca</a> sometime'
|
44
54
|
|
45
55
|
== Filter::Email
|
46
56
|
|
47
57
|
Filter::Email('hey email me@foo.com sometime')
|
48
|
-
# => 'hey email <a href="mailto:me@foo.com">
|
58
|
+
# => 'hey email <a href="mailto:me@foo.com">me@foo.com</a> sometime'
|
49
59
|
|
50
60
|
== Filter::Markup
|
51
61
|
|
data/Rakefile
CHANGED
data/filters.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{filters}
|
5
|
-
s.version = "1.0
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-11-23}
|
10
10
|
s.description = %q{Text filters including phrases, profanity, mini-markdown, uri, email, etc}
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/filters.rb", "lib/filters/all.rb", "lib/filters/email.rb", "lib/filters/filter.rb", "lib/filters/markup.rb", "lib/filters/phrase.rb", "lib/filters/profanity.rb", "lib/filters/uri.rb", "lib/filters/version.rb"
|
13
|
-
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "filters.gemspec", "lib/filters.rb", "lib/filters/all.rb", "lib/filters/email.rb", "lib/filters/filter.rb", "lib/filters/markup.rb", "lib/filters/phrase.rb", "lib/filters/profanity.rb", "lib/filters/uri.rb", "lib/filters/version.rb", "spec/filter_email_spec.rb", "spec/filter_markup_spec.rb", "spec/filter_phrase_spec.rb", "spec/filter_profanity_spec.rb", "spec/filter_uri_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/filters.rb", "lib/filters/all.rb", "lib/filters/email.rb", "lib/filters/filter.rb", "lib/filters/markup.rb", "lib/filters/phrase.rb", "lib/filters/profanity.rb", "lib/filters/uri.rb", "lib/filters/version.rb"]
|
13
|
+
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "filters.gemspec", "lib/filters.rb", "lib/filters/all.rb", "lib/filters/email.rb", "lib/filters/filter.rb", "lib/filters/markup.rb", "lib/filters/phrase.rb", "lib/filters/profanity.rb", "lib/filters/uri.rb", "lib/filters/version.rb", "spec/filter_email_spec.rb", "spec/filter_markup_spec.rb", "spec/filter_phrase_spec.rb", "spec/filter_profanity_spec.rb", "spec/filter_uri_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
14
14
|
s.homepage = %q{http://github.com/visionmedia/filters}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Filters", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
data/lib/filters/all.rb
CHANGED
data/lib/filters/filter.rb
CHANGED
@@ -13,14 +13,34 @@ class Filter
|
|
13
13
|
@string, @options = string, options
|
14
14
|
end
|
15
15
|
|
16
|
+
##
|
17
|
+
# Non-mutative filter.
|
18
|
+
|
19
|
+
def filter
|
20
|
+
@string = string.dup and filter!
|
21
|
+
end
|
22
|
+
|
16
23
|
##
|
17
24
|
# Auto generate Filter::Subclass() methods which
|
18
|
-
# act as a shortcut to Filter::Subclass.new(...).filter
|
25
|
+
# act as a shortcut to Filter::Subclass.new(...).filter
|
19
26
|
|
20
27
|
def self.inherited subclass
|
21
28
|
(class << self; self end).send :define_method, subclass.name.split('::').last do |*args|
|
29
|
+
subclass.new(*args).filter
|
30
|
+
end
|
31
|
+
(class << self; self end).send :define_method, subclass.name.split('::').last + '!' do |*args|
|
22
32
|
subclass.new(*args).filter!
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
36
|
+
#--
|
37
|
+
# Autoloading
|
38
|
+
#++
|
39
|
+
|
40
|
+
autoload :URI, 'filters/uri'
|
41
|
+
autoload :Email, 'filters/email'
|
42
|
+
autoload :Markup, 'filters/markup'
|
43
|
+
autoload :Phrase, 'filters/phrase'
|
44
|
+
autoload :Profanity, 'filters/profanity'
|
45
|
+
|
26
46
|
end
|
data/lib/filters/profanity.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
|
2
|
-
require 'filters/phrase'
|
3
|
-
|
4
2
|
class Filter
|
5
3
|
class Profanity < Phrase
|
6
4
|
|
@@ -300,7 +298,11 @@ class Filter
|
|
300
298
|
|
301
299
|
end
|
302
300
|
|
303
|
-
def self.Profanity *args
|
301
|
+
def self.Profanity! *args
|
304
302
|
Profanity.new(*args).filter!
|
305
303
|
end
|
304
|
+
|
305
|
+
def self.Profanity *args
|
306
|
+
Profanity.new(*args).filter
|
307
|
+
end
|
306
308
|
end
|
data/lib/filters/uri.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'uri/common'
|
1
2
|
|
2
3
|
class Filter
|
3
4
|
class URI < self
|
@@ -17,13 +18,13 @@ class Filter
|
|
17
18
|
|
18
19
|
##
|
19
20
|
# Convert URIs to anchor tags.
|
20
|
-
|
21
|
+
|
21
22
|
def filter!
|
22
|
-
string.gsub!
|
23
|
+
string.gsub! ::URI.regexp do |uri|
|
23
24
|
if new_window
|
24
|
-
%(<a href="#{uri
|
25
|
+
%(<a href="#{uri}" target="_blank">#{uri}</a>)
|
25
26
|
else
|
26
|
-
%(<a href="#{uri
|
27
|
+
%(<a href="#{uri}">#{uri}</a>)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
string
|
data/lib/filters/version.rb
CHANGED
data/spec/filter_email_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
require 'filters/email'
|
4
3
|
|
5
4
|
describe Filter::Email do
|
6
5
|
it "should convert URIs to clickable anchor tags" do
|
@@ -12,6 +11,22 @@ describe Filter::Email do
|
|
12
11
|
it "should retain whitespace" do
|
13
12
|
string = 'email tj@vision-media.ca for awesome web-dev'
|
14
13
|
Filter::Email(string).
|
15
|
-
should == 'email <a href="mailto:tj@vision-media.ca">tj@vision-media.ca</a> for awesome web-dev'
|
14
|
+
should == 'email <a href="mailto:tj@vision-media.ca">tj@vision-media.ca</a> for awesome web-dev'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not mutate the string passed" do
|
18
|
+
string = 'email tj@vision-media.ca for awesome web-dev'
|
19
|
+
Filter::Email(string)
|
20
|
+
string.should == 'email tj@vision-media.ca for awesome web-dev'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should mutate when bang is used" do
|
24
|
+
string = 'email tj@vision-media.ca for awesome web-dev'
|
25
|
+
Filter::Email!(string)
|
26
|
+
string.should == 'email <a href="mailto:tj@vision-media.ca">tj@vision-media.ca</a> for awesome web-dev'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the string untouched when no emails are present" do
|
30
|
+
Filter::Email('foo bar').should == 'foo bar'
|
16
31
|
end
|
17
32
|
end
|
data/spec/filter_markup_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
require 'filters/markup'
|
4
3
|
|
5
4
|
describe Filter::Markup do
|
6
5
|
it "should treat *STR* as strong" do
|
@@ -96,4 +95,20 @@ describe Filter::Markup do
|
|
96
95
|
filtered2.should include('<h2>Article</h2>')
|
97
96
|
filtered2.should include('<h3>Sub Article</h3>')
|
98
97
|
end
|
98
|
+
|
99
|
+
it "should not mutate the string passed" do
|
100
|
+
string = 'foo *bar*'
|
101
|
+
Filter::Markup(string)
|
102
|
+
string.should == 'foo *bar*'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should mutate when a bang is used" do
|
106
|
+
string = 'foo *bar*'
|
107
|
+
Filter::Markup!(string)
|
108
|
+
string.should == 'foo <strong>bar</strong>'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return the string untouched when no conversion are present" do
|
112
|
+
Filter::Markup('foo bar').should == 'foo bar'
|
113
|
+
end
|
99
114
|
end
|
data/spec/filter_phrase_spec.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
require 'filters/phrase'
|
4
3
|
|
5
4
|
describe Filter::Phrase do
|
6
5
|
it "should not modify the string when no phrases are passed" do
|
7
|
-
|
8
|
-
Filter::Phrase(string).should == string
|
6
|
+
Filter::Phrase('everything is good here!').should == 'everything is good here!'
|
9
7
|
end
|
10
8
|
|
11
9
|
it "should remove phrases by default" do
|
@@ -41,4 +39,16 @@ describe Filter::Phrase do
|
|
41
39
|
result = Filter::Phrase(string, :phrases => ['fuck(ing|!)?'])
|
42
40
|
result.should be_empty
|
43
41
|
end
|
42
|
+
|
43
|
+
it "should not mutate the string passed" do
|
44
|
+
string = 'fuck fuck!'
|
45
|
+
Filter::Phrase(string, :phrases => ['fuck'])
|
46
|
+
string.should == 'fuck fuck!'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should mutate when a bang is used" do
|
50
|
+
string = 'fuck fuck!'
|
51
|
+
Filter::Phrase!(string, :phrases => ['fuck'])
|
52
|
+
string.should == 'fuck!'
|
53
|
+
end
|
44
54
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
require 'filters/profanity'
|
4
3
|
|
5
4
|
describe Filter::Profanity do
|
6
5
|
it "should remove profanity" do
|
@@ -8,4 +7,20 @@ describe Filter::Profanity do
|
|
8
7
|
results = Filter::Profanity(string, :phrases => %w( fucking! ) )
|
9
8
|
results.should == 'this is so awesome i just love it'
|
10
9
|
end
|
10
|
+
|
11
|
+
it "should return the string untouched when no profanity is present" do
|
12
|
+
Filter::Markup('foo bar').should == 'foo bar'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not mutate the string passed" do
|
16
|
+
string = 'fuck this shit'
|
17
|
+
Filter::Profanity(string)
|
18
|
+
string.should == 'fuck this shit'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should mutate when a bang is used" do
|
22
|
+
string = 'fuck this shit'
|
23
|
+
Filter::Profanity!(string)
|
24
|
+
string.strip.should == 'this'
|
25
|
+
end
|
11
26
|
end
|
data/spec/filter_uri_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
require 'filters/uri'
|
4
3
|
|
5
4
|
describe Filter::URI do
|
6
5
|
it "should return string when no uris are present" do
|
@@ -22,6 +21,18 @@ describe Filter::URI do
|
|
22
21
|
it "should retain whitespace" do
|
23
22
|
string = 'goto ftp://foo.com to do stuff'
|
24
23
|
Filter::URI(string).
|
25
|
-
should == 'goto <a href="ftp://foo.com">ftp://foo.com
|
24
|
+
should == 'goto <a href="ftp://foo.com">ftp://foo.com</a> to do stuff'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not mutate the string passed" do
|
28
|
+
string = 'goto ftp://foo.com to do stuff'
|
29
|
+
Filter::URI(string)
|
30
|
+
string.should == 'goto ftp://foo.com to do stuff'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should mutate when a bang is used" do
|
34
|
+
string = 'goto ftp://foo.com to do stuff'
|
35
|
+
Filter::URI!(string)
|
36
|
+
string.should == 'goto <a href="ftp://foo.com">ftp://foo.com</a> to do stuff'
|
26
37
|
end
|
27
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,9 +30,6 @@ extra_rdoc_files:
|
|
30
30
|
- lib/filters/profanity.rb
|
31
31
|
- lib/filters/uri.rb
|
32
32
|
- lib/filters/version.rb
|
33
|
-
- tasks/docs.rake
|
34
|
-
- tasks/gemspec.rake
|
35
|
-
- tasks/spec.rake
|
36
33
|
files:
|
37
34
|
- History.rdoc
|
38
35
|
- Manifest
|
@@ -55,9 +52,6 @@ files:
|
|
55
52
|
- spec/filter_uri_spec.rb
|
56
53
|
- spec/spec.opts
|
57
54
|
- spec/spec_helper.rb
|
58
|
-
- tasks/docs.rake
|
59
|
-
- tasks/gemspec.rake
|
60
|
-
- tasks/spec.rake
|
61
55
|
has_rdoc: true
|
62
56
|
homepage: http://github.com/visionmedia/filters
|
63
57
|
licenses: []
|
data/tasks/docs.rake
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
namespace :docs do
|
3
|
-
|
4
|
-
desc 'Remove rdoc products'
|
5
|
-
task :remove => [:clobber_docs]
|
6
|
-
|
7
|
-
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
8
|
-
task :open do
|
9
|
-
browser = ENV["BROWSER"] || "safari"
|
10
|
-
sh "open -a #{browser} doc/index.html"
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/tasks/gemspec.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'spec/rake/spectask'
|
3
|
-
|
4
|
-
desc "Run all specifications"
|
5
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
6
|
-
t.libs << "lib"
|
7
|
-
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
8
|
-
end
|
9
|
-
|
10
|
-
namespace :spec do
|
11
|
-
|
12
|
-
desc "Run all specifications verbosely"
|
13
|
-
Spec::Rake::SpecTask.new(:verbose) do |t|
|
14
|
-
t.libs << "lib"
|
15
|
-
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
16
|
-
end
|
17
|
-
|
18
|
-
desc "Run specific specification verbosely (specify SPEC)"
|
19
|
-
Spec::Rake::SpecTask.new(:select) do |t|
|
20
|
-
t.libs << "lib"
|
21
|
-
t.spec_files = [ENV["SPEC"]]
|
22
|
-
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|