Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from trotzig/static-html
Browse files Browse the repository at this point in the history
Bundle uploaded diffs in HTML file
  • Loading branch information
trotzig committed Jul 25, 2015
2 parents 54f02a0 + 528440a commit 2d36561
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
5 changes: 2 additions & 3 deletions bin/likadan
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ when 'approve', 'reject'
LikadanAction.new(example_name, width).send(action)

when 'upload_diffs'
LikadanUploader.new.upload_diffs.each do |url|
puts url
end
# `upload_diffs` returns a URL to a static html file
puts LikadanUploader.new.upload_diffs
else
abort "Unknown action \"#{action}\""
end
17 changes: 17 additions & 0 deletions lib/likadan-diffs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Likadan diffs</title>
</head>
<body>
<h1>Likadan diffs</h1>
<p>File generated: <%= Time.now %></p>

<% diff_images.each do |diff| %>
<h3>
<%= diff[:name] %> @ <%= diff[:width] %>
</h3>
<p><img src="<%= diff[:url] %>"></p>
<% end %>
</body>
</html>
23 changes: 17 additions & 6 deletions lib/likadan_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ def upload_diffs
bucket = service.buckets.build(SecureRandom.hex)
bucket.save(location: :us)

current_snapshots[:diffs].map do |diff|
object = bucket.objects.build("#{diff[:name]}_#{diff[:width]}.png")
object.content = open(diff[:file])
object.content_type = 'image/png'
object.save
object.url
diff_images = current_snapshots[:diffs].map do |diff|
image = bucket.objects.build("#{diff[:name]}_#{diff[:width]}.png")
image.content = open(diff[:file])
image.content_type = 'image/png'
image.save
diff[:url] = image.url
diff
end

html = bucket.objects.build('likadan-diffs.html')
html.content =
ERB.new(
File.read(File.expand_path(
File.join(File.dirname(__FILE__), 'likadan-diffs.html.erb')))
).result(binding)
html.content_type = 'text/html'
html.save
html.url
end
end

0 comments on commit 2d36561

Please sign in to comment.