Add digest to theme images to not keep rebuilding them
The digest is based on the colors of theme, so will change when the colors change
This commit is contained in:
+20
-8
@@ -5,7 +5,7 @@ require 'mini_magick'
|
||||
|
||||
class Screenshot
|
||||
include Capybara::DSL
|
||||
attr_accessor :theme, :theme_name
|
||||
attr_accessor :theme
|
||||
|
||||
def self.prepare
|
||||
Capybara.register_driver :poltergeist do |app|
|
||||
@@ -19,30 +19,42 @@ class Screenshot
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(theme_name)
|
||||
@theme_name = theme_name
|
||||
@theme = theme_name.parameterize.underscore
|
||||
def initialize(theme)
|
||||
@theme = OpenStruct.new(theme.merge(
|
||||
slug: theme[:name].parameterize.underscore,
|
||||
digest: Digest::MD5.new.hexdigest(theme[:colors])
|
||||
))
|
||||
end
|
||||
|
||||
def generate_theme_image
|
||||
puts "Generating image for theme #{theme_name}"
|
||||
if File.exist? target_file
|
||||
puts "Image for theme #{theme.name} already exists"
|
||||
return
|
||||
end
|
||||
|
||||
puts "Generating image for theme #{theme.name}"
|
||||
visit '/'
|
||||
within ".theme_#{theme}" do
|
||||
within ".theme_#{theme.slug}" do
|
||||
choose 'sidebar_theme_rd'
|
||||
end
|
||||
sleep 1
|
||||
file = Tempfile.new([theme, ".png"])
|
||||
|
||||
file = Tempfile.new([theme.slug, ".png"])
|
||||
begin
|
||||
page.save_screenshot(file.path, full: true)
|
||||
|
||||
MiniMagick::Tool::Convert.new do |convert|
|
||||
convert << file.path
|
||||
convert.crop '220x220+0+0'
|
||||
convert << "source/images/theme/#{theme}.png"
|
||||
convert << target_file
|
||||
end
|
||||
ensure
|
||||
file.close
|
||||
file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
def target_file
|
||||
"source/images/theme/#{theme.slug}-#{theme.digest}.png"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user