10

bourbon uses font-url here.

Rails has the method font_url which I'm fairly certain is what is being invoked. However, I can't find where the connection between these two things is made. I have explored the codebases of bourbon, sass, sass-rais, and rails.

Where is font-url defined, and/or the connection between it and rails's font_url made?

update

Clarification: my ultimate goal is to define my own helpers in rubyland which are siblings to font_url.

John Bachir
  • 22,495
  • 29
  • 154
  • 227

1 Answers1

9

font-url is a part of rails asset pipeline just like image-url. If you look at rail guides it clearly says

When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.

So if you are using font-url("some_font") it will look for some_font in app/assets/font directory

Update:

As it is mentioned in docs that if you are using sass then your can use your assets with hypenated urls(image-url) but if you are using a ruby file then those helpers would be underscored (image_url) probably because Ruby doesn't like you having methods or variables with hyphens in the name syntactically, but semantically, there's nothing wrong with it

Mandeep
  • 9,093
  • 2
  • 26
  • 36
  • great, getting closer. but can you point out where in the rails code the translation from hyphen to underscore takes place? – John Bachir Aug 23 '14 at 03:15
  • 1
    (also, the docs seem to indicate that sass-rails provides this, but your answer seems to indicate that rails provides this) – John Bachir Aug 23 '14 at 03:18
  • @JohnBachir yeah sass-rails provides it. I only said that it's a part of a rails asset pipeline. If you are using sass then you can use hypenated url but if you want to use your assets in a ruby file then those helpers are with underscore. I think both of these helpers are exclusive to each others as they are defined separately – Mandeep Aug 23 '14 at 03:57
  • I could not find where the hyphen version is defined, and this is what I am asking in my question. My goal is to define my own helper. I'll update the question to reflect that. – John Bachir Aug 23 '14 at 03:59
  • @JohnBachir Ahh couldn't find the source of image-url btw if you want to define helpers which are siblings to font_url then why are you looking for a source of font-url? I mean you could just define a method and then replicate what's inside font_url helper. If you want your method name to have hypen then you can checkout this https://www.ruby-forum.com/topic/72154#101895 – Mandeep Aug 23 '14 at 04:47
  • 1
    Making hyphen interchangeable with underscore is a feature of Sass. However, depending on how the function is defined, this might not always work. – cimmanon Aug 23 '14 at 14:42
  • How do I define a method in ruby that a sibling to font-url which I can use in SASS? – John Bachir Aug 24 '14 at 14:49
  • Just use Compass? http://compass-style.org/reference/compass/helpers/urls/#font-url – cimmanon Aug 24 '14 at 18:53