Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base_path and compare_path options for paths #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions lib/wraith/gallery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "fileutils"
require "wraith/wraith"
require "wraith/helpers/logger"
require "wraith/helpers/capture_options"

class Wraith::GalleryGenerator
include Logging
Expand Down Expand Up @@ -60,15 +61,22 @@ def matcher(match, filename, dirname, category)
end

def figure_out_url(group, category)
root = wraith.domains["#{group}"]
group = "#{group}"
root = wraith.domains[group]
base_or_compare = wraith.domains.keys.index(group) == 0 ? :base : :compare
return "" if root.nil?
path = get_path(category)
path = get_path(category, base_or_compare)
url = root + path
url
end

def get_path(category)
wraith.paths[category]["path"] || wraith.paths[category]
def get_path(category, base_or_compare)
path_options = CaptureOptions.new(wraith.paths[category], wraith)
if base_or_compare == :base
path_options.base_path
else
path_options.compare_path
end
end

def get_group_from_match(match)
Expand Down
12 changes: 10 additions & 2 deletions lib/wraith/helpers/capture_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def path
casper?(options)
end

def base_path
options.is_a?(Hash) && options.key?('base_path') ? options['base_path'] : path
end

def compare_path
options.is_a?(Hash) && options.key?('compare_path') ? options['compare_path'] : path
end

def selector
options["selector"] || "body"
end
Expand All @@ -31,11 +39,11 @@ def before_capture
end

def base_url
base_urls(path)
base_urls(base_path)
end

def compare_url
compare_urls(path)
compare_urls(compare_path)
end

def base_urls(path)
Expand Down
4 changes: 2 additions & 2 deletions lib/wraith/save_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def define_individual_job(label, settings, width)
compare_file_name = meta.file_names(width, label, meta.compare_label)

jobs = []
jobs << [label, settings.path, prepare_widths_for_cli(width), settings.base_url, base_file_name, settings.selector, wraith.before_capture, settings.before_capture, 'invalid1.jpg']
jobs << [label, settings.path, prepare_widths_for_cli(width), settings.compare_url, compare_file_name, settings.selector, wraith.before_capture, settings.before_capture, 'invalid2.jpg'] unless settings.compare_url.nil?
jobs << [label, settings.base_path, prepare_widths_for_cli(width), settings.base_url, base_file_name, settings.selector, wraith.before_capture, settings.before_capture, 'invalid1.jpg']
jobs << [label, settings.compare_path, prepare_widths_for_cli(width), settings.compare_url, compare_file_name, settings.selector, wraith.before_capture, settings.before_capture, 'invalid2.jpg'] unless settings.compare_url.nil?

jobs
end
Expand Down
9 changes: 9 additions & 0 deletions spec/configs/test_config--base_compare_paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
imports: 'test_config--phantom.yaml'

paths:
home:
base_path: /old-home
compare_path: /new-home
uk_index:
base_path: /old-uk
compare_path: /new-uk
29 changes: 29 additions & 0 deletions spec/gallery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,33 @@
expect(dirs["home"][0][:diff][:thumb]).to eq "thumbnails/home/test_image-diff.png"
end
end

describe "#figure_out_url" do
it "returns an empty string if it can't find the domain" do
expect(gallery.figure_out_url("missing_domain", "home")).to eq ""
end

it "returns a full url" do
expected = "http://www.bbc.com/afrique/"
expect(gallery.figure_out_url("afrique", "home")).to eq expected
end

context "when base_path and compare_path are set" do
let(:config_name) do
get_path_relative_to __FILE__,
"./configs/test_config--base_compare_paths.yaml"
end
let(:gallery) { Wraith::GalleryGenerator.new(config_name, false) }

it "uses the base path for the first domain" do
expected = "http://www.bbc.com/afrique/old-home"
expect(gallery.figure_out_url("afrique", "home")).to eq expected
end

it "uses the compare path for the second domain" do
expected = "http://www.bbc.com/russian/new-home"
expect(gallery.figure_out_url("russian", "home")).to eq expected
end
end
end
end