Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 7f7dd00

Browse files
committed
Once again, fixing the code blocks in the readme file
1 parent 32e3b91 commit 7f7dd00

File tree

1 file changed

+124
-121
lines changed

1 file changed

+124
-121
lines changed

Diff for: README.md

+124-121
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ Obscenity is a profanity filter gem for Ruby, Rails (through ActiveModel), and R
66

77
Add this line to your application's Gemfile:
88

9-
```ruby
10-
gem 'obscenity'
11-
```
9+
```ruby
10+
gem 'obscenity'
11+
```
1212

1313
And then execute:
1414

15-
```ruby
16-
bundle install
17-
```
15+
```ruby
16+
bundle install
17+
```
1818

1919
Or install it yourself as:
2020

21-
```ruby
22-
gem install obscenity
23-
```
21+
```ruby
22+
gem install obscenity
23+
```
2424

2525
## Compatibility
2626

@@ -56,107 +56,107 @@ The following methods are available to use with Obscenity:
5656

5757
Example:
5858

59-
```ruby
60-
Obscenity.configure do |config|
61-
config.blacklist = "path/to/blacklist/file.yml"
62-
config.whitelist = ["safe", "word"]
63-
config.replacement = :stars
64-
end
65-
```
59+
```ruby
60+
Obscenity.configure do |config|
61+
config.blacklist = "path/to/blacklist/file.yml"
62+
config.whitelist = ["safe", "word"]
63+
config.replacement = :stars
64+
end
65+
```
6666

6767
### Basic Usage
6868

6969
`Obscenity.profane?(text)` analyses the content and returns `true` or `false` based on its profanity:
7070

71-
```ruby
72-
Obscenity.profane?("simple text")
73-
=> false
74-
75-
Obscenity.profane?("text with shit")
76-
=> true
77-
```
71+
```ruby
72+
Obscenity.profane?("simple text")
73+
=> false
74+
75+
Obscenity.profane?("text with shit")
76+
=> true
77+
```
7878

7979
`Obscenity.sanitize(text)` sanities the content and returns a new sanitized content (if profane) or the original content (if not profane):
8080

81-
```ruby
82-
Obscenity.sanitize("simple text")
83-
=> "simple text"
84-
85-
Obscenity.sanitize("text with shit")
86-
=> "text with $@!#%"
87-
```
81+
```ruby
82+
Obscenity.sanitize("simple text")
83+
=> "simple text"
84+
85+
Obscenity.sanitize("text with shit")
86+
=> "text with $@!#%"
87+
```
8888

8989
`Obscenity.replacement(style).sanitize(text)` allows you to pass the replacement method to be used when sanitizing the given content. Available replacement values are `:default`, `:garbled`, `:stars`, `:vowels`, and a custom string.
9090

91-
```ruby
92-
Obscenity.replacement(:default).sanitize("text with shit")
93-
=> "text with $@!#%"
91+
```ruby
92+
Obscenity.replacement(:default).sanitize("text with shit")
93+
=> "text with $@!#%"
9494

95-
Obscenity.replacement(:garbled).sanitize("text with shit")
96-
=> "text with $@!#%"
97-
98-
Obscenity.replacement(:stars).sanitize("text with shit")
99-
=> "text with ****"
95+
Obscenity.replacement(:garbled).sanitize("text with shit")
96+
=> "text with $@!#%"
97+
98+
Obscenity.replacement(:stars).sanitize("text with shit")
99+
=> "text with ****"
100100

101-
Obscenity.replacement(:vowels).sanitize("text with shit")
102-
=> "text with sh*t"
101+
Obscenity.replacement(:vowels).sanitize("text with shit")
102+
=> "text with sh*t"
103103

104-
Obscenity.replacement("[censored]").sanitize("text with shit")
105-
=> "text with [censored]"
106-
```
104+
Obscenity.replacement("[censored]").sanitize("text with shit")
105+
=> "text with [censored]"
106+
```
107107

