wraith 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ad5c9e4eecd6cbe1a694bc29c62410ff45b7c86
4
- data.tar.gz: c84b6e122617e02962a281ad885717342c919d35
3
+ metadata.gz: 49d53e6583e9fabf57c3f55f25567c2ac8ce32ec
4
+ data.tar.gz: 88d3d71b9c69d819769a5ab18d92a5433d1c2900
5
5
  SHA512:
6
- metadata.gz: 5d415de27039b977ba067eac6a0f17edacdd301ea5a43e5058454b8b8b35151f1a1bc9cc0b0216695374ff9b2d11bce6afc90ffe11299c5ca14af8818ade9917
7
- data.tar.gz: 68d6c30abf6631ba704fe705290b9ca909d95859b8268e0886ef19773c991fdb90aa36972fba343ad3a7089729ca41f3e45365005b4a3c90ad8110f81d642419
6
+ metadata.gz: f676037d79b75fb02c4912bc23a4ab119fd5a0ab7645bade4ecc4abb3672c0c08cda53a53942989d8f31eb71edd8c0cb1780e6435e1b64e14fac2c6b6ed68465
7
+ data.tar.gz: 7610535f0bfe23ff74df774502e32f8f63ec30423a3e42e1b1f071deb31c387b9d51249e1ef7f60895cc71f896aafd528afa908502ab33ba178ea4c9fba68ed7
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ shots/
3
3
  data.txt
4
4
  .DS_Store
5
5
  *.swp
6
+ Gemfile.lock
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ require 'wraith/spider'
7
7
  require 'wraith/folder'
8
8
  require 'wraith/thumbnails'
9
9
  require 'wraith/compare_images'
10
- require 'wraith/images'
11
10
  require 'wraith/gallery'
12
11
 
13
12
  @config = ('config')
@@ -19,7 +18,7 @@ task :config, [:yaml] do |_t, custom|
19
18
  Rake::Task['default'].invoke
20
19
  end
21
20
 
22
- task default: [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :check_images, :crop_images, :compare_images, :generate_thumbnails, :generate_gallery] do
21
+ task default: [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :crop_images, :compare_images, :generate_thumbnails, :generate_gallery] do
23
22
  puts 'Done!'
24
23
  end
25
24
 
@@ -53,11 +52,6 @@ task :crop_images do
53
52
  crop.crop_images
54
53
  end
55
54
 
56
- task :check_images do
57
- image = Wraith::Images.new(@config)
58
- image.files
59
- end
60
-
61
55
  task :generate_thumbnails do
62
56
  thumbs = Wraith::Thumbnails.new(@config)
63
57
  thumbs.generate_thumbnails
data/bin/wraith CHANGED
@@ -3,7 +3,7 @@
3
3
  begin
4
4
  require 'wraith/cli'
5
5
  Wraith::CLI.start
6
- rescue Interrupt => e
6
+ rescue Interrupt
7
7
  puts "\nQuitting..."
8
8
  exit 1
9
9
  rescue SystemExit => e
data/lib/wraith/cli.rb CHANGED
@@ -6,7 +6,6 @@ require 'wraith/spider'
6
6
  require 'wraith/folder'
7
7
  require 'wraith/thumbnails'
8
8
  require 'wraith/compare_images'
9
- require 'wraith/images'
10
9
  require 'wraith/gallery'
11
10
 
12
11
  class Wraith::CLI < Thor
@@ -41,11 +40,6 @@ class Wraith::CLI < Thor
41
40
  spider = Wraith::Spidering.new(config_name)
42
41
  spider.check_for_paths
43
42
  end
44
-
45
- def check_images(config_name)
46
- image = Wraith::Images.new(config_name)
47
- image.files
48
- end
49
43
  end
50
44
 
51
45
  desc 'save_images [config_name]', 'captures screenshots'
@@ -85,10 +79,17 @@ class Wraith::CLI < Thor
85
79
  check_for_paths(config)
86
80
  setup_folders(config)
87
81
  save_images(config)
88
- check_images(config)
89
82
  crop_images(config)
90
83
  compare_images(config)
91
84
  generate_thumbnails(config)
92
85
  generate_gallery(config)
93
86
  end
