This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bdf8425
updated version to 3.1.1
ChrisBAshton Feb 28, 2016
dd474ad
fix #395
gserrg Feb 29, 2016
ad36c28
fix #395
ChrisBAshton Feb 29, 2016
3b3a1ac
Merge pull request #396 from gserrg/master
ChrisBAshton Feb 29, 2016
fb9c672
incremented version
ChrisBAshton Feb 29, 2016
ee2eabe
Merge branch 'master' of github.com:BBC-News/wraith
ChrisBAshton Feb 29, 2016
cd4cfa6
fix #397 - add version command
katekligman Mar 11, 2016
c6e64e1
Version command adjustments.
katekligman Mar 17, 2016
936e24a
Merge pull request #400 from katekligman/version_command
ChrisBAshton Mar 17, 2016
c3ee92d
Fix #298 - use the latest version of ImageMagick with Docker
katekligman Mar 30, 2016
1c87a63
incremented to 3.1.3
ChrisBAshton Apr 8, 2016
bf5888c
fix #415
ChrisBAshton Apr 8, 2016
1b31e4b
incremented to v3.1.4
ChrisBAshton Apr 8, 2016
6b58c56
fixes #423
mfdj Apr 17, 2016
871c292
update spec
mfdj Apr 17, 2016
bde0aad
Allow newer nokogiris
Apr 18, 2016
c998e9b
Merge pull request #406 from katekligman/imagemagick-docker-fix
ChrisBAshton Apr 22, 2016
e4dfba0
fix #405
ChrisBAshton Apr 22, 2016
b099577
fix #419
ChrisBAshton Apr 25, 2016
992de56
incremented to v3.1.5
ChrisBAshton Apr 25, 2016
252eb23
Merge pull request #424 from mfdj/master
ChrisBAshton Apr 25, 2016
fe519eb
check for directory regardless of wraith mode
ChrisBAshton Apr 25, 2016
e72b7a3
Merge pull request #425 from envato/relax-nokigiri-version
ChrisBAshton May 16, 2016
25757a1
added test
ChrisBAshton May 16, 2016
395c3e7
incremented to 3.1.7
ChrisBAshton May 16, 2016
0a3c1ed
merged master into branch
ChrisBAshton May 16, 2016
b578306
Merge pull request #429 from BBC-News/issue405
ChrisBAshton May 16, 2016
15f7ece
fix #430
ChrisBAshton May 16, 2016
342bc04
added issue templates and contributing guidelines
ChrisBAshton May 16, 2016
0aa8085
moved contributing instructions from readme to dedicated template
ChrisBAshton May 16, 2016
b6ea4bd
use checkboxes
ChrisBAshton May 16, 2016
9ba5e1d
fix #377
ChrisBAshton May 16, 2016
751fc02
incremented to v3.1.8
ChrisBAshton May 16, 2016
be3632c
Merge pull request #434 from BBC-News/improvements
ChrisBAshton May 16, 2016
d4833b7
removed casperjs from the wraith gem dependencies
ChrisBAshton May 16, 2016
e882245
add casperjs as a developer dependency
ChrisBAshton May 16, 2016
d5b2f6c
Merge pull request #435 from BBC-News/fix_build
ChrisBAshton May 16, 2016
ff306ff
incremented to v3.2.0
ChrisBAshton May 16, 2016
2d3e7f1
fix #366
ChrisBAshton May 16, 2016
d8e6aae
updated dockerfile to install the new phantomjs and casperjs
May 20, 2016
5da31dc
Merge pull request #438 from punit-shah/master
ChrisBAshton May 21, 2016
1099b6e
Add attr_reader to Wraith::Spider to fix error "undefined local varia…
Domi202 Jul 13, 2016
a658500
Merge pull request #447 from Domi202/master
ChrisBAshton Aug 4, 2016
2f23719
bump to v3.2.1
ChrisBAshton Aug 4, 2016
ee569d7
Use left/right arrow keys for changing to next/prev gallery slide
vfonic Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
We're always happy to receive Pull Requests from the Wraith community.

Guidelines:

* Make sure your PR is documented (What does it do? Why is it needed?)
* New features and bug fixes should have tests written alongside them
* Appreciate that contributors maintain Wraith in their spare time, so a response may take several weeks

