For what it's worth, Compass already provides a similar feature. It's called
image_url() and it will use your project's image directory as a relative
root.

http://github.com/chriseppstein/compass/blob/master/lib/compass/sass_extensions/functions/urls.rb#L36

Even if you don't decide to use compass, you can see how it works by reading
the code. You call it like this:

div
  background-image= image_url("foo.png")

and it emits (assuming your configuration has images at /images):

div { background-image: url(/images/foo.png?12345678); }

The query parameter is a cache buster in case the image changes -- it can be
disabled if you don't want one.

Chris

On Thu, Jan 21, 2010 at 2:03 PM, Tim <[email protected]> wrote:

> Hello,
>
> I'm writing a custom function for Sass in Sass::Script::Functions.
> When I pass a string parameter (a file name) to my function, something
> messes with the string.  For example, I do something in Sass like:
>
> my_image_path(reduction.jpg)
>
> But when I call file_name.value in my Ruby implementation I get "red
> uction.jpg".
>
> I'm aware that I can quote the file name to prevent this, but then
> file_name.value is "'reduction.jpg'" (notice the quotes inside the
> quotes).  Is there a standard Sass method for extracting the string
> from the quotation marks?  I know how to do this myself, just
> wondering if there is a standard method that I'm missing.
>
> Also, but less importantly, is there a way I can pass file_name
> without quotes and preserve the exact string I passed?
>
> Thanks,
> Tim
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haml" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected] <haml%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/haml?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Reply via email to