Skip to content

Commit

Permalink
Merge pull request #482 from vfonic/master
Browse files Browse the repository at this point in the history
Use left/right arrow keys for changing to next/prev gallery slide
  • Loading branch information
ChrisBAshton authored Nov 25, 2016
2 parents d424ef4 + ee569d7 commit 1ff5d8c
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 39 deletions.
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@

// http://jquery.malsup.com/cycle/options.html
$('.slideshow').cycle({
fx: 'cover',
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
speed: 300,
Expand Down Expand Up @@ -244,6 +245,20 @@
var slide = $(this).closest(".slide")
fullScreenSlide(slide);
})

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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 number Diff line number Diff 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 number Diff line number Diff 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

0 comments on commit 1ff5d8c

Please sign in to comment.