-
-
Save hrp/278023 to your computer and use it in GitHub Desktop.
This file contains 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
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