redacted 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +34 -0
- data/app/assets/stylesheets/redacted.css +2 -0
- data/lib/redacted.rb +10 -0
- data/lib/redacted/action_view/helpers.rb +45 -0
- data/lib/redacted/engine.rb +4 -0
- data/lib/redacted/railtie.rb +9 -0
- data/lib/redacted/version.rb +3 -0
- data/redacted.gemspec +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/welcome_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/welcome/index.html.erb +42 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +38 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/welcome_controller_test.rb +9 -0
- data/test/redacted_helper_test.rb +63 -0
- data/test/redacted_test.rb +29 -0
- data/test/test_helper.rb +8 -0
- metadata +235 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 696543c83a20c2ec7c2e3e1be6062f94b220c5e6
|
4
|
+
data.tar.gz: e6a6d8bfd03718e43f5aae7b492ddf583a392a3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c90ebfe53f7445723c715c0871e7f6fd681ae41db835eae3ab773478945173a8e9c0ce54d1447bad0ec3227d764ec5f9cbb72b7130cb135a4c24ba231031fe4c
|
7
|
+
data.tar.gz: 25720cd8c67d238dff781e163da67c690b7af1b411f10c2f103e30c3056252e1532c79be7047c569ad22b465842e2622d8e9c886bb7a14fe4e3819a226072d3b
|
data/.gitignore
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.DS_Store
|
7
|
+
.ruby-version
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
*.bundle
|
21
|
+
*.so
|
22
|
+
*.o
|
23
|
+
*.a
|
24
|
+
mkmf.log
|
25
|
+
log/*.log
|
26
|
+
pkg/
|
27
|
+
test/dummy/db/*.sqlite3
|
28
|
+
test/dummy/db/*.sqlite3-journal
|
29
|
+
test/dummy/log/*.log
|
30
|
+
test/dummy/tmp/
|
31
|
+
test/dummy/.sass-cache
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kurt Funai
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Redacted
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'redacted'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
In your application.css, include the css file:
|
18
|
+
```
|
19
|
+
/*
|
20
|
+
*= require redacted
|
21
|
+
*/
|
22
|
+
```
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Redacted will convert both plaintext and HTML into redacted text.
|
26
|
+
|
27
|
+
After installing the gem, you will have access to a couple new methods in your Rails Views.
|
28
|
+
|
29
|
+
**Plain text (inline):**
|
30
|
+
```ruby
|
31
|
+
<%= redact('All of the maple syrup was stolen by aliens.')=>
|
32
|
+
#=> Iusto eos eligendi non iure rerum quia accus
|
33
|
+
|
34
|
+
All of the maple syrup was stolen by <%= redact('aliens')=>.
|
35
|
+
#=> All of the maple syrup was stolen by ducimu
|
36
|
+
```
|
37
|
+
The plain text method can create inline redacted text, or write out paragraphs to maintain the size/shape of paragraphs.
|
38
|
+
|
39
|
+
**Plain text (paragraphs):**
|
40
|
+
```ruby
|
41
|
+
<%= redact('Roses are red.\nViolets are blue.\n\nAll our base\r\n are belong to you.')=>
|
42
|
+
#=> <p>Roses are red.</p><p>Violets are blue.</p><p>All our base</p><p>are belong to you.</p>
|
43
|
+
```
|
44
|
+
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.
|
45
|
+
|
46
|
+
**HTML**
|
47
|
+
```ruby
|
48
|
+
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>')
|
49
|
+
#=> <p>adipisci labore quae perferendis impedit autem <br>odit impedit dolorem rerum</p><div>et quibusdam qui quis accusantium ullam</div>
|
50
|
+
```
|
51
|
+
Redacted parses the HTML string and replaces the text with lorem ipsum while maintaining the original HTML structure.
|
52
|
+
|
53
|
+
## How it works
|
54
|
+
Redacted takes text like `Winter is coming.` and replaces it with lorem ipsum of the same string length.
|
55
|
+
|
56
|
+
It then returns the redacted text surrounded by `<span></span>` tags that have the class `.redacted-text`.
|
57
|
+
```ruby
|
58
|
+
redact('Winter is coming.')
|
59
|
+
```
|
60
|
+
Becomes:
|
61
|
+
```html
|
62
|
+
<span class="redacted-text">quis saepe enimat</span>
|
63
|
+
```
|
64
|
+
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.
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it ( https://github.com/[my-github-username]/redacted/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Redacted'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.rdoc')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
33
|
+
|
34
|
+
|
data/lib/redacted.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Redacted
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
def ascii_redact str
|
5
|
+
length = str.length
|
6
|
+
"\u2588" * length unless length.zero?
|
7
|
+
end
|
8
|
+
|
9
|
+
def redact str
|
10
|
+
if str.include?("\n")
|
11
|
+
redact_paragraphs(str).join('').html_safe
|
12
|
+
else
|
13
|
+
redact_text(str).html_safe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def redact_paragraphs str
|
18
|
+
str.lines.map do |l|
|
19
|
+
"<p>#{redact_text(l.chomp)}</p>" if l.chomp.present?
|
20
|
+
end.reject{|l|l.nil?}
|
21
|
+
end
|
22
|
+
|
23
|
+
def redact_text str
|
24
|
+
return '' unless str
|
25
|
+
"<span class=\"redacted-text\">#{generate_fake_text(str)}</span>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def redact_html html_str
|
29
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(html_str)
|
30
|
+
doc.traverse do |ele|
|
31
|
+
ele.replace(redact_text(ele.content.chomp)) if ele.text?
|
32
|
+
end
|
33
|
+
doc.to_html
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def generate_fake_text str
|
38
|
+
word_count = str.split.size
|
39
|
+
fake_text = Faker::Lorem.words(word_count).join(' ')
|
40
|
+
fake_text << Faker::Lorem.characters(str.length - fake_text.length) if str.length > fake_text.length
|
41
|
+
fake_text.slice(0, str.length)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/redacted.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redacted/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redacted"
|
8
|
+
spec.version = Redacted::VERSION
|
9
|
+
spec.authors = ["Kurt Funai"]
|
10
|
+
spec.email = ["me@kurtfunai.com"]
|
11
|
+
spec.summary = "Convert strings into redacted text."
|
12
|
+
spec.description = "Allows a user to turn any string of text into a redacted block of the same size."
|
13
|
+
spec.homepage = "http://kurtfunai.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faker", "~> 1.4"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.3"
|
23
|
+
spec.add_dependency "railties", ">= 3.2", "< 5.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rails", "~> 4.1"
|
28
|
+
end
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*= require redacted
|
16
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<h1>Welcome#index</h1>
|
2
|
+
<p>Don't mind me... just redacting some stuff.</p>
|
3
|
+
|
4
|
+
<h3>Example:</h3>
|
5
|
+
<p>All of the maple syrup was stolen by aliens.</p>
|
6
|
+
<p><%= redact('All of the maple syrup was stolen by aliens.') %></p>
|
7
|
+
|
8
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, molestias maiores sit doloribus officiis quibusdam quod perspiciatis minus cupiditate necessitatibus vitae architecto atque error eaque repellat et quae aliquam tenetur!
|
9
|
+
<p><%= redact('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, molestias maiores sit doloribus officiis quibusdam quod perspiciatis minus cupiditate necessitatibus vitae architecto atque error eaque repellat et quae aliquam tenetur!') %></p>
|
10
|
+
|
11
|
+
<p>All of the maple syrup was stolen by <%= redact('aliens.') %></p>
|
12
|
+
|
13
|
+
<br><br><br><br>
|
14
|
+
<%
|
15
|
+
@new_lines =
|
16
|
+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. In, provident, cupiditate iusto magni eius tenetur voluptates quisquam nobis modi alias quia vitae necessitatibus et adipisci sunt placeat reprehenderit non molestiae.
|
17
|
+
|
18
|
+
Quas, possimus unde a cumque quasi. Saepe aliquam ex nobis autem recusandae minus libero! Facere incidunt optio repellat aperiam autem quam non dolore recusandae. Perspiciatis corporis beatae maxime illum quis.
|
19
|
+
|
20
|
+
Non aliquid architecto optio provident sequi placeat cupiditate similique voluptate eveniet nesciunt? Nisi, sint, veniam, delectus, obcaecati rem nobis veritatis explicabo saepe velit et impedit quae possimus qui quidem repellendus.'
|
21
|
+
%>
|
22
|
+
<%= @new_lines.html_safe %>
|
23
|
+
<br>
|
24
|
+
<%= redact(@new_lines).html_safe %>
|
25
|
+
|
26
|
+
<br><br><br><br>
|
27
|
+
<%
|
28
|
+
@p_tags = '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, tempora, qui temporibus ut a sapiente natus voluptate incidunt soluta velit ullam recusandae veniam nulla. A laboriosam reprehenderit esse quas voluptates!</p>
|
29
|
+
<p>Esse, similique, deleniti neque fuga ea perferendis praesentium vitae nam repudiandae atque labore nostrum autem omnis iusto in dolore blanditiis doloremque quae ut maxime placeat quo sit. Earum, enim, pariatur!</p>'
|
30
|
+
%>
|
31
|
+
<%= @p_tags.html_safe %>
|
32
|
+
<br>
|
33
|
+
<%= redact_html(@p_tags).html_safe %>
|
34
|
+
|
35
|
+
|
36
|
+
<br><br><br><br>
|
37
|
+
<%
|
38
|
+
@br = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, tempora, qui temporibus ut a sapiente natus voluptate incidunt soluta velit ullam recusandae veniam nulla. A laboriosam reprehenderit esse quas voluptates!<br>Esse, similique, deleniti neque fuga ea perferendis praesentium vitae nam repudiandae atque labore nostrum autem omnis iusto in dolore blanditiis doloremque quae ut maxime placeat quo sit. Earum, enim, pariatur!'
|
39
|
+
%>
|
40
|
+
<%= @br.html_safe %>
|
41
|
+
<br>
|
42
|
+
<%= redact_html(@br).html_safe %>
|
data/test/dummy/bin/rake
ADDED