wraith 1.1.1 → 1.1.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: 632e6875afc7f887a075632ef30887a31410ba79
4
- data.tar.gz: 1936f1eec71795aac70ae0e14abbd1471b93f3ae
3
+ metadata.gz: 4b91a9e01056e5ee44ce5a8726152a023023285f
4
+ data.tar.gz: 3043cc0f99e7dedee6c0878f09e41ff71f042923
5
5
  SHA512:
6
- metadata.gz: 3a475a73580b5589cec9232c7588f7ccce6692897c63476f9773d2b5bbca65b52a8fe66aa79877e85a2f56565114a5542f02f097ecbb5fff3b2f213e305d93be
7
- data.tar.gz: 1cfa109de3917ed0e1d78e9ce29b152de30ff94659472f26262d746adf9f47cd11e2f094152986e16b60add2958a0545fba7cd4819fd7c83a7829e171a88a683
6
+ metadata.gz: e0ea6720ac947da1b0ad1fda376fa288ae3ea58953c8b5cb239b22e08e410df49fd6f89ca8cd3bcd546148c413a29a16de4b7f65dd1a2eb7b10ecf3739a3830a
7
+ data.tar.gz: ccec5c11e607f1c3faf657edff070cfff0ba61b6641b135e7f97078290d452a34f0f808ec936ecdc525e08a65d2156cc1b0540aa527f29e6057e445b81076cb0
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - "1.9.2"
4
4
  - "2.0.0"
5
5
 
6
- script: "./bin/wraith"
6
+ script: "./bin/wraith capture config"
7
7
 
8
8
  notifications:
9
9
  email:
data/README.md CHANGED
@@ -62,20 +62,16 @@ And then download the PhantomJS binary package from
62
62
 
63
63
  Open terminal and run
64
64
 
65
- git clone https://github.com/BBC-News/wraith
65
+ gem install wraith
66
66
 
67
- You can then run the following inside the Wraith directory:
67
+ You can then run the following inside the Wraith directory to create a template snap.js and config file:
68
68
 
69
- bundle install
70
-
71
- If you don't have bundler installed, install it :
72
-
73
- gem install bundler
69
+ gem setup
74
70
 
75
71
 
76
72
  Alternatively you can download the install script via curl, this will not create a git repo though.
77
73
 
78
- curl -fsSL https://raw.github.com/bbc-news/wraith/go/install | bash
74
+ git clone https://github.com/BBC-News/wraith
79
75
  cd wraith
80
76
  bundle install
81
77
 
File without changes
data/lib/wraith/cli.rb CHANGED
@@ -7,18 +7,31 @@ require 'wraith/folder'
7
7
  require 'wraith/thumbnails'
8
8
  require 'wraith/compare_images'
9
9
  require 'wraith/images'
10
+ require 'wraith/gallery'
10
11
 
11
12
  class Wraith::CLI < Thor
13
+ include Thor::Actions
12
14
 
13
15
  attr_accessor :config_name
14
16
 
17
+ def self.source_root
18
+ File.expand_path('../../../templates/',__FILE__)
19
+ end
20
+
21
+ desc "setup", "creates config folder and default config"
22
+ def setup
23
+ template('configs/config.yaml', 'configs/config.yaml')
24
+ template('javascript/snap.js', 'javascript/snap.js')
25
+ template('assets/invalid.jpg', 'assets/invalid.jpg')
26
+ end
27
+
15
28
  desc "reset_shots", "removes all the files in the shots folder"
16
29
  def reset_shots(config_name)
17
30
  reset = Wraith::FolderManager.new(config_name)
18
31
  reset.clear_shots_folder
19
32
  end
20
33
 
21
- desc "setup_folders", "create folders for images"
34
+ desc "folders", "create folders for images"
22
35
  def setup_folders(config_name)
23
36
  create = Wraith::FolderManager.new(config_name)
24
37
  create.create_folders
@@ -62,9 +75,9 @@ class Wraith::CLI < Thor
62
75
 
63
76
  desc "generate_gallery", "create page for viewing images"
64
77
  def generate_gallery(config_name)
65
- dir = Wraith::Wraith.new(config_name)
66
- puts 'Generating gallery'
67
- `ruby lib/wraith/gallery.rb "#{dir.directory}"`
78
+ gallery = Wraith::GalleryGenerator.new(config_name)
79
+ gallery.generate_gallery
80
+ puts "Gallery generated"
68
81
  end
69
82
 
70
83
  desc "capture config_name", "A full Wraith job"
@@ -1,86 +1,100 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Given all the screenshots in the shots/ directory, produces a nice looking
4
- # gallery
5
-
6
1
  require 'erb'
7
2
  require 'pp'
8
3
  require 'fileutils'