108108
`Obscenity.offensive(text)` returns an array of profane words in the given content:
109109

110-
```ruby
111-
Obscenity.offensive("simple text")
112-
=> []
113-
114-
Obscenity.offensive("text with shit and another biatch")
115-
=> ["shit", "biatch"]
116-
```
110+
```ruby
111+
Obscenity.offensive("simple text")
112+
=> []
113+
114+
Obscenity.offensive("text with shit and another biatch")
115+
=> ["shit", "biatch"]
116+
```
117117

118118
### ActiveModel
119119

120120
The ActiveModel component provides easy profanity validation for your models.
121121

122122
First, you need to explicitly require the ActiveModel component:
123123

124-
```ruby
125-
require 'obscenity/active_model'
126-
```
124+
```ruby
125+
require 'obscenity/active_model'
126+
```
127127

128128
Then you can use it in your models as such:
129129

130-
```ruby
131-
# ActiveRecord example
132-
class Post < ActiveRecord::Base
133-
134-
validates :title, obscenity: true
135-
validates :body, obscenity: { sanitize: true, replacement: "[censored]" }
136-
end
130+
```ruby
131+
# ActiveRecord example
132+
class Post < ActiveRecord::Base
133+
134+
validates :title, obscenity: true
135+
validates :body, obscenity: { sanitize: true, replacement: "[censored]" }
136+
end
137137

138-
# MongoMapper example
139-
class Book
140-
include MongoMapper::Document
138+
# MongoMapper example
139+
class Book
140+
include MongoMapper::Document
141141

142-
key :title, String
143-
key :body, String
142+
key :title, String
143+
key :body, String
144144

145-
validates :title, obscenity: true
146-
validates :body, obscenity: { sanitize: true, replacement: :vowels }
147-
end
148-
149-
# Mongoid example
150-
class Page
151-
include Mongoid::Document
145+
validates :title, obscenity: true
146+
validates :body, obscenity: { sanitize: true, replacement: :vowels }
147+
end
148+
149+
# Mongoid example
150+
class Page
151+
include Mongoid::Document
152152

153-
field :title, type: String
154-
field :body, type: String
153+
field :title, type: String
154+
field :body, type: String
155155

156-
validates :title, obscenity: true
157-
validates :body, obscenity: { sanitize: true, replacement: :garbled }
158-
end
159-
```
156+
validates :title, obscenity: true
157+
validates :body, obscenity: { sanitize: true, replacement: :garbled }
158+
end
159+
```
160160

161161
The following usage is available:
162162

@@ -172,14 +172,15 @@ You can use Obscenity as a Rack middleware to automatically reject requests that
172172

173173
First you need to explicitly require the Rack middleware:
174174

175-
```ruby
176-
require 'obscenity/rack'
177-
```
175+
```ruby
176+
require 'obscenity/rack'
177+
```
178+
178179
And to use the middleware, the basic syntax is:
179180

180-
```ruby
181-
use Rack::Obscenity, {} # options Hash
182-
```
181+
```ruby
182+
use Rack::Obscenity, {} # options Hash
183+
```
183184

184185
You need to use the options below inside the options Hash (above)
185186

@@ -189,73 +190,75 @@ Any of the following options can be used to reject a request.
189190

190191
`reject: true` : will reject a request if any parameter value contains profanity.
191192

192-
```ruby
193-
use Rack::Obscenity, reject: true
194-
```
193+
```ruby
194+
use Rack::Obscenity, reject: true
195+
```
196+
195197
`reject: { params: [] }` : will analyze the selected parameters and reject the request if their values contain profanity.
196198

197-
```ruby
198-
use Rack::Obscenity, reject: { params: [:foo, :bar] }
199-
```
199+
```ruby
200+
use Rack::Obscenity, reject: { params: [:foo, :bar] }
201+
```
200202

201203
`reject: { message: 'Custom message' }` : will reject a request and display the custom message if any parameter value contains profanity
202204

