stowaway 0.1.2 → 0.1.5

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.
data/TODO.txt CHANGED
@@ -1,6 +1,9 @@
1
1
  == Future
2
2
 
3
- * when locator returns duplicate filenames, the files should be matched on path+name in order to retain uniqueness
4
- * currently, two files with the same name in different directories will be treated as the same file
3
+ * add verbose option to output file names of the files that weren't found and
4
+ the files that were only partially matched on name.
5
+ * ignore vendor folder
6
+ * ignore spec folder
7
+ * move appropriate sweeper tests to matcher
5
8
  * specify runner.rb
6
- * clean up it's dependencies
9
+ * clean up it's dependencies
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 2
4
+ :patch: 5
5
5
  :build:
data/bin/stowaway CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'stowaway/runner'
3
+ require 'lib/stowaway/runner'
4
4
  runner = Stowaway::Runner.new(ARGV)
5
5
  runner.run
data/lib/stowaway/file.rb CHANGED
@@ -2,8 +2,9 @@ module Stowaway
2
2
  class FileObj
3
3
  attr :fullpath
4
4
 
5
- def initialize(fullpath)
5
+ def initialize(fullpath, root = nil)
6
6
  @fullpath = fullpath
7
+ @root = root || Dir.pwd
7
8
  end
8
9
 
9
10
  def name
@@ -13,9 +14,14 @@ module Stowaway
13
14
  def path
14
15
  File.split(@fullpath)[0]
15
16
  end