4
+ require 'wraith/wraith'
5
+
6
+ class Wraith::GalleryGenerator
7
+ attr_reader :wraith
9
8
 
10
- MATCH_FILENAME = /(\S+)_(\S+)\.\S+/
11
- TEMPLATE_LOCATION = "lib/wraith/gallery_template/gallery_template.erb"
12
- TEMPLATE_BY_DOMAIN_LOCATION = "lib/wraith/gallery_template/gallery_template.erb"
13
- BOOTSTRAP_LOCATION = "lib/wraith/gallery_template/bootstrap.min.css"
9
+ MATCH_FILENAME = /(\S+)_(\S+)\.\S+/
14
10
 
15
- def parse_directories(dirname)
11
+ TEMPLATE_LOCATION = File.expand_path('gallery_template/gallery_template.erb', File.dirname(__FILE__))
12
+ TEMPLATE_BY_DOMAIN_LOCATION = File.expand_path('gallery_template/gallery_template.erb', File.dirname(__FILE__))
13
+ BOOTSTRAP_LOCATION = File.expand_path('gallery_template/bootstrap.min.css', File.dirname(__FILE__))
14
+
15
+ def initialize(config)
16
+ @wraith = Wraith::Wraith.new(config)
17
+ @location = wraith.directory
18
+ end
19
+
20
+ def parse_directories(dirname)
16
21
  dirs = {}
17
22
  categories = Dir.foreach(dirname).select do |category|
18
- if ['.', '..', 'thumbnails'].include? category
19
- # Ignore special dirs
20
- false
21
- elsif File.directory? "#{dirname}/#{category}" then
22
- # Ignore stray files
23
- true
24
- else
25
- false
26
- end
23
+ if ['.', '..', 'thumbnails'].include? category
24
+ # Ignore special dirs
25
+ false
26
+ elsif File.directory? "#{dirname}/#{category}" then
27
+ # Ignore stray files
28
+ true
29
+ else
30
+ false
31
+ end
27
32
  end
28
33
 
29
34
  categories.each do |category|
30
- dirs[category] = {}
31
- Dir.foreach("#{dirname}/#{category}") do |filename|
32
- match = MATCH_FILENAME.match(filename)
33
- if not match.nil? then
34
- size = match[1].to_i
35
- group = match[2]
36
- filepath = category + "/" + filename
37
- thumbnail = "thumbnails/#{category}/#{filename}"
38
-
39
- if dirs[category][size].nil? then
40
- dirs[category][size] = {:variants => []}
41
- end
42
- size_dict = dirs[category][size]
43
-
44
- case group
45
- when 'diff'
46
- size_dict[:diff] = {
47
- :filename => filepath, :thumb => thumbnail
48
- }
49
- when 'data'
50
- size_dict[:data] = File.read("#{dirname}/#{filepath}")
51
- else
52
- size_dict[:variants] << {
53
- :name => group,
54
- :filename => filepath,
55
- :thumb => thumbnail
56
- }
57
-
58
- end
59
- size_dict[:variants].sort! {|a, b| a[:name] <=> b[:name] }
60
- end
35
+ dirs[category] = {}
36
+ Dir.foreach("#{dirname}/#{category}") do |filename|
37
+ match = MATCH_FILENAME.match(filename)
38
+ if not match.nil? then
39
+ size = match[1].to_i
40
+ group = match[2]
41
+ filepath = category + "/" + filename
42
+ thumbnail = "thumbnails/#{category}/#{filename}"
43
+
44
+ if dirs[category][size].nil? then
45
+ dirs[category][size] = {:variants => []}
46
+ end
47
+ size_dict = dirs[category][size]
48
+
49
+ case group
50
+ when 'diff'
51
+ size_dict[:diff] = {
52
+ :filename => filepath, :thumb => thumbnail
53
+ }
54
+ when 'data'
55
+ size_dict[:data] = File.read("#{dirname}/#{filepath}")
56
+ else
57
+ size_dict[:variants] << {
58
+ :name => group,
59
+ :filename => filepath,
60
+ :thumb => thumbnail
61
+ }
62
+
63
+ end
64
+ size_dict[:variants].sort! { |a, b| a[:name] <=> b[:name] }
61
65
  end
66
+ end
62
67
  end
63
68
 
64
69
  return dirs
65
- end
70
+ end
66
71
 
67
- def generate_html(domain, directories, template, destination)
72
+ def generate_html(location, directories, template, destination, path)
68
73
  template = File.read(template)
69
- html = ERB.new(template).result
74
+ locals = {
75
+ :location => location,
76
+ :directories => directories,
77
+ :path => path
78
+ }
79
+ html = ERB.new(template).result(ErbBinding.new(locals).get_binding)
70
80
  File.open(destination, 'w') do |outf|