203-
```ruby
204-
use Rack::Obscenity, reject: { message: "We don't allow profanity!" }
205-
```
205+
```ruby
206+
use Rack::Obscenity, reject: { message: "We don't allow profanity!" }
207+
```
206208

207209
`reject: { path: 'path/to/file' }` : will reject a request and render the custom file if any parameter value contains profanity
208210

209-
```ruby
210-
use Rack::Obscenity, reject: { path: 'public/no_profanity.html' }
211-
```
211+
```ruby
212+
use Rack::Obscenity, reject: { path: 'public/no_profanity.html' }
213+
```
212214

213215
More usage example:
214216

215-
```ruby
216-
# Rejects the request for all params and renders a file
217-
use Rack::Obscenity, reject: { params: :all, path: 'public/no_profanity.html' }
217+
```ruby
218+
# Rejects the request for all params and renders a file
219+
use Rack::Obscenity, reject: { params: :all, path: 'public/no_profanity.html' }
218220

219-
# Rejects the request based on the selected params and renders a file
220-
use Rack::Obscenity, reject: { params: [:foo, :bar], path: 'public/no_profanity.html' }
221+
# Rejects the request based on the selected params and renders a file
222+
use Rack::Obscenity, reject: { params: [:foo, :bar], path: 'public/no_profanity.html' }
221223

222-
# Rejects the request based on the selected params and displays a message
223-
use Rack::Obscenity, reject: { params: [:foo, :bar], message: "Profanity is not allowed!" }
224-
```
224+
# Rejects the request based on the selected params and displays a message
225+
use Rack::Obscenity, reject: { params: [:foo, :bar], message: "Profanity is not allowed!" }
226+
```
225227

226228
#### Sanitizing Requests:
227229

228230
Any of the following options can be used to sanitize a request.
229231

230232
`sanitize: true` : will sanitize all parameter values if they contain profanity.
231233

232-
```ruby
233-
use Rack::Obscenity, sanitize: true
234-
```
234+
```ruby
235+
use Rack::Obscenity, sanitize: true
236+
```
237+
235238
`sanitize: { params: [] }` : will analyze the selected parameters and sanitize them if their values contain profanity.
236239

237-
```ruby
238-
use Rack::Obscenity, sanitize: { params: [:foo, :bar] }
239-
```
240+
```ruby
241+
use Rack::Obscenity, sanitize: { params: [:foo, :bar] }
242+
```
240243

241244
`sanitize: { replacement: (:default | :garbled | :stars | :vowels | 'custom') }` : will use this replacement method when sanitizing parameter values
242245

243-
```ruby
244-
use Rack::Obscenity, sanitize: { replacement: :vowels }
245-
```
246+
```ruby
247+
use Rack::Obscenity, sanitize: { replacement: :vowels }
248+
```
246249

247250
More usage example:
248251

249-
```ruby
250-
# Sanitizes all params and replaces their values using :stars
251-
use Rack::Obscenity, sanitize: { params: :all, replacement: :stars }
252+
```ruby
253+
# Sanitizes all params and replaces their values using :stars
254+
use Rack::Obscenity, sanitize: { params: :all, replacement: :stars }
252255

253-
# Sanitizes the given params and replaces their values using a custom word
254-
use Rack::Obscenity, sanitize: { params: [:foo, :bar], replacement: "[censored]" }
256+
# Sanitizes the given params and replaces their values using a custom word
257+
use Rack::Obscenity, sanitize: { params: [:foo, :bar], replacement: "[censored]" }
255258

256-
# Sanitizes all params and replaces their values using :garbled
257-
use Rack::Obscenity, sanitize: { replacement: :garbled }
258-
```
259+
# Sanitizes all params and replaces their values using :garbled
260+
use Rack::Obscenity, sanitize: { replacement: :garbled }
261+
```
259262

260263
## Contributing to obscenity
261264

0 commit comments

Comments
 (0)