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:
Ufuk Kayserilioglu committed 2015-03-16 14:55:18 +02:00
1 parent 403a791c94
commit 511718e973
24 files changed
+23 -10

No files matched your search

+20 -8
View File
@@ -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
+1 -1
View File
@@ -9,7 +9,7 @@ class ScreenshotGenerator < ::Middleman::Extension
Screenshot.prepare
data = YAML.load_file('data/themes.yml')
data.each do |theme|
Screenshot.new(theme[:name]).generate_theme_image
Screenshot.new(theme).generate_theme_image
end
puts "Hello World"
# builder.run './my_deploy_script.sh'
+2 -1
View File
@@ -4,8 +4,9 @@ title: Slack Themes
<% data.themes.each do |theme| %>
<% theme_slug = theme[:name].parameterize.underscore %>
<% digest = Digest::MD5.new.hexdigest(theme[:colors]) %>
<label class="radio theme_label theme_<%= theme[:name].parameterize.underscore %>">
<img src="/images/theme/<%= theme_slug %>.png" class="theme_thumb"><br>
<img src="/images/theme/<%= theme_slug %>-<%= digest %>.png" class="theme_thumb"><br>
<input name="sidebar_theme_rd" type="radio" value="<%= theme[:colors] %>" ng-model="theme" ng-change="setTheme()"> <%= theme[:name] %>
</label>
<% end %>