71
- outf.write(html)
81
+ outf.write(html)
72
82
  end
73
- end
83
+ end
74
84
 
75
- if ARGV.length < 1 then
76
- puts "USAGE: create_gallery.rb <directory>"
77
- exit 1
78
- end
79
85
 
80
- location = ARGV[0]
81
- domain = location
82
- directories = parse_directories(location)
83
- dest = "#{location}/gallery.html"
86
+ def generate_gallery(withPath="")
87
+ dest = "#{@location}/gallery.html"
88
+ directories = parse_directories(@location);
89
+ generate_html(@location, directories, TEMPLATE_BY_DOMAIN_LOCATION, dest, withPath)
90
+ FileUtils.cp(BOOTSTRAP_LOCATION, "#{@location}/bootstrap.min.css")
91
+
92
+ end
93
+
94
+ class ErbBinding < OpenStruct
95
+ def get_binding
96
+ return binding()
97
+ end
98
+ end
84
99
 
85
- generate_html(domain, directories, TEMPLATE_BY_DOMAIN_LOCATION, dest)
86
- FileUtils.cp(BOOTSTRAP_LOCATION, "#{location}/bootstrap.min.css")
100
+ end
@@ -12,7 +12,7 @@
12
12
  <body>
13
13
  <div class="container">
14
14
  <div class="row page-header">
15
- <h1>List of screenshots for <%= domain %> </h1>
15
+ <h1>List of screenshots for <%= location %> </h1>
16
16
  </div>
17
17
  <div class="row">
18
18
  <!-- <%= directories.length %> -->
@@ -21,7 +21,7 @@
21
21
  <div class="panel-heading">Screenshots:</div>
22
22
  <ul class="list-group list-group-flush">
23
23
  <% directories.keys.sort.each do |dir| %>
24
- <li class="list-group-item"><a href="#<%=dir%>"><%=dir%></a></li>
24
+ <li class="list-group-item"><a href="#<%=path%><%=dir%>"><%=dir%></a></li>
25
25
  <% end %>
26
26
  </ul>
27
27
  </div>
@@ -37,16 +37,16 @@
37
37
  <h3 class="col-lg-1 text-muted"><%=size%>px</h3>
38
38
  <% files[:variants].each do |file| %>
39
39
  <div class="col-lg-3">
40
- <a href="<%=file[:filename]%>">
41
- <img class="short-screenshot img-thumbnail" src="<%=file[:thumb]%>">
40
+ <a href="<%=path%>/<%=file[:filename]%>">
41
+ <img class="short-screenshot img-thumbnail" src="<%=path%><%=file[:thumb]%>">
42
42
  </a>
43
43
  <p class="text-center"><%=file[:name]%></p>
44
44
  </div>
45
45
  <% end %>
46
46
  <div class="col-lg-3">
47
47
  <% if files[:diff] %>
48
- <a href="<%=files[:diff][:filename]%>">
49
- <img class="short-screenshot img-thumbnail" src="<%=files[:diff][:thumb]%>">
48
+ <a href="<%=path%>/<%=files[:diff][:filename]%>">
49
+ <img class="short-screenshot img-thumbnail" src="<%=path%><%=files[:diff][:thumb]%>">
50
50
  </a>
51
51
  <% end %>
52
52
  <p class="text-center">diff</p>
data/lib/wraith/images.rb CHANGED
@@ -11,7 +11,7 @@ class Wraith::Images
11
11
  files = Dir.glob("#{wraith.directory}/*/*.png").sort
12
12
  files.each do |filename|
13
13
  if File.stat("#{filename}").size == 0
