Redacted
The goal of Redacted is to take a block of text, turn it into Lorem ipsum of the same size, and then apply styles with CSS to make the text appear redacted! Just like top secret documents.
Basically it takes a string like My maple syrup was stolen by a moose!
and turns it into a blacked-out block of text that is roughly the same size.
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
Redacted will convert both plaintext and HTML into redacted text.
After installing the gem, you will have access to a couple new methods in your Rails Views.
Plain text (inline):
<%= redact('All of the maple syrup was stolen by aliens.')=>
#=> Iusto eos eligendi non iure rerum quia accus
All of the maple syrup was stolen by <%= redact('aliens')=>.
#=> All of the maple syrup was stolen by ducimu
The plain text method can create inline redacted text, or write out paragraphs to maintain the size/shape of paragraphs.
Plain text (paragraphs):
<%= redact('Roses are red.\nViolets are blue.\n\nAll our base\r\n are belong to you.')=>
#=> <p>Roses are red.</p><p>Violets are blue.</p><p>All our base</p><p>are belong to you.</p>
The #redact
method will try to guess if the text should be inline or not, but you can also explictly call redact_text
or redact_paragraphs
if you want specific functionality.
HTML
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