-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: SASS Mixins #16
Comments
I agree it could be helpful to be able to do it directly. SpriteFactory.run!('images/timer') do |images|
rules = []
rules << "div.running img.button { cursor: pointer; #{images[:running][:style]} }"
rules << "div.stopped img.button { cursor: pointer; #{images[:stopped][:style]} }"
rules.join("\n")
end into something (untested) like: SpriteFactory.run!('images/timer') do |images|
images.map do |image_name, image_data|
"@mixin sprite-image-#{image_name} { ... }"
end.join("\n")
end |
thanks man, just FYI if anyone wants to use it: this is the code i came up with (could certainly be more DRY, pls help if you know how): SpriteFactory.run!('app/assets/images/icons', output_style: 'app/assets/stylesheets/sprite-icons-mixins.sass', style: 'sass') do |images|
images.map do |name, data|
<<EOF
=sprite-icon-#{name}($position: 'before', $x-offset: 0, $y-offset: 0)
overflow: visible
position: relative
@if $position == 'before'
&:before
background: url(icons.png) -#{data[:x]}px -#{data[:y]}px no-repeat
content: ''
display: block
height: #{data[:height]}px
left: -(#{data[:width]}+10)+px
margin: (#{-(data[:height]/2)}+$y-offset)+px 0 0 $x-offset+px
position: absolute
top: 50%
width: #{data[:width]}px
@else if $position == 'after'
&:after
background: url(icons.png) -#{data[:x]}px -#{data[:y]}px no-repeat
content: ''
display: block
height: #{data[:height]}px
margin: (#{-(data[:height]/2)}+$y-offset)+px 0 0 $x-offset+px
position: absolute
right: -(#{data[:width]}+10)+px
top: 50%
width: #{data[:width]}px
EOF
end.join("\n")
end |
great, I'm not used to SaSS but ScSS equivalent code shouldn't be that different. |
I was able to format the css output with mixin this way: SpriteFactory.run!(
ref,
:style => 'scss',
:library => 'chunkypng',
:nocomments => true) do |images|
items = []
images.map do |name, data|
items << "@include type(#{name}, #{data[:width]}, #{data[:height]}, #{data[:x]}, #{data[:y]});"
end
rules = []
rules << "@mixin type($type, $w, $h, $x, $y) {
&.\#{$type} {
background-position: -\#{$x}px -\#{$y}px;
width: \#{$w}px;
height: \#{$h}px;
}
}\n"
rules << items
end Which gave me this: @mixin type($type, $w, $h, $x, $y) {
&.#{$type} {
background-position: -#{$x}px -#{$y}px;
width: #{$w}px;
height: #{$h}px;
}
}
@include type(item-1, 10, 20, 0, 0);
@include type(item-2, 10, 20, 0, 20);
... |
@pshizzle hey, was there a reason you switched from https://github.com/merbjedi/sprite/ ? Are you still using https://github.com/jakesgordon/sprite-factory/ for your image spriting? Yours hopefully, |
+1 for this feature request too! ~ https://twitter.com/ldexterldesign/status/352080562871209986 Regards, |
+1 from me. |
Hey @dmitriy-korotayev, I've recently settled on the following for all my icon/spriting needs: Regards, |
Interesting approach to the old concept. |
I would like to see that feature as well. |
What I really loved about merbjedi's sprite gem was that it could output sass mixins (https://github.com/merbjedi/sprite/) which enabled you to add images via :before or :after pseudo-elements. you could just add your mixin to it with +sprite('icons', 'arrow'), no need for extra-markup.
would that be hard to do with sprite-factory?
The text was updated successfully, but these errors were encountered: