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:
1 parent
403a791c94
commit
511718e973
24 files changed
+23
-10
No files matched your search
+20
-8
@@ -5,7 +5,7 @@ require 'mini_magick'
|
|||||||
|
|
||||||
class Screenshot
|
class Screenshot
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
attr_accessor :theme, :theme_name
|
attr_accessor :theme
|
||||||
|
|
||||||
def self.prepare
|
def self.prepare
|
||||||
Capybara.register_driver :poltergeist do |app|
|
Capybara.register_driver :poltergeist do |app|
|
||||||
@@ -19,30 +19,42 @@ class Screenshot
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(theme_name)
|
def initialize(theme)
|
||||||
@theme_name = theme_name
|
@theme = OpenStruct.new(theme.merge(
|
||||||
@theme = theme_name.parameterize.underscore
|
slug: theme[:name].parameterize.underscore,
|
||||||
|
digest: Digest::MD5.new.hexdigest(theme[:colors])
|
||||||
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_theme_image
|
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 '/'
|
visit '/'
|
||||||
within ".theme_#{theme}" do
|
within ".theme_#{theme.slug}" do
|
||||||
choose 'sidebar_theme_rd'
|
choose 'sidebar_theme_rd'
|
||||||
end
|
end
|
||||||
sleep 1
|
sleep 1
|
||||||
file = Tempfile.new([theme, ".png"])
|
|
||||||
|
file = Tempfile.new([theme.slug, ".png"])
|
||||||
begin
|
begin
|
||||||
page.save_screenshot(file.path, full: true)
|
page.save_screenshot(file.path, full: true)
|
||||||
|
|
||||||
MiniMagick::Tool::Convert.new do |convert|
|
MiniMagick::Tool::Convert.new do |convert|
|
||||||
convert << file.path
|
convert << file.path
|
||||||
convert.crop '220x220+0+0'
|
convert.crop '220x220+0+0'
|
||||||
convert << "source/images/theme/#{theme}.png"
|
convert << target_file
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
file.close
|
file.close
|
||||||
file.unlink
|
file.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def target_file
|
||||||
|
"source/images/theme/#{theme.slug}-#{theme.digest}.png"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -9,7 +9,7 @@ class ScreenshotGenerator < ::Middleman::Extension
|
|||||||
Screenshot.prepare
|
Screenshot.prepare
|
||||||
data = YAML.load_file('data/themes.yml')
|
data = YAML.load_file('data/themes.yml')
|
||||||
data.each do |theme|
|
data.each do |theme|
|
||||||
Screenshot.new(theme[:name]).generate_theme_image
|
Screenshot.new(theme).generate_theme_image
|
||||||
end
|
end
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
# builder.run './my_deploy_script.sh'
|
# builder.run './my_deploy_script.sh'
|
||||||
|
|||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -4,8 +4,9 @@ title: Slack Themes
|
|||||||
|
|
||||||
<% data.themes.each do |theme| %>
|
<% data.themes.each do |theme| %>
|
||||||
<% theme_slug = theme[:name].parameterize.underscore %>
|
<% theme_slug = theme[:name].parameterize.underscore %>
|
||||||
|
<% digest = Digest::MD5.new.hexdigest(theme[:colors]) %>
|
||||||
<label class="radio theme_label theme_<%= theme[:name].parameterize.underscore %>">
|
<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] %>
|
<input name="sidebar_theme_rd" type="radio" value="<%= theme[:colors] %>" ng-model="theme" ng-change="setTheme()"> <%= theme[:name] %>
|
||||||
</label>
|
</label>
|
||||||
<% end %>
|
<% end %>
|
||||||
Reference in new issue
Block a user