Skip to content

Commit

Permalink
Merge pull request #434 from BBC-News/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
ChrisBAshton committed May 16, 2016
2 parents b578306 + 751fc02 commit be3632c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 19 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
```
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
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
8 changes: 8 additions & 0 deletions lib/wraith/helpers/custom_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ class MissingRequiredPropertyError < CustomError

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/validate.rb
Original file line number Diff line number Diff line change
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.7"
VERSION = "3.1.8"
end

0 comments on commit be3632c

Please sign in to comment.