code_reaper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +11 -0
- data/code_reaper.gemspec +19 -0
- data/lib/code_reaper.rb +7 -0
- data/lib/code_reaper/directory.rb +46 -0
- data/lib/code_reaper/file.rb +22 -0
- data/lib/code_reaper/strip.rb +30 -0
- data/lib/code_reaper/version.rb +3 -0
- data/test/code_reaper/directory_test.rb +13 -0
- data/test/code_reaper/file_test.rb +29 -0
- data/test/code_reaper/strip_test.rb +42 -0
- data/test/code_reaper_test.rb +4 -0
- data/test/fixtures/index.html +17 -0
- data/test/fixtures/index.html.erb +17 -0
- data/test/test_helper.rb +4 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Marcelo Eden
|
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,29 @@
|
|
1
|
+
# ErbReaper
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'erb_reaper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install erb_reaper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/code_reaper.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/code_reaper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Marcelo Eden"]
|
6
|
+
gem.email = ["edendroid@gmail.com"]
|
7
|
+
gem.description = %q{Remove evil tags from your code}
|
8
|
+
gem.summary = %q{Run the method strip to remove unwanted tags from your code}
|
9
|
+
gem.homepage = "https://github.com/3den/code_reaper"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "code_reaper"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = CodeReaper::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
end
|
data/lib/code_reaper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module CodeReaper
|
2
|
+
class Directory
|
3
|
+
attr_reader :dirname, :files
|
4
|
+
|
5
|
+
def initialize(dirname, options={}, input = ::Dir)
|
6
|
+
unless input.exist?(dirname)
|
7
|
+
raise InvalidDirectory, dirname
|
8
|
+
end
|
9
|
+
|
10
|
+
@dirname = dirname
|
11
|
+
load_files options
|
12
|
+
end
|
13
|
+
|
14
|
+
def strip regex
|
15
|
+
files.map do |file|
|
16
|
+
striped = File.new(file).strip regex
|
17
|
+
block_given? ? yield(striped) : striped
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def strip_file file, regex
|
24
|
+
File.new(file).strip regex
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_files options={}
|
28
|
+
@files = Dir["#{dirname}/**/**"]
|
29
|
+
select_files options[:only]
|
30
|
+
reject_files options[:except]
|
31
|
+
end
|
32
|
+
|
33
|
+
def select_files(regex)
|
34
|
+
return files unless regex
|
35
|
+
files.select! { |file| file =~ regex }
|
36
|
+
end
|
37
|
+
|
38
|
+
def reject_files(regex)
|
39
|
+
return files unless regex
|
40
|
+
files.reject! { |file| file =~ regex }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
InvalidDirectory = Class.new(ArgumentError)
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CodeReaper
|
2
|
+
class File
|
3
|
+
attr_reader :file, :filename
|
4
|
+
|
5
|
+
def initialize(filename, input = ::File)
|
6
|
+
unless input.file?(filename)
|
7
|
+
raise InvalidFile, filename
|
8
|
+
end
|
9
|
+
|
10
|
+
@filename = filename
|
11
|
+
@file = input.read filename
|
12
|
+
end
|
13
|
+
|
14
|
+
def strip(regex)
|
15
|
+
striped = Strip.new(file).strip regex
|
16
|
+
|
17
|
+
block_given? ? yield(striped) : striped
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
InvalidFile = Class.new(ArgumentError)
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CodeReaper
|
2
|
+
class Strip
|
3
|
+
attr_reader :str
|
4
|
+
|
5
|
+
STRIP_REGEX = {
|
6
|
+
erb: /\<\%(.*?)\%\>/,
|
7
|
+
handlebars: /\{\{(.*?)\}\}/
|
8
|
+
}
|
9
|
+
|
10
|
+
def initialize str
|
11
|
+
@str = str
|
12
|
+
end
|
13
|
+
|
14
|
+
def strip regex
|
15
|
+
str.gsub filter(regex), ''
|
16
|
+
end
|
17
|
+
|
18
|
+
STRIP_REGEX.keys.each do |key|
|
19
|
+
define_method "strip_#{key}" do
|
20
|
+
strip key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def filter regex
|
27
|
+
regex.is_a?(Symbol) ? STRIP_REGEX[regex] : regex
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module CodeReaper
|
4
|
+
describe Directory do
|
5
|
+
describe "#strip" do
|
6
|
+
it "removes all erb code from a file" do
|
7
|
+
reaper = Directory.new(FIXTURE_PATH)
|
8
|
+
striped = ::File.read("#{FIXTURE_PATH}index.html")
|
9
|
+
reaper.strip(:erb).must_equal [striped, striped]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module CodeReaper
|
4
|
+
describe File do
|
5
|
+
describe "#strip" do
|
6
|
+
it "removes all erb code from a file" do
|
7
|
+
reaper = File.new("#{FIXTURE_PATH}index.html.erb")
|
8
|
+
striped = ::File.read("#{FIXTURE_PATH}index.html")
|
9
|
+
reaper.strip(:erb).must_equal striped
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does nothing if there is nothing to remove" do
|
13
|
+
reaper = File.new("#{FIXTURE_PATH}index.html")
|
14
|
+
striped = ::File.read("#{FIXTURE_PATH}index.html")
|
15
|
+
reaper.strip(:erb).must_equal striped
|
16
|
+
end
|
17
|
+
|
18
|
+
it "acepts a block to interact with the stripec content" do
|
19
|
+
reaper = File.new("#{FIXTURE_PATH}index.html.erb")
|
20
|
+
striped = reaper.strip :erb do |text|
|
21
|
+
Strip.new(text).strip /\<p\>(.*)\<\/p\>/
|
22
|
+
end
|
23
|
+
|
24
|
+
striped.wont_include "<p>"
|
25
|
+
striped.must_include "<table>"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module CodeReaper
|
4
|
+
describe Strip do
|
5
|
+
describe "#strip" do
|
6
|
+
it "removes all erb tags" do
|
7
|
+
code = "my code<% if true %><%= \"hello\" %><% end %>"
|
8
|
+
reaper = Strip.new(code)
|
9
|
+
|
10
|
+
reaper.strip_erb.must_equal "my code"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "removes all handlebars tags" do
|
14
|
+
code = "my code{{ variable }}"
|
15
|
+
reaper = Strip.new(code)
|
16
|
+
|
17
|
+
reaper.strip_handlebars.must_equal "my code"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "removes a custom regex" do
|
21
|
+
code = "my code 123"
|
22
|
+
reaper = Strip.new(code)
|
23
|
+
|
24
|
+
reaper.strip(/\D|\s/).must_equal "123"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "removes a custom string" do
|
28
|
+
code = "my code 123"
|
29
|
+
reaper = Strip.new(code)
|
30
|
+
|
31
|
+
reaper.strip("123").must_equal "my code "
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does nothing if there are no matching tags" do
|
35
|
+
code = "my code{{ variable }}"
|
36
|
+
reaper = Strip.new(code)
|
37
|
+
|
38
|
+
reaper.strip_erb.must_equal "my code{{ variable }}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% if @inventories.blank? %>
|
2
|
+
<p>there are no inventories</p>
|
3
|
+
<% else %>
|
4
|
+
<table>
|
5
|
+
<% @inventories.each do |inventory| %>
|
6
|
+
<tr>
|
7
|
+
<td><%= inventory.title %></td>
|
8
|
+
<td><%= inventory.description %></td>
|
9
|
+
<td><%= inventory.user %></td>
|
10
|
+
<td><%= link_to 'Show', inventory %></td>
|
11
|
+
<td><%= link_to 'Edit', edit_inventory_path(inventory) %></td>
|
12
|
+
<td><%= link_to 'Destroy', inventory, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
13
|
+
</tr>
|
14
|
+
<% end %>
|
15
|
+
</table>
|
16
|
+
<% end %>
|
17
|
+
<%= link_to 'New Inventory', new_inventory_path %>
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code_reaper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcelo Eden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Remove evil tags from your code
|
31
|
+
email:
|
32
|
+
- edendroid@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- code_reaper.gemspec
|
43
|
+
- lib/code_reaper.rb
|
44
|
+
- lib/code_reaper/directory.rb
|
45
|
+
- lib/code_reaper/file.rb
|
46
|
+
- lib/code_reaper/strip.rb
|
47
|
+
- lib/code_reaper/version.rb
|
48
|
+
- test/code_reaper/directory_test.rb
|
49
|
+
- test/code_reaper/file_test.rb
|
50
|
+
- test/code_reaper/strip_test.rb
|
51
|
+
- test/code_reaper_test.rb
|
52
|
+
- test/fixtures/index.html
|
53
|
+
- test/fixtures/index.html.erb
|
54
|
+
- test/test_helper.rb
|
55
|
+
homepage: https://github.com/3den/code_reaper
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 2676411933027878250
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: 2676411933027878250
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Run the method strip to remove unwanted tags from your code
|
85
|
+
test_files:
|
86
|
+
- test/code_reaper/directory_test.rb
|
87
|
+
- test/code_reaper/file_test.rb
|
88
|
+
- test/code_reaper/strip_test.rb
|
89
|
+
- test/code_reaper_test.rb
|
90
|
+
- test/fixtures/index.html
|
91
|
+
- test/fixtures/index.html.erb
|
92
|
+
- test/test_helper.rb
|