12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/happo/uploader.rb', line 12
def upload_diffs
result_summary = YAML.load(File.read(File.join(
Happo::Utils.config['snapshots_folder'], 'result_summary.yaml')))
return [] if result_summary[:diff_examples].empty? &&
result_summary[:new_examples].empty?
bucket = find_or_build_bucket
dir = SecureRandom.uuid
diff_images = result_summary[:diff_examples].map do |diff|
image = bucket.objects.build(
"#{dir}/#{diff[:description]}_#{diff[:viewport]}.png")
image.content = open(Happo::Utils.path_to(diff[:description],
diff[:viewport],
'diff.png'))
image.content_type = 'image/png'
image.save
diff[:url] = image.url
diff
end
new_images = result_summary[:new_examples].map do |example|
image = bucket.objects.build(
"#{dir}/#{example[:description]}_#{example[:viewport]}.png")
image.content = open(Happo::Utils.path_to(example[:description],
example[:viewport],
'baseline.png'))
image.content_type = 'image/png'
image.save
example[:url] = image.url
example
end
html = bucket.objects.build("#{dir}/index.html")
path = File.expand_path(
File.join(File.dirname(__FILE__), 'diffs.html.erb'))
html.content = ERB.new(File.read(path)).result(binding)
html.content_type = 'text/html'
html.save
html.url
end
|