how to use replace-text-with-dimensions in a DRY way with Rails 3.1?

737 views
Skip to first unread message

Ramon Tayag

unread,
Sep 8, 2011, 10:13:37 AM9/8/11
to compas...@googlegroups.com
I have a bunch of variables:

$add_icon_24: "icons/dimensions_24/add.png";
$arrow_up_down_icon_24: "icons/dimensions_24/arrow_up_down.png";

These images live in `app/assets/images/`. How do you use
`replace-text-with-dimensions` in a DRY manner with these?

`@include replace-text-with-dimensions($add_icon_24)` won't work. I
get an error: "Unknown file type png". I was thinking of making a Sass
function that finds the asset and returns the relative path from the
Rails.root, using
`YourAppName::Application.assets.find_asset('icons/dimensions_24/add.png')`,
but I figured I'd ask here first. I have to wrap my head around how
Sass Literals work before I do that.

Ramon Tayag

Ramon Tayag

unread,
Sep 8, 2011, 10:45:41 AM9/8/11
to compas...@googlegroups.com
I worked on this: https://gist.github.com/1203567

It's almost complete, but the value that gets passed in already has
`url()` surrounding it. Howcome?

Ramon Tayag

Roy Tomeij

unread,
Sep 8, 2011, 10:50:46 AM9/8/11
to Compass
This works perfectly fine in my Rails 3.1 project:

@import "compass/utilities/text/replacement"

#test
+replace-text-with-dimensions("icons/dimensions_24/logo.gif")

Ramon Tayag

unread,
Sep 9, 2011, 9:50:14 AM9/9/11
to compas...@googlegroups.com
And your icons are in app/assets/images?

I tried `replace-text-with-dimension("icons/dimensions_24/cancel.png")`,
but still got `No such file or directory -
/home/ramon/source/unstilted/images/icons/dimensions_24/cancel.png`

This is the compass I'm using: gem 'compass', :git =>
'git://github.com/chriseppstein/compass.git', :branch => 'rails31'

I've updated it in the past day.

Ramon Tayag

> --
> You received this message because you are subscribed to the Google Groups "Compass" group.
> To post to this group, send email to compas...@googlegroups.com.
> To unsubscribe from this group, send email to compass-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/compass-users?hl=en.
>
>

Chris Eppstein

unread,
Sep 9, 2011, 3:45:41 PM9/9/11
to compas...@googlegroups.com
Here's what I did recently:

@import "jd/icons/subtle-icon/*.png";

#{$subtle-icon-sprite-base-class} {
  @include subtle-icon-sprite-dimensions(default); //default is the name of one of my sprites -- adjust accordingly.
}

@include all-subtle-icon-sprites;

Ramon Tayag

unread,
Sep 9, 2011, 9:56:48 PM9/9/11
to compas...@googlegroups.com
Chris, I'm not familiar with this syntax, not sure why - I've imported
sprites before. However, from what you've typed, do you suggest
importing them as sprites instead? Or did you paste that to show that
pngs work?

Ramon Tayag

Ramon Tayag

unread,
Sep 9, 2011, 10:19:49 PM9/9/11
to compas...@googlegroups.com
Ok nvm, just had a brain fart. My old code was like that. I'll try
using sprites.

Ramon Tayag

Ramon Tayag

unread,
Sep 24, 2011, 6:36:43 AM9/24/11
to compas...@googlegroups.com
I found myself not going with sprites. However, I'm still unable to
get the `replace-text-with-dimensions` to work with an image that's in
the `app/asset/images/icons/dimensions_48/` directory. This code:

@include replace-text-with-dimensions("/icons/dimensions_48/box_upload.png");

Produces this error:

No such file or directory -

/home/ramon/source/unstilted/images/icons/dimensions_48/box_upload.png
(in /home/ramon/source/unstilted/app/assets/stylesheets/admin_site/image_and_attachment_editor.css.scss)

Just to keep things simple (not use sprites), how do I use
`replace-text-with-dimensions` with a Rails 3.1 asset?

Thanks!

Scott Davis

unread,
Sep 24, 2011, 11:00:46 AM9/24/11
to compas...@googlegroups.com
I just fixed this last night try the current master

Sent from my iPhone

Ramon Tayag

unread,
Sep 29, 2011, 8:47:23 AM9/29/11
to compas...@googlegroups.com
Oh. Sweet. Thanks!

Ramon Tayag



On Sat, Sep 24, 2011 at 11:00 PM, Scott Davis <jetvi...@gmail.com> wrote:


Quinn Chaffee

unread,
Oct 12, 2011, 11:51:28 AM10/12/11
to compas...@googlegroups.com
Sweet! I want to bump this because it solved my problem.

Just had to update my Gemfile to point compass to the github repo.

I was pointing it to a rubygems version.

Thanks a bunch guys!

Reply all
Reply to author
Forward
0 new messages