Created
December 11, 2015 06:45
Railsアプリでsprite-factoryを使ってRetina対応したい気持ち ref: http://qiita.com/Layzie/items/d4268b8d76d668d3f232
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ico-hoge-sp { | |
background-image: image-url('[email protected]'); | |
width: 109px; | |
height: 29px; | |
background-position: 0px -103px; | |
background-repeat: no-repeat; | |
background-size: 322px auto; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sprite_factory' | |
require 'fastimage' | |
namespace :assets do | |
namespace :sprite do | |
desc 'recreate sprite images and css for SP' | |
task :sp do | |
SpriteFactory.run!( | |
'app/assets/images/sprite', | |
:layout => 'packed', | |
:style => 'scss', | |
:cssurl => "image-url('sprite/$IMAGE')", | |
:output_style => 'app/assets/stylesheets/[email protected]', | |
:output_image => 'app/assets/images/[email protected]' | |
) do |images| | |
images.map do |name, data| | |
sprite_size = FastImage.size('app/assets/images/[email protected]') | |
<<EOF | |
.ico-#{name}-sp { | |
background-image: image-url('[email protected]'); | |
width: #{data[:cssw] / 2}px; | |
height: #{data[:cssh] / 2}px; | |
background-position: #{data[:cssx] / -2}px #{data[:cssy] / -2}px; | |
background-repeat: no-repeat; | |
background-size: #{sprite_size[0] / 2}px auto; | |
} | |
EOF | |
end.join("\n") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment