Redacted
The goal of Redacted is to take text like My maple syrup was stolen by a moose!
and black it out, just like on a top secret document!
To keep the redacted information private, it turns the text into Lorem ipsum. It tries its best to maintain the same size & shape of the text that is being redacted.
Redacted works with both plain text and HTML.
Installation
Add this line to your application's Gemfile:
gem 'redacted'
And then execute:
$ bundle
In your application.css, include the css file:
/*
*= require redacted
*/
Usage
After installing the gem, you will have access to a couple new methods in your Rails Views.
redact(str)
# Plain text (inline):
<%= redact("You know nothing Jon Snow") %>
#=> Iusto eos eligendi non iu
All of the maple syrup was stolen by <%= redact("aliens") %>.
#=> All of the maple syrup was stolen by ducimu
# Plain text (paragraphs):
<%= redact("Roses are red.\nViolets are blue.\n\nAll our base\r\n are belong to you.") %>
#=> <p>consequatur et</p><p>excepturi sed dol</p><p>maxime id su</p><p>at non quia nonotas</p>
The #redact
method will try to guess if the text should be inline or not, but you can also explictly call redact_text(str)
for inline rendering, or redact_paragraphs(str)
for paragraphs wrapped in <p>
tags.
redact_html(html_str)
redact_html("<p>A mind needs books as a sword needs a whetstone<br>if it is to keep its edge.</p><div>- George R.R. Martin, A Game of Thrones</div>")
#=> <p>adipisci labore quae perferendis impedit autem <br>odit impedit dolorem rerum</p><div>et quibusdam qui quis accusantium ullam</div>
Redacted parses the HTML string and replaces the text with lorem ipsum while maintaining the original HTML structure.
How it works
Redacted takes text like Winter is coming.
and replaces it with lorem ipsum of the same string length.
It then returns the redacted text surrounded by <span></span>
tags that have the class .redacted-text
.
redact("Winter is coming.")
Becomes:
<span class="redacted-text">quis saepe enimat</span>
Some basic CSS styles are included with the gem, but you can overwrite the look of the text by adding your own styles if you prefer.
Contributing
- Fork it ( https://github.com/[my-github-username]/redacted/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request