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 #67 from diffux/base64-names
Browse files Browse the repository at this point in the history
Use base64 encoding for folder names
  • Loading branch information
trotzig committed Nov 20, 2015
2 parents baf820e + f41f19c commit c18fb79
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/diffux_ci-diffs.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% require 'rack' %>
<!DOCTYPE html>
<html>
<head>
Expand All @@ -9,7 +10,7 @@

<% diff_images.each do |diff| %>
<h3>
<%= diff[:description] %> @ <%= diff[:viewport] %>
<%= Rack::Utils.escape_html(diff[:description]) %> @ <%= diff[:viewport] %>
</h3>
<p><img src="<%= diff[:url] %>"></p>
<% end %>
Expand Down
6 changes: 6 additions & 0 deletions lib/diffux_ci_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class DiffuxCIServer < Sinatra::Base
set :port, DiffuxCIUtils.config['port']
end

helpers do
def h(text)
Rack::Utils.escape_html(text)
end
end

get '/' do
@config = DiffuxCIUtils.config
erb :index
Expand Down
5 changes: 3 additions & 2 deletions lib/diffux_ci_utils.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'yaml'
require 'erb'
require 'uri'
require 'base64'

class DiffuxCIUtils
def self.config
Expand Down Expand Up @@ -33,7 +34,7 @@ def self.config_from_file
end

def self.normalize_description(description)
description.gsub(/[^a-zA-Z0-9\-_]/, '_')
Base64.encode64(description)
end

def self.path_to(description, viewport_name, file_name)
Expand All @@ -59,7 +60,7 @@ def self.current_snapshots
viewport_dir = File.expand_path('..', file)
description_dir = File.expand_path('..', viewport_dir)
{
description: File.basename(description_dir),
description: Base64.decode64(File.basename(description_dir)),
viewport: File.basename(viewport_dir).sub('@', ''),
file: file
}
Expand Down
4 changes: 2 additions & 2 deletions lib/views/review.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h2>DIFFS</h2>
<% @snapshots[:diffs].each do |diff| %>
<h3>
<%= diff[:description] %> @ <%= diff[:viewport] %>
<%= h diff[:description] %> @ <%= diff[:viewport] %>
</h3>
<p><img src="/resource?file=<%= ERB::Util.url_encode(diff[:file]) %>"></p>
<form style="display: inline-block"
Expand All @@ -29,7 +29,7 @@
<h2>BASELINES</h2>
<% @snapshots[:baselines].each do |baseline| %>
<h3>
<%= baseline[:description] %> @ <%= baseline[:viewport] %>
<%= h baseline[:description] %> @ <%= baseline[:viewport] %>
</h3>
<p><img src="/resource?file=<%= ERB::Util.url_encode(baseline[:file]) %>"></p>
<% end %>
Expand Down
4 changes: 3 additions & 1 deletion spec/diffux_ci_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'yaml'
require 'tmpdir'
require 'open3'
require 'base64'

describe 'diffux_ci' do
let(:config) do
Expand Down Expand Up @@ -52,7 +53,8 @@ def run_diffux

def snapshot_file_exists?(description, size, file_name)
File.exist?(
File.join(@tmp_dir, 'snapshots', description, size, file_name)
File.join(@tmp_dir, 'snapshots',
Base64.encode64(description), size, file_name)
)
end

Expand Down
5 changes: 3 additions & 2 deletions spec/diffux_ci_utils_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'diffux_ci_utils'
require 'base64'

describe 'DiffuxCIUtils' do
before do
Expand Down Expand Up @@ -47,7 +48,7 @@

context 'with special characters' do
let(:description) { '<MyComponent> something interesting' }
it { should eq('_MyComponent__something_interesting') }
it { should eq(Base64.encode64(description)) }
end
end

Expand All @@ -56,6 +57,6 @@
let(:description) { '<MyComponent>' }
let(:viewport_name) { 'large' }
let(:file_name) { 'diff.png' }
it { should eq('./snapshots/_MyComponent_/@large/diff.png') }
it { should eq("./snapshots/#{Base64.encode64(description)}/@large/diff.png") }
end
end

0 comments on commit c18fb79

Please sign in to comment.