stowaway 0.0.6 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +3 -2
- data/bin/stowaway +1 -1
- data/lib/stowaway/matcher.rb +42 -0
- data/lib/stowaway/runner.rb +1 -0
- data/lib/stowaway/sweeper.rb +10 -6
- data/spec/data/testfile1.txt +7 -3
- data/spec/data/testfile2.txt +8 -1
- data/spec/lib/sweeper_spec.rb +67 -16
- data/stowaway.gemspec +6 -4
- metadata +3 -2
data/VERSION.yml
CHANGED
data/bin/stowaway
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stowaway
|
2
|
+
class Matcher
|
3
|
+
def match?(line, file)
|
4
|
+
return true if attr_ref?(line, file)
|
5
|
+
return true if rails_js_ref?(line, file)
|
6
|
+
return true if rails_css_ref?(line, file)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def attr_ref?(line, file)
|
12
|
+
line =~ /(src|link|href)=(["|'])(#{file.fullpath})(\2)/
|
13
|
+
end
|
14
|
+
|
15
|
+
def rails_js_ref?(line, file)
|
16
|
+
return false unless line =~ /=?\s(javascript_include_tag)?\s(["|'])(.+)(\2)/
|
17
|
+
params = $3.gsub(/[\s|"]/, "").split(",")
|
18
|
+
params.each do |f|
|
19
|
+
if f =~ /\.js$/
|
20
|
+
return true if "/public/javascripts/#{f}" == file.fullpath
|
21
|
+
else
|
22
|
+
return true if "/public/javascripts/#{f}.js" == file.fullpath
|
23
|
+
end
|
24
|
+
end
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def rails_css_ref?(line, file)
|
29
|
+
return false unless line =~ /=?\s(stylesheet_link_tag)?\s(["|'])(.+)(\2)/
|
30
|
+
params = $3.gsub(/[\s|"]/, "").split(",")
|
31
|
+
params.each do |f|
|
32
|
+
if f =~ /\.css$/
|
33
|
+
return true if "/public/stylesheets/#{f}" == file.fullpath
|
34
|
+
else
|
35
|
+
return true if "/public/stylesheets/#{f}.css" == file.fullpath
|
36
|
+
end
|
37
|
+
end
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/stowaway/runner.rb
CHANGED
data/lib/stowaway/sweeper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'fshelpyhelp'
|
2
2
|
require_relative 'status'
|
3
|
+
require_relative "matcher"
|
3
4
|
|
4
5
|
module Stowaway
|
5
6
|
class Sweeper
|
@@ -9,17 +10,18 @@ module Stowaway
|
|
9
10
|
@files_to_find = files_to_find
|
10
11
|
@ignore = ext_to_ignore || [/^\.|\.jpg$|\.gif$|.png$/i]
|
11
12
|
@status = status
|
13
|
+
@matcher = Matcher.new
|
12
14
|
end
|
13
|
-
|
14
|
-
|
15
|
+
|
15
16
|
def sweep(path)
|
16
17
|
dir = Dir.new(path)
|
17
|
-
|
18
|
+
@root = path if @root.nil?
|
19
|
+
|
18
20
|
dir.each do |f|
|
19
21
|
next if ignore?(f)
|
20
|
-
|
22
|
+
|
21
23
|
file = File.join(dir.path, f)
|
22
|
-
|
24
|
+
|
23
25
|
if File.directory?(file)
|
24
26
|
sweep(file)
|
25
27
|
else
|
@@ -30,6 +32,7 @@ module Stowaway
|
|
30
32
|
end
|
31
33
|
|
32
34
|
private
|
35
|
+
|
33
36
|
def inspect_file(file)
|
34
37
|
@status.out "Sweeping: #{file}"
|
35
38
|
File.open(file, 'r') do |i|
|
@@ -41,7 +44,8 @@ module Stowaway
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def remove_match(line)
|
44
|
-
@files_to_find.delete_if { |file|
|
47
|
+
@files_to_find.delete_if { |file| @matcher.match?(line, file) }
|
45
48
|
end
|
49
|
+
|
46
50
|
end
|
47
51
|
end
|
data/spec/data/testfile1.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
this is a line of test text.
|
2
|
-
this
|
3
|
-
|
4
|
-
|
2
|
+
this filename on this line should be ignored: file1.js.
|
3
|
+
= javascript_include_tag "file.js"
|
4
|
+
= javascript_include_tag "jquery.js", "home/index.js"
|
5
|
+
= javascript_include_tag "application"
|
6
|
+
= stylesheet_link_tag "file.css"
|
7
|
+
= stylesheet_link_tag "reset", "common"
|
8
|
+
the end.
|
data/spec/data/testfile2.txt
CHANGED
@@ -1,2 +1,9 @@
|
|
1
1
|
Hello, I'm test data:
|
2
|
-
|
2
|
+
|
3
|
+
This is testing files with the same name but different paths
|
4
|
+
|
5
|
+
<img src="/fake/path1/button.jpg" />
|
6
|
+
<img src="/fake/path2/button.jpg" />
|
7
|
+
<a href="/fake/path/photo.jpg" />
|
8
|
+
<script type="text/javascript" src="/fake/path/file.js" ></script>
|
9
|
+
|
data/spec/lib/sweeper_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec/spec_helper"
|
2
|
+
require "lib/stowaway/file"
|
3
|
+
require "lib/stowaway/sweeper"
|
4
4
|
|
5
5
|
describe Stowaway::Sweeper do
|
6
6
|
|
@@ -10,36 +10,87 @@ describe Stowaway::Sweeper do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
before(:each) do
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@f3 = Stowaway::FileObj.new('/fake/file3.js')
|
16
|
-
@f4 = Stowaway::FileObj.new('/fake/also/file3.js')
|
17
|
-
@files = [@f1, @f2, @f3, @f4]
|
18
|
-
@status_mock = mock('status_mock', :null_object => true)
|
13
|
+
@files = []
|
14
|
+
@status_mock = mock("status_mock", :null_object => true)
|
19
15
|
end
|
20
16
|
|
21
|
-
it "should
|
22
|
-
|
17
|
+
it "should match images referened in a src attribute" do
|
18
|
+
@files << Stowaway::FileObj.new("/fake/path1/button.jpg")
|
19
|
+
sweeper.sweep("spec/data")
|
23
20
|
@files.should be_empty
|
24
21
|
end
|
25
22
|
|
23
|
+
it "should match images referened in an href attribute" do
|
24
|
+
@files << Stowaway::FileObj.new("/fake/path/photo.jpg")
|
25
|
+
sweeper.sweep("spec/data")
|
26
|
+
@files.should be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should match scripts referenced in a src attribute" do
|
30
|
+
@files << Stowaway::FileObj.new("/fake/path/file.js")
|
31
|
+
sweeper.sweep("spec/data")
|
32
|
+
@files.should be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should match scripts referenced in a rails javascript_include_tag helper" do
|
36
|
+
@files << Stowaway::FileObj.new("/public/javascripts/file.js")
|
37
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
38
|
+
@files.should be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should match scripts referenced in a rails javascript_include_tag helper when no extension is given" do
|
42
|
+
@files << Stowaway::FileObj.new("/public/javascripts/application.js")
|
43
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
44
|
+
@files.should be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should match multiple scripts referenced in a rails javascript_include_tag helper" do
|
48
|
+
@files << Stowaway::FileObj.new("/public/javascripts/jquery.js")
|
49
|
+
@files << Stowaway::FileObj.new("/public/javascripts/home/index.js")
|
50
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
51
|
+
@files.should be_empty
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should match css files referenced in a rails stylesheet_link_tag helper" do
|
55
|
+
@files << Stowaway::FileObj.new("/public/stylesheets/file.css")
|
56
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
57
|
+
@files.should be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should match multiple css files referenced in a rails stylesheet_link_tag helper" do
|
61
|
+
@files << Stowaway::FileObj.new("/public/stylesheets/reset.css")
|
62
|
+
@files << Stowaway::FileObj.new("/public/stylesheets/common.css")
|
63
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
64
|
+
@files.should be_empty
|
65
|
+
end
|
66
|
+
|
26
67
|
it "should not sweep through ignored file types" do
|
27
|
-
|
68
|
+
@files << Stowaway::FileObj.new("/public/stylesheets/reset.css")
|
69
|
+
sweeper([/^\.|\.rb$|testfile1/]).sweep("spec/data").length.should == 1
|
28
70
|
end
|
29
71
|
|
30
72
|
it "should output a message when sweeping through a file" do
|
31
73
|
@status_mock.should_receive(:out).with("Sweeping: spec/data/testfile1.txt").once
|
32
|
-
sweeper([/^\.|\.rb$|testfile2/]).sweep(
|
74
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
33
75
|
end
|
34
76
|
|
35
77
|
it "should flush the output after sweeping through a file" do
|
36
78
|
@status_mock.should_receive(:flush).once
|
37
|
-
sweeper([/^\.|\.rb$|testfile2/]).sweep(
|
79
|
+
sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should find images of the same name but with different paths" do
|
83
|
+
@files << Stowaway::FileObj.new("/fake/path1/button.jpg")
|
84
|
+
@files << Stowaway::FileObj.new("/fake/path2/button.jpg")
|
85
|
+
sweeper([/^\.|\.rb$/]).sweep("spec/data")
|
86
|
+
@files.should be_empty
|
38
87
|
end
|
39
88
|
|
40
89
|
it "should remove matches and leave files that were not found" do
|
41
|
-
|
42
|
-
|
90
|
+
@files << Stowaway::FileObj.new("/a/stowaway/file.txt")
|
91
|
+
sweeper([/^\.|\.rb$/]).sweep("spec/data")
|
92
|
+
@files.should_not be_empty
|
93
|
+
@files.first.fullpath.should == "/a/stowaway/file.txt"
|
43
94
|
end
|
44
95
|
|
45
96
|
end
|
data/stowaway.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stowaway}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Emilio Cavazos"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-14}
|
13
13
|
s.default_executable = %q{stowaway}
|
14
14
|
s.email = %q{ejcavazos@gmail.com}
|
15
15
|
s.executables = ["stowaway"]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/stowaway/file.rb",
|
29
29
|
"lib/stowaway/fshelpyhelp.rb",
|
30
30
|
"lib/stowaway/locator.rb",
|
31
|
+
"lib/stowaway/matcher.rb",
|
31
32
|
"lib/stowaway/options.rb",
|
32
33
|
"lib/stowaway/runner.rb",
|
33
34
|
"lib/stowaway/status.rb",
|
@@ -67,3 +68,4 @@ Gem::Specification.new do |s|
|
|
67
68
|
else
|
68
69
|
end
|
69
70
|
end
|
71
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stowaway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emilio Cavazos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-14 00:00:00 -08:00
|
13
13
|
default_executable: stowaway
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/stowaway/file.rb
|
34
34
|
- lib/stowaway/fshelpyhelp.rb
|
35
35
|
- lib/stowaway/locator.rb
|
36
|
+
- lib/stowaway/matcher.rb
|
36
37
|
- lib/stowaway/options.rb
|
37
38
|
- lib/stowaway/runner.rb
|
38
39
|
- lib/stowaway/status.rb
|