87
+
88
+ desc 'multi_capture [filelist]', 'A Batch of Wraith Jobs'
89
+ def multi_capture(filelist)
90
+ config_array = IO.readlines(filelist)
91
+ config_array.each do |config|
92
+ capture(config.chomp)
93
+ end
94
+ end
94
95
  end
data/lib/wraith/crop.rb CHANGED
@@ -26,10 +26,14 @@ class Wraith::CropImages
26
26
  height_to_crop_to = compare_height
27
27
  end
28
28
 
29
- Wraith::Wraith.crop_images(image_to_crop, height_to_crop_to)
29
+ crop_task(image_to_crop, height_to_crop_to)
30
30
  end
31
31
  end
32
32
 
33
+ def crop_task(crop, height)
34
+ `convert #{crop} -background none -extent 0x#{height} #{crop}`
35
+ end
36
+
33
37
  def image_height(image)
34
38
  File.open(image, 'rb') do |fh|
35
39
  size = ImageSize.new(fh.read).size
data/lib/wraith/folder.rb CHANGED
@@ -44,17 +44,16 @@ class Wraith::FolderManager
44
44
 
45
45
  # Tidy up the shots folder, removing uncessary files
46
46
  #
47
- def tidy_shots_folder dirs
47
+ def tidy_shots_folder(dirs)
48
48
  if wraith.mode == 'diffs_only'
49
49
  dirs.each do |a, b|
50
50
  # If we are running in "diffs_only mode, and none of the variants show a difference
51
51
  # we remove the file from the shots folder
52
- if b.none? {|k, v| v[:data] > 0}
52
+ if b.none? { |_k, v| v[:data] > 0 }
53
53
  FileUtils.rm_rf("#{wraith.directory}/#{a}")
54
54
  dirs.delete(a)
55
55
  end
56
56
  end
57
57
  end
58
58
  end
59
-
60
59
  end
@@ -70,10 +70,10 @@ class Wraith::GalleryGenerator
70
70
  end
71
71
  end
72
72
  @folder_manager.tidy_shots_folder(@dirs)
73
- if [ 'diffs_only', 'diffs_first' ].include?(wraith.mode)
74
- @sorted = @dirs.sort_by { |category, sizes| -1 * sizes.max_by { |size, dict| dict[:data]}[1][:data] }
73
+ if %w(diffs_only diffs_first).include?(wraith.mode)
74
+ @sorted = @dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
75
75
  else
76
- @sorted = @dirs.sort_by { |category, sizes| category }
76
+ @sorted = @dirs.sort_by { |category, _sizes| category }
77
77
  end
78
78
  # The sort has made this into an enumerable, convert it back to a Hash
79
79
  Hash[@sorted]
@@ -39,7 +39,7 @@ class Wraith::SaveImages
39
39
 
40
40
  def attempt_image_capture(width, url, filename, max_attempts)
41
41
  max_attempts.times do |i|
42
- wraith.capture_page_image engine, url, width, filename
42
+ capture_page_image engine, url, width, filename
43
43
 
44
44
  return if File.exist? filename
45
45
 
@@ -80,8 +80,16 @@ class Wraith::SaveImages
80
80
  FileUtils.cp invalid, filename
81
81
 
82
82
  # Set width of fallback image
83
- wraith.set_image_width(filename, width)
83
+ set_image_width(filename, width)
84
84
  end
85
85
  end
86
86
  end
87
+
88
+ def set_image_width(image, width)
89
+ `convert #{image} -background none -extent #{width}x0 #{image}`
90
+ end
91
+
92
+ def capture_page_image(browser, url, width, file_name)
93
+ puts `"#{browser}" "#{wraith.phantomjs_options}" "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}"`
94
+ end
87
95
  end
data/lib/wraith/spider.rb CHANGED
@@ -4,7 +4,6 @@ require 'nokogiri'
4
4
  require 'uri'
5
5
 
6
6
  class Wraith::Spidering
7
-
8
7
  def initialize(config)
9
8
  @wraith = Wraith::Wraith.new(config)
10
9
  end
@@ -24,7 +23,6 @@ class Wraith::Spidering
24
23
  end
25
24
 
26
25
  class Wraith::Spider
