Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Useful functions for sass

View gist:58005
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
module Sass::Script
module Functions
# substitue text in a string
# @params
# str the string to substitute text from
# reg the regexp given to sub
# rep the replacement text
def sub(str, reg, rep = '')
Sass::Script::String.new(str.to_s.sub(/#{reg.to_s}/, rep.to_s))
end
 
# Returns the width in pixels of an image
def width(path)
Sass::Script::Number.new(img_identify(path, 'w').to_i , ["px"])
end
# Returns the height in pixels of an image
def height(path)
Sass::Script::Number.new(img_identify(path, 'h').to_i, ["px"])
end
 
private
 
def img_identify(path, f)
path = path.to_s
if path[0].chr == '/'
path = Merb.root / 'public' / path
else
path = Sass::Plugin.options[:css_location] / path
end
`identify -format %#{f}\\\\n #{path}`.split("\n")[0]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.