This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsive_screenshots.rb
53 lines (43 loc) · 1.65 KB
/
responsive_screenshots.rb
1
2
3
4
5
6
7
8
9
10
11
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
require 'optparse'
require 'ostruct'
require 'time'
options = OpenStruct.new
OptionParser.new do |opts|
opts.banner = "Usage: responsive_screenshot.rb [base-url] [subpages] \nExample: ruby responsive_screenshots.rb http://192.168.1.36:4567/ apps.html contact.html features.html feedback.html imprint.html privacy.html team.html tour.html"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!
if options.update
puts "updating"
exec("curl -L #{scriptSource}?$(date +%s) -o #{File.basename($0)}")
end
url = ARGV[0] || 'http://localhost:4567'
subpages = [""]
subpages = subpages + (ARGV[1..-1] || [''])
widths = {:w320_iPhone_5_portrait => 320,
:w586_iPhone_5_landscape => 586,
:w375_iPhone_6_portrait => 375,
:w667_iPhone_6_landscape => 667,
:w786_iPad_portrait => 786,
:w1024_iPad_landscape => 1024,
:w834_iPad_Pro_portrait => 834,
:w1112_iPad_Pro_landscape => 1112,
:w1024_iPad_Pro_13_portrait => 1024,
:w1366_iPad_Pro_13_landscape => 1366,
:w1920_Web => 1920,
:w1366_Web => 1366}
$timestamp = DateTime.now.strftime("%Y-%d-%m-") + Time.now.to_i.to_s
if ARGV.empty?
puts "Missing arguments. See: ruby responsive_screenshots.rb --help"
else
for device in widths.keys
if subpages
for page in subpages
system("webkit2png -W #{widths[device]} --scale=1 -F --dir=responsive_screenshots/#{$timestamp}/#{page}/ --filename=#{device} #{url}#{page}")
end
end
system("webkit2png -W #{widths[device]} --scale=1 -F --dir=responsive_screenshots/#{$timestamp} --filename=#{device} #{url}")
end
end