14
- FileUtils.cp 'lib/wraith/assets/invalid.jpg', "#{filename}"
14
+ FileUtils.cp 'assets/invalid.jpg', "#{filename}"
15
15
  puts "#{filename} is invalid"
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Wraith
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
Binary file
@@ -0,0 +1,43 @@
1
+ #Headless browser option
2
+ browser:
3
+ webkit: "phantomjs"
4
+ # gecko: "slimerjs"
5
+
6
+ #If you want to have multiple snapping files, set the file name here
7
+ snap_file: "javascript/snap.js"
8
+
9
+ # Type the name of the directory that shots will be stored in
10
+ directory:
11
+ - 'shots'
12
+
13
+ # Add only 2 domains, key will act as a label
14
+ domains:
15
+ english: "http://www.live.bbc.co.uk/news"
16
+ russian: "http://www.live.bbc.co.uk/russian"
17
+
18
+ #Type screen widths below, here are a couple of examples
19
+ screen_widths:
20
+ - 320
21
+ - 600
22
+ - 768
23
+ - 1024
24
+ - 1280
25
+
26
+ #Type page URL paths below, here are a couple of examples
27
+ paths:
28
+ home: /
29
+ uk_index: /uk
30
+
31
+ # If you don't want to name the paths explicitly you can use a yaml
32
+ # collection as follows, and names will be derived by replacing / with _
33
+ #
34
+ # paths:
35
+ # - /imghp
36
+ # - /maps
37
+
38
+ #Amount of fuzz ImageMagick will use
39
+ fuzz: '20%'
40
+
41
+ #Set the number of days to keep the site spider file
42
+ spider_days:
43
+ - 10
@@ -0,0 +1,85 @@
1
+ var system = require('system');
2
+ var page = require('webpage').create();
3
+ var fs = require('fs');
4
+
5
+ if (system.args.length === 3) {
6
+ console.log('Usage: snap.js <some URL> <view port width> <target image name>');
7
+ phantom.exit();
8
+ }
9
+
10
+ var url = system.args[1];
11
+ var image_name = system.args[3];
12
+ var view_port_width = system.args[2];
13
+ var current_requests = 0;
14
+ var last_request_timeout;
15
+ var final_timeout;
16
+
17
+
18
+ page.viewportSize = { width: view_port_width, height: 1500};
19
+ page.settings = { loadImages: true, javascriptEnabled: true };
20
+
21
+ // If you want to use additional phantomjs commands, place them here
22
+ page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.17';
23
+
24
+ // You can place custom headers here, example below.
25
+ // page.customHeaders = {
26
+
27
+ // 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
28
+
29
+ // };
30
+
31
+ // If you want to set a cookie, just add your details below in the following way.
32
+
33
+ // phantom.addCookie({
34
+ // 'name': 'ckns_policy',
35
+ // 'value': '111',
36
+ // 'domain': '.bbc.co.uk'
37
+ // });
38
+ // phantom.addCookie({
39
+ // 'name': 'locserv',
40
+ // 'value': '1#l1#i=6691484:n=Oxford+Circus:h=e@w1#i=8:p=London@d1#1=l:2=e:3=e:4=2@n1#r=40',
41
+ // 'domain': '.bbc.co.uk'
42
+ // });
43
+
44
+ page.onResourceRequested = function(req) {
45
+ current_requests += 1;
46
+ };
47
+
48
+ page.onResourceReceived = function(res) {
49
+ if (res.stage === 'end') {
50
+ current_requests -= 1;
51
+ debounced_render();
52
+ }
53
+ };
54
+
55
+ page.open(url, function(status) {
56
+ if (status !== 'success') {
57
+ console.log('Error with page ' + url);
58
+ phantom.exit();
59
+ }
60
+ });
61
+
62
+
63
+ function debounced_render() {
64
+ clearTimeout(last_request_timeout);
65
+ clearTimeout(final_timeout);
66
+
67
+ // If there's no more ongoing resource requests, wait for 1 second before
68
+ // rendering, just in case the page kicks off another request
69
+ if (current_requests < 1) {
70
+ clearTimeout(final_timeout);
71
+ last_request_timeout = setTimeout(function() {
72
+ console.log('Snapping ' + url + ' at width ' + view_port_width);
73
+ page.render(image_name);
74
+ phantom.exit();
75
+ }, 1000);
76
+ }
77
+
78
+ // Sometimes, straggling requests never make it back, in which
79
+ // case, timeout after 5 seconds and render the page anyway
80
+ final_timeout = setTimeout(function() {
81
+ console.log('Snapping ' + url + ' at width ' + view_port_width);
82
+ page.render(image_name);
83
+ phantom.exit();
84
+ }, 5000);
85
+ }
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.1.1
4
+ version: 1.1.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-02-06 00:00:00.000000000 Z
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -169,12 +169,12 @@ files:
169
169
  - LICENSE
170
170
  - README.md
171
171
  - Rakefile
172
+ - assets/invalid.jpg
172
173
  - bin/wraith
173
174
  - configs/config.yaml
174
175
  - configs/config_nojs.yaml
175
176
  - configs/test_config.yaml
176
177
  - lib/wraith.rb
177
- - lib/wraith/assets/invalid.jpg
178
178
  - lib/wraith/cli.rb
179
179
  - lib/wraith/compare_images.rb
180
180
  - lib/wraith/crop.rb
@@ -192,6 +192,9 @@ files:
192
192
  - lib/wraith/version.rb
193
193
  - lib/wraith/wraith.rb
194
194
  - spec/wraith_spec.rb
195
+ - templates/assets/invalid.jpg
196
+ - templates/configs/config.yaml
197
+ - templates/javascript/snap.js
195
198
  - wraith.gemspec
196
199
  homepage: http://responsivenews.co.uk
197
200
  licenses: