unders (owner)

Fork Of

gist: 58005 by giom Useful functions for sass

Revisions

gist: 58328 Download_button fork
public
Public Clone URL: git://gist.github.com/58328.git
Embed All Files: show embed
Ruby #
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