17
+
18
+ def root_path
19
+ root = @root.split("/").last
20
+ @fullpath.sub(/^.+\/#{root}/, "")
21
+ end
16
22
 
17
23
  def ==(fileObj)
18
24
  self.fullpath == fileObj.fullpath
19
25
  end
20
26
  end
21
- end
27
+ end
@@ -18,7 +18,8 @@ module Stowaway
18
18
  end
19
19
 
20
20
  def find_all(path, files = [])
21
-
21
+ @root = path if @root.nil?
22
+
22
23
  dir = Dir.new(path)
23
24
 
24
25
  dir.each do |f|
@@ -29,7 +30,7 @@ module Stowaway
29
30
  if File.directory?(file)
30
31
  find_all file, files
31
32
  elsif type?(f)
32
- files << FileObj.new(file)
33
+ files << FileObj.new(file, @root)
33
34
  end
34
35
  end
35
36
  files
@@ -2,47 +2,58 @@ module Stowaway
2
2
  class Matcher
3
3
  def match?(line, file)
4
4
  @line, @file = line, file
5
- return true if html_attr_ref?
6
- return true if haml_attr_ref?
7
- return true if rails_js_ref?
8
- return true if rails_css_ref?
5
+ html_attr_ref? ||
6
+ haml_attr_ref? ||
7
+ rails_js_ref? ||
8
+ rails_css_ref? ||
9
+ css_url_ref?
9
10
  end
10
11
 
11
12
  private
12
13
 
13
14
  def html_attr_ref?
14
- @line =~ /(src|link|href|:href)\s?[=|=>]\s?(["|'])(#{@file.fullpath})(\2)/
15
+ exp = /(src|link|href|:href)\s?[=|=>]\s?(["|'])(%s)(\2)/
16
+ direct_or_public_dir_match?(exp)
15
17
  end
16
18
 
17
19
  def haml_attr_ref?
18
- @line =~ /(:src|:link|:href)(\s?=>\s?)(["|'])(#{@file.fullpath})(\3)/
20
+ exp = /(:src|:link|:href)(\s?=>\s?)(["|'])(%s)(\3)/
21
+ direct_or_public_dir_match?(exp)
19
22
  end
20
23
 
21
24
  def rails_js_ref?
22
- return false unless @line =~ /=?\s(javascript_include_tag)?\s(["|'])(.+)(\2)/
23
- params = $3.gsub(/[\s|"]/, "").split(",")
24
- params.each do |f|
25
- if f =~ /\.js$/
26
- return true if "/public/javascripts/#{f}" == @file.fullpath
27
- else
28
- return true if "/public/javascripts/#{f}.js" == @file.fullpath
29
- end
30
- end
31
- false
25
+ rails_helper_ref?("javascript_include", "javascripts", "js")
32
26
  end
33
27
 
34
28
  def rails_css_ref?
35
- return false unless @line =~ /=?\s(stylesheet_link_tag)?\s(["|'])(.+)(\2)/
29
+ rails_helper_ref?("stylesheet_link", "stylesheets", "css")
30
+ end
31
+
32
+ def css_url_ref?
33
+ exp = /url\(["|']?(%s)\)/
34
+ direct_or_public_dir_match?(exp)
35
+ end
36
+
37
+ def rails_helper_ref?(helper_name, directory, extension)
38
+ expression = Regexp.new(/=?\s(%s_tag)?\s(["|'])(.+)(\2)/.to_s % helper_name)
39
+ return false unless @line =~ expression
36
40
  params = $3.gsub(/[\s|"]/, "").split(",")
37
41
  params.each do |f|
38
- if f =~ /\.css$/
39
- return true if "/public/stylesheets/#{f}" == @file.fullpath
40
- else
41
- return true if "/public/stylesheets/#{f}.css" == @file.fullpath
42
- end
42
+ return true if "/public/#{directory}/#{f}" == @file.root_path ||
43
+ "/public/#{directory}/#{f}.#{extension}" == @file.root_path
43
44
  end
44
45
  false
45
46
  end
46
47
 
48
+ def direct_or_public_dir_match?(expression)
49
+ @line =~ Regexp.new(expression.to_s % @file.fullpath) ||
50
+ @line =~ Regexp.new(expression.to_s % trim_public)
51
+ end
52
+
53
+ def trim_public
54
+ # remove /public from the beginning of the path
55
+ @file.root_path.sub(/\/public/, "")
56
+ end
57
+
47
58
  end
48
59
  end
@@ -10,10 +10,11 @@ module Stowaway
10
10
  end
11
11
 
12
12
  def run
13
- p "Locating files ..."
13
+ print "\nLocating files ... "
14
14
  locator = Stowaway::Locator.new(@options.file_types)
15
15
  files = locator.find_all @options.path
16
- p "#{files.size} files located"
16
+ @total = files.length
17
+ p "#{@total} files located"
17
18
 
18
19
  fs = Stowaway::Sweeper.new files
19
20
  respond fs.sweep @options.path
@@ -21,13 +22,19 @@ module Stowaway
21
22
 
22
23
  private
23
24
 
24
- def respond(not_found)
25
- if not_found.empty?
25
+ def respond(results)
26
+ if results[:files_to_find].empty?
26
27
  print "Zero stowaways found. You run a tight ship.\n\n"
27
28
  else
28
- print "\nYou have #{not_found.length} stowaway(s)\n"
29
- print "--------------------------\n\n"
30
- not_found.each_with_index { |f, i| print "#{i+1}: #{f.fullpath}\n" }
29
+ print "\nYou have #{results[:files_to_find].length} stowaway(s) ... shameful\n\n"
30
+
31
+ unless results[:name_only].empty?
32
+ p "Warning: #{results[:name_only].length} file(s) partially matched on name only"
33
+ end
34
+
35
+ 100.times { print "-" }
36
+ print "\n\n"
37
+ results[:files_to_find].each_with_index { |f, i| print "#{i+1}: #{f.root_path}\n" }
31
38
  print "\n"
32
39
  end
33
40
  end
@@ -6,7 +6,6 @@ module Stowaway
6
6
  end
7
7
 
8
8
  def flush
9
- sleep(0.12)
10
9
  print RESET
11
10
  $stdout.flush
12
11
  end
@@ -7,15 +7,14 @@ module Stowaway
7
7
  include FSHelpyHelp
8
8
 
9
9
  def initialize(files_to_find, status = Status.new, ext_to_ignore = nil)
10
- @files_to_find = files_to_find
11
- @ignore = ext_to_ignore || [/^\.|\.jpg$|\.gif$|.png$/i]
10
+ @results = { :files_to_find => files_to_find, :name_only => []}
11
+ @ignore = ext_to_ignore || [/^\.|\.jpg$|\.gif$|.png$|.ico$/i]
12
12
  @status = status
13
13
  @matcher = Matcher.new
14
14
  end
15
15
 
16
16
  def sweep(path)
17
17
  dir = Dir.new(path)
18
- @root = path if @root.nil?
19
18
 
20
19
  dir.each do |f|
21
20
  next if ignore?(f)
@@ -28,7 +27,7 @@ module Stowaway
28
27
  inspect_file(file)
29
28
  end
30
29
  end
31
- @files_to_find
30
+ @results
32
31
  end
33
32
 
34
33
  private
@@ -37,14 +36,21 @@ module Stowaway
37
36
  @status.out "Sweeping: #{file}"
38
37
  File.open(file, 'r') do |i|
39
38
  while line = i.gets
40
- remove_match(line)
39
+ remove_match(line) #rescue nil
41
40
  end
42
41
  end
43
42
  @status.flush
44
43
  end
45
44
 
46
45
  def remove_match(line)
47
- @files_to_find.delete_if { |file| @matcher.match?(line, file) }
46
+ @results[:files_to_find].delete_if do |file|
47
+ if @matcher.match?(line, file)
48
+ true
49
+ elsif line.include?(file.name)
50
+ @results[:name_only] << file
51
+ true
52
+ end
53
+ end
48
54
  end
49
55
 
50
56
  end
@@ -1,11 +1,17 @@
1
1
  this is a line of test text.
2
2
  this filename on this line should be ignored: file1.js.
3
+
3
4
  = javascript_include_tag "file.js"
4
5
  = javascript_include_tag "jquery.js", "home/index.js"
5
6
  = javascript_include_tag "application"
6
7
  = stylesheet_link_tag "file.css"
7
8
  = stylesheet_link_tag "reset", "common"
9
+
8
10
  %a{ :href => "/images/haml.jpg", :title => "haml" }
9
11
  %img{ :src => "/images/file.jpg", :alt => "file" }
10
12
 
13
+ background: url("/images/header.png") no-repeat
14
+ background: url('/images/header.png') no-repeat
15
+ background: url(/images/header.png) no-repeat
16
+
11
17
  the end.
@@ -26,18 +26,30 @@ describe Stowaway::Sweeper do
26
26
  @files.should be_empty
27
27
  end
28
28
 
29
- it "should match images referenced in an href attribute when using haml" do
30
- @files << Stowaway::FileObj.new("/images/haml.jpg")
29
+ it "should match images referenced in a src attribute when files are stored in public folder" do
30
+ @files << Stowaway::FileObj.new("/public/fake/path1/button.jpg")
31
31
  sweeper.sweep("spec/data")
32
32
  @files.should be_empty
33
33
  end
34
34
 
35
- it "should match images referenced in a src attribute when using haml" do
35
+ it "should match images referenced in an haml href attribute" do
36
+ @files << Stowaway::FileObj.new("/images/haml.jpg")
37
+ sweeper.sweep("spec/data")
38
+ @files.should be_empty
39
+ end
40
+
41
+ it "should match images referenced in a haml src attribute" do
36
42
  @files << Stowaway::FileObj.new("/images/file.jpg")
37
43
  sweeper.sweep("spec/data")
38
44
  @files.should be_empty
39
45
  end
40
46
 
47
+ it "should match images referenced in a haml src attribute when files are stored in public folder" do
48
+ @files << Stowaway::FileObj.new("/public/images/file.jpg")
49
+ sweeper.sweep("spec/data")
50
+ @files.should be_empty
51
+ end
52
+
41
53
  it "should match scripts referenced in a src attribute" do
42
54
  @files << Stowaway::FileObj.new("/fake/path/file.js")
43
55
  sweeper.sweep("spec/data")
data/stowaway.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stowaway}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.5"
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{2010-02-15}
12
+ s.date = %q{2010-02-19}
13
13
  s.default_executable = %q{stowaway}
14
14
  s.email = %q{ejcavazos@gmail.com}
15
15
  s.executables = ["stowaway"]
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.1.2
4
+ version: 0.1.5
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: 2010-02-15 00:00:00 -08:00
12
+ date: 2010-02-19 00:00:00 -08:00
13
13
  default_executable: stowaway
14
14
  dependencies: []
15
15