A PR is more likely to be merged if it fixes one of [Wraith's open issues](https://github.com/BBC-News/wraith/issues).

How to contribute:

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@



------
Reporting a problem? Please describe the issue above, and complete the following checklist so that we can help you more quickly.

#### Issue checklist:

- [ ] I have validated my config file against [YAML Validator](http://codebeautify.org/yaml-validator) to make sure it is valid YAML.

- [ ] I have run the command in verbose mode (by adding `verbose: true` to my config) and pasted the output below:

```
paste results here
```

- [ ] I have pasted the contents of my config file below:

```
paste config here
```
11 changes: 7 additions & 4 deletions Dockerfile
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,11 @@ FROM ruby:2.1.2
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN apt-get update
RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
RUN tar -xvf phantomjs.tar.gz
RUN mv phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/bin
RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
RUN apt-get install -y libfreetype6 libfontconfig1
RUN apt-get install -y libfreetype6 libfontconfig1 nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install npm
RUN npm install -g phantomjs@2.1.7 casperjs@1.1.1
RUN gem install wraith --no-rdoc --no-ri
RUN gem install aws-sdk --no-rdoc --no-ri

Expand All@@ -17,4 +17,7 @@ RUN echo "deb http://security.debian.org/ jessie/updates contrib non-free" | tee
RUN apt-get update
RUN apt-get install -y ttf-freefont ttf-mscorefonts-installer ttf-bitstream-vera ttf-dejavu ttf-liberation

# Make sure a recent (>6.7.7-10) version of ImageMagick is installed.
RUN apt-get install -y imagemagick

ENTRYPOINT [ "wraith" ]
12 changes: 1 addition & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,17 +56,7 @@ Wraith also requires at least one of these headless browsers:

## Contributing

If you want to add functionality to this project, pull requests are welcome.

* Fork a branch based off BBC-News/wraith:master and do all of your changes within it.
* Make commits of logical units and describe them properly.
* Check for unnecessary whitespace with git diff --check before committing.
* If possible, submit tests to your patch / new feature so it can be tested easily.
* Assure nothing is broken by running all the tests (`bundle exec rspec`).
* Please ensure that it complies with coding standards.
* When writing the title of your Pull Request, if you have to pause to add an 'and' anywhere in the title - it should be two pull requests.

**Please raise any issues with this project as a GitHub issue.**
Please read [how to contribute to Wraith](https://github.com/BBC-News/wraith/blob/master/.github/CONTRIBUTING.md).

## License

Expand Down
8 changes: 7 additions & 1 deletion lib/wraith/cli.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ def copy_old_shots(config_name)
end
end

desc "validate", "checks your configuration and validates that all required properties exist"
desc "validate [config_name]", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
logger.info Wraith::Validate.new(config_name).validate
Expand DownExpand Up@@ -176,4 +176,10 @@ def latest(config)
generate_gallery(config)
end
end

desc "version", "Show the version of Wraith"
map ["--version", "-version", "-v"] => "version"
def version
logger.info Wraith::VERSION
end
end
7 changes: 2 additions & 5 deletions lib/wraith/folder.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,11 +86,8 @@ def threshold_rate(dirs)
dirs.each do |_folder_name, shot_info|
shot_info.each do |_k, v|
begin
if !v.include?(:diff)
return false
elsif v[:data] > wraith.threshold
return false
end
return false unless v.include?(:diff)
return false if v[:data] > wraith.threshold
rescue
return true
end
Expand Down
23 changes: 21 additions & 2 deletions lib/wraith/gallery.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,32 @@ def data_check(size_dict, dirname, filepath)

def sorting_dirs(dirs)
if %w(diffs_only diffs_first).include?(wraith.mode)
@sorted = dirs.sort_by { |_category, sizes| -1 * sizes.max_by { |_size, dict| dict[:data] }[1][:data] }
@sorted = sort_by_diffs dirs
else
@sorted = dirs.sort_by { |category, _sizes| category }
@sorted = sort_alphabetically dirs
end
Hash[@sorted]
end

def sort_by_diffs(dirs)
dirs.sort_by do |_category, sizes|
size = select_size_with_biggest_diff sizes
-1 * size[1][:data]
end
end

def select_size_with_biggest_diff(sizes)
begin
sizes.max_by { |_size, dict| dict[:data] }
rescue
fail MissingImageError
end
end

def sort_alphabetically(dirs)
dirs.sort_by { |category, _sizes| category }
end

def generate_gallery(with_path = "")
dest = "#{@location}/gallery.html"
directories = parse_directories(@location)
Expand Down
17 changes: 16 additions & 1 deletion lib/wraith/gallery_template/slideshow_template.erb
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,8 @@
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
Expand DownExpand Up@@ -147,6 +148,20 @@
$(this).remove();
})
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down
11 changes: 11 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,14 @@ class InvalidDomainsError < CustomError

class MissingRequiredPropertyError < CustomError
end

class ConfigFileDoesNotExistError < CustomError
end

class MissingImageError < CustomError
def initialize(msg = false)
default_msg = "Something went wrong! It looks like you're missing some images. Check your output directory and make sure that each path has four files for every screen size (data.txt, diff, base, latest). If in doubt, delete your output directory and run Wraith again."
msg = default_msg unless msg
super(msg)
end
end
2 changes: 2 additions & 0 deletions lib/wraith/spider.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,8 @@ def check_for_paths
end

class Wraith::Spider
attr_reader :wraith

def initialize(wraith)
@wraith = wraith
@paths = {}
Expand Down
14 changes: 8 additions & 6 deletions lib/wraith/validate.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,12 +19,12 @@ def validate(mode = false)
end

def validate_basic_properties
if wraith.engine.nil?
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}"
end
unless wraith.domains
fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}"
end
fail MissingRequiredPropertyError, "You must specify a browser engine! #{docs_prompt}" if wraith.engine.nil?