27
-
28
26
  def initialize(wraith)
29
27
  @wraith = wraith
30
28
  @paths = {}
@@ -40,19 +38,16 @@ class Wraith::Spider
40
38
  def write_file
41
39
  File.open(@wraith.spider_file, 'w+') { |file| file.write(@paths) }
42
40
  end
43
-
41
+
44
42
  def add_path(path)
45
43
  @paths[path == '/' ? 'home' : path.gsub('/', '__').chomp('__').downcase] = path.downcase
46
44
  end
47
45
 
48
46
  def spider
49
-
50
47
  end
51
-
52
48
  end
53
49
 
54
50
  class Wraith::Crawler < Wraith::Spider
55
-
56
51
  EXT = %w(flv swf png jpg gif asx zip rar tar 7z \
57
52
  gz jar js css dtd xsd ico raw mp3 mp4 \
58
53
  wav wmv ape aac ac3 wma aiff mpg mpeg \
@@ -77,15 +72,13 @@ class Wraith::Crawler < Wraith::Spider
77
72
  def modified_since(file, since)
78
73
  (Time.now - File.ctime(file)) / (24 * 3600) < since
79
74
  end
80
-
81
75
  end
82
76
 
83
77
  class Wraith::Sitemap < Wraith::Spider
84
-
85
78
  def spider
86
79
  unless @wraith.sitemap.nil?
87
80
  puts "reading sitemap.xml from #{@wraith.sitemap}"
88
- if @wraith.sitemap =~ URI::regexp
81
+ if @wraith.sitemap =~ URI.regexp
89
82
  sitemap = Nokogiri::XML(open(@wraith.sitemap))
90
83
  else
91
84
  sitemap = Nokogiri::XML(File.open(@wraith.sitemap))
@@ -94,7 +87,7 @@ class Wraith::Sitemap < Wraith::Spider
94
87
  sitemap.css('loc').each do |loc|
95
88
  path = loc.content
96
89
  # Allow use of either domain in the sitemap.xml
97
- @wraith.domains.each do |k, v|
90
+ @wraith.domains.each do |_k, v|
98
91
  path.sub!(v, '')
99
92
  end
100
93
  if @wraith.spider_skips.nil? || @wraith.spider_skips.none? { |regex| regex.match(path) }
@@ -103,6 +96,4 @@ class Wraith::Sitemap < Wraith::Spider
103
96
  end
104
97
  end
105
98
  end
106
-
107
99
  end
108
-
@@ -15,7 +15,11 @@ class Wraith::Thumbnails
15
15
 
16
16
  Parallel.each(files, in_processes: Parallel.processor_count) do |filename|
17
17
  new_name = filename.gsub(/^#{wraith.directory}/, "#{wraith.directory}/thumbnails")
18
- wraith.thumbnail_image(filename, new_name)
18
+ thumbnail_image(filename, new_name)
19
19
  end
20
20
  end
21
+
22
+ def thumbnail_image(png_path, output_path)
23
+ `convert #{png_path} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
24
+ end
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module Wraith
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.2'
3
3
  end
data/lib/wraith/wraith.rb CHANGED
@@ -4,7 +4,14 @@ class Wraith::Wraith
4
4
  attr_accessor :config
5
5
 
6
6
  def initialize(config_name)
7
- @config = YAML.load(File.open("configs/#{config_name}.yaml"))
7
+ if File.exist?(config_name) && File.extname(config_name) == '.yaml'
8
+ @config = YAML.load(File.open(config_name))
9
+ else
10
+ @config = YAML.load(File.open("configs/#{config_name}.yaml"))
11
+ end
12
+ rescue
13
+ puts 'unable to find config'
14
+ exit 1
8
15
  end
9
16
 
10
17
  def directory
@@ -68,36 +75,14 @@ class Wraith::Wraith
68
75
  end
69
76
 
70
77
  def mode
71
- if ['diffs_only', 'diffs_first', 'alphanumeric'].include?(@config['mode'])
78
+ if %w(diffs_only diffs_first alphanumeric).include?(@config['mode'])
72
79
  @config['mode']
73
80
  else
74
81
  'alphanumeric'
75
82
  end
76
83
  end
77
84
 
78
- def capture_page_image(browser, url, width, file_name)
79
- puts `"#{browser}" #{@config['phantomjs_options']} "#{snap_file}" "#{url}" "#{width}" "#{file_name}"`
80
- end
81
-
82
- def self.crop_images(crop, height)
83
- # For compatibility with windows file structures switch commenting on the following 2 lines
84
- `convert #{crop} -background none -extent 0x#{height} #{crop}`
85
- # puts `convert #{crop.gsub('/', '\\')} -background none -extent 0x#{height} #{crop.gsub('/', '\\')}`
86
- end
87
-
88
- def crop_images(_crop, _height)
89
- self.class.crop_images
90
- end
91
-
92
- def set_image_width(image, width)
93
- # For compatibility with windows file structures switch commenting on the following 2 lines
94
- `convert #{image} -background none -extent #{width}x0 #{image}`
95
- # puts `convert #{image.gsub('/', '\\')} -background none -extent #{width}x0 #{image.gsub('/', '\\')}`
96
- end
97
-
98
- def thumbnail_image(png_path, output_path)
99
- # For compatibility with windows file structures switch commenting on the following 2 lines
100
- `convert #{png_path} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
101
- # `convert #{png_path.gsub('/', '\\')} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
85
+ def phantomjs_options
86
+ @config['phantomjs_options']
102
87
  end
103
88
  end
data/spec/wraith_spec.rb CHANGED
@@ -12,6 +12,7 @@ describe Wraith do
12
12
  Given(:test_image2) { 'shots/test/test2.png' }
13
13
  Given(:diff_image) { 'shots/test/test_diff.png' }
14
14
  Given(:data_txt) { 'shots/test/test.txt' }
15
+ Given(:saving) { Wraith::SaveImages.new(config_name) }
15
16
 
16
17
  When(:wraith) { Wraith::Wraith.new(config_name) }
17
18
  Then { wraith.is_a? Wraith::Wraith }
@@ -31,7 +32,7 @@ describe Wraith do
31
32
  # capture_page_image
32
33
  When do
33
34
  wraith.engine.each do |_type, engine|
34
- wraith.capture_page_image(engine, test_url1, 320, test_image1)
35
+ saving.capture_page_image(engine, test_url1, 320, test_image1)
35
36
  end
36
37
  end
37
38
  When(:image_size) { ImageSize.path(test_image1).size }
@@ -41,8 +42,8 @@ describe Wraith do
41
42
  context 'When comparing images' do
42
43
  When(:diff_image_size) do
43
44
  wraith.engine.each do |_type, engine|
44
- wraith.capture_page_image(engine, test_url1, 320, test_image1)
45
- wraith.capture_page_image(engine, test_url2, 320, test_image2)
45
+ saving.capture_page_image(engine, test_url1, 320, test_image1)
46
+ saving.capture_page_image(engine, test_url2, 320, test_image2)
46
47
  end
47
48
  Wraith::CropImages.new(config_name).crop_images
48
49
  Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wraith
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Blooman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-11 00:00:00.000000000 Z
12
+ date: 2014-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -182,7 +182,6 @@ files:
182
182
  - lib/wraith/gallery.rb
183
183
  - lib/wraith/gallery_template/bootstrap.min.css
184
184
  - lib/wraith/gallery_template/gallery_template.erb
185
- - lib/wraith/images.rb
186
185
  - lib/wraith/javascript/nojs.js
187
186
  - lib/wraith/javascript/snap.js
188
187
  - lib/wraith/save_images.rb
data/lib/wraith/images.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'wraith'
2
-
3
- class Wraith::Images
4
- attr_reader :wraith
5
-
6
- def initialize(config)
7
- @wraith = Wraith::Wraith.new(config)
8
- end
9
-
10
- def files
11
- files = Dir.glob("#{wraith.directory}/*/*.png").sort
12
- invalid = File.expand_path('../../assets/invalid.jpg', File.dirname(__FILE__))
13
- files.each do |filename|
14
- if File.stat("#{filename}").size == 0
15
- FileUtils.cp invalid, filename
16
- puts "#{filename} is invalid"
17
- end
18
- end
19
- end
20
- end