Skip to content

Commit

Permalink
[webui] port from compass to sprite_factory
Browse files Browse the repository at this point in the history
compass-rails hasn't seen any commit for 2 months and is not rails 4
ready. and all we need from compass is the sprite functionality, so use
a simpler gem: sprite_factory

The drawback is that the resulting image is in git, so you need to call
bundle exec rake assets:resprite if you add icons
  • Loading branch information
coolo committed May 16, 2013
1 parent 78eea93 commit c12c5fa
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/webui/Gemfile
Expand Up @@ -10,10 +10,11 @@ group :assets do
gem 'cssmin', '>= 1.0.2'
gem 'uglifier', '>= 1.2.2'
gem 'sass-rails'
gem 'compass-rails'
gem 'jquery-datatables-rails'
gem 'codemirror-rails', '>= 3.0'
gem 'rails_tokeninput', '>= 1.6.1.rc1'
gem 'sprite-factory', '>= 1.5.2'
gem 'chunky_png'
end

group :development do
Expand Down
11 changes: 3 additions & 8 deletions src/webui/Gemfile.lock
Expand Up @@ -52,12 +52,6 @@ GEM
codemirror-rails (3.12)
railties (~> 3.0)
coderay (1.0.9)
compass (0.12.2)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
compass-rails (1.0.3)
compass (>= 0.12.2, < 0.14)
cssmin (1.0.3)
dalli (2.6.3)
delayed_job (3.0.5)
Expand All @@ -72,7 +66,6 @@ GEM
i18n (~> 0.5)
fast_xs (0.8.0)
ffi (1.8.1)
fssm (0.2.10)
headless (1.0.1)
hike (1.2.2)
hoptoad_notifier (2.4.11)
Expand Down Expand Up @@ -156,6 +149,7 @@ GEM
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
slop (3.4.4)
sprite-factory (1.5.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -184,9 +178,9 @@ DEPENDENCIES
capybara (~> 2.0.1)
capybara-webkit
capybara_minitest_spec
chunky_png
ci_reporter
codemirror-rails (>= 3.0)
compass-rails
cssmin (>= 1.0.2)
dalli
delayed_job (> 3.0)
Expand Down Expand Up @@ -214,6 +208,7 @@ DEPENDENCIES
rdoc
sass-rails
simplecov-rcov
sprite-factory (>= 1.5.2)
sqlite3
uglifier (>= 1.2.2)
xmlhash (>= 1.3.2)
Binary file added src/webui/app/assets/images/icons_sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/webui/app/assets/stylesheets/application.scss
Expand Up @@ -12,11 +12,11 @@
*= require token-input
*= require token-input-facebook
*/
@import "compass";
@import "bento/reset";
@import "bento/960";
@import "bento/base";

@import "icons";
@import "style";
@import "monitor";
@import "package";
Expand Down
168 changes: 168 additions & 0 deletions src/webui/app/assets/stylesheets/icons.scss.erb

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/webui/app/assets/stylesheets/style.scss
Expand Up @@ -391,11 +391,6 @@ div.dataTables_wrapper:after {
height: 0;
}

$icons-spacing:2px;
$icons-sprite-dimensions:true;
@import "icons/*.png";
@include all-icons-sprites;

.icon_24 {
width: 24px;
height: 24px;
Expand All @@ -420,8 +415,6 @@ $icons-sprite-dimensions:true;
cursor:pointer;
border: none;
text-indent: -1000em;
background: sprite($icons-sprites, note_delete) no-repeat !important;
@include sprite-dimensions($icons-sprites, note_delete);
}

#breadcrump .icons-home_grey {
Expand Down
25 changes: 25 additions & 0 deletions src/webui/lib/tasks/sprites.rake
@@ -0,0 +1,25 @@
require 'sprite_factory'

namespace :assets do
desc 'recreate sprite images and css'
task :resprite => :environment do
SpriteFactory.library = 'chunkypng'
SpriteFactory.layout = 'packed'
SpriteFactory.cssurl = "image-url('$IMAGE')" # use a sass-rails helper method to be evaluated by the rails asset pipeline
## run it once for the md5sum
#SpriteFactory.run!('app/assets/icons', output_image: 'tmp/sprite.tmp.png', margin: 2, nocss: true)
#md5=Digest::MD5.hexdigest(File.open('tmp/sprite.tmp.png').read)
#File.unlink('tmp/sprite.tmp.png')
SpriteFactory.run!('app/assets/icons', output_style: 'app/assets/stylesheets/icons.scss.erb',
output_image: "app/assets/images/icons_sprite.png", margin: 2, nocomments: true) do |images|
rules = []
images.each do |icon, hash|
rules << ".icons-#{icon} { #{hash[:style]}; }"
end
rules.sort!
rules << ".delete-attribute { #{images[:note_delete][:style]} !important; }"
rules.join("\n")
end
system("optipng", "-o5", "app/assets/images/icons_sprite.png")
end
end

0 comments on commit c12c5fa

Please sign in to comment.