fail MissingRequiredPropertyError, "You must specify at least one domain for Wraith to do anything! #{docs_prompt}" unless wraith.domains

fail MissingRequiredPropertyError, "You must specify a directory for capture! #{docs_prompt}" if wraith.directory.nil?

# @TODO validate fuzz is not nil, etc
end

Expand DownExpand Up@@ -68,12 +68,14 @@ def docs_prompt

def list_debug_information
wraith_version = Wraith::VERSION
command_run = ARGV.join ' '
ruby_version = run_command_safely("ruby -v") || "Ruby not installed"
phantomjs_version = run_command_safely("phantomjs --version") || "PhantomJS not installed"
casperjs_version = run_command_safely("casperjs --version") || "CasperJS not installed"
imagemagick_version = run_command_safely("convert -version") || "ImageMagick not installed"

logger.debug "#################################################"
logger.debug " Command run: #{command_run}"
logger.debug " Wraith version: #{wraith_version}"
logger.debug " Ruby version: #{ruby_version}"
logger.debug " ImageMagick: #{imagemagick_version}"
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.1.0"
VERSION = "3.2.1"
end
5 changes: 2 additions & 3 deletions lib/wraith/wraith.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,12 +22,11 @@ def open_config_file(config_name)

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
config = File.open filepath
return YAML.load config
end
end
rescue
logger.error "unable to find config \"#{config}\""
fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end

def directory
Expand Down
4 changes: 2 additions & 2 deletions spec/before_capture_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def run_js_then_capture(config)

# @TODO - we need tests determining the path to "path-level before_capture hooks"

describe "When hooking into beforeCapture (CasperJS)" do
describe "When hooking into before_capture (CasperJS)" do
it "Executes the global JS before capturing" do
run_js_then_capture(
:global_js => before_suite_js,
Expand DownExpand Up@@ -75,7 +75,7 @@ def run_js_then_capture(config)
end

# @TODO - uncomment and figure out why broken
# describe "When hooking into beforeCapture (PhantomJS)" do
# describe "When hooking into before_capture (PhantomJS)" do
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
# let(:saving) { Wraith::SaveImages.new(config_name) }
# let(:wraith) { Wraith::Wraith.new(config_name) }
Expand Down
15 changes: 15 additions & 0 deletions spec/validate_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
test: http://www.bbc.com

browser: "casperjs"

directory: some/dir
')
end

Expand All@@ -24,6 +26,10 @@
config["browser"] = nil
expect { Wraith::Validate.new(config, true).validate }.to raise_error MissingRequiredPropertyError
end

it "should complain if the config file doesn't exist" do
expect { Wraith::Wraith.new('configs/some_made_up_config.yml') }.to raise_error ConfigFileDoesNotExistError
end
end

describe "validation specific to capture mode" do
Expand All@@ -47,6 +53,15 @@
')
Wraith::Validate.new(config, true).validate("capture")
end

it "should fail if no directory is specified" do
config["domains"] = YAML.load('
test: http://something.bbc.com
live: http://www.bbc.com
')
config["directory"] = nil
expect { Wraith::Validate.new(config, true).validate("capture") }.to raise_error MissingRequiredPropertyError
end
end

describe "validations specific to history mode" do
Expand Down
2 changes: 1 addition & 1 deletion templates/configs/history.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ paths:
clickable_guide__after_click:
path: /news/entertainment-arts-27221191
selector: '.idt__news'
before_capture: 'javascript/beforeCapture--casper_example.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.

# (optional) JavaScript file to execute before taking screenshot of every path. Default: nil
before_capture: 'javascript/wait--casper.js'
Expand Down
4 changes: 2 additions & 2 deletions wraith.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'casperjs'

spec.add_runtime_dependency 'rake'
spec.add_runtime_dependency 'image_size'
spec.add_runtime_dependency 'anemone'
spec.add_runtime_dependency 'robotex'
spec.add_runtime_dependency 'nokogiri', '1.6.7'
spec.add_runtime_dependency 'nokogiri', '~> 1.6.7'
spec.add_runtime_dependency 'log4r'
spec.add_runtime_dependency 'thor'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'casperjs'
end