Skip to content

Instantly share code, notes, and snippets.

@hrp
Forked from giom/gist:58005
Created January 15, 2010 12:41
Show Gist options
  • Save hrp/278023 to your computer and use it in GitHub Desktop.
Save hrp/278023 to your computer and use it in GitHub Desktop.
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