Where does the sass "font-url" method get defined? - ruby-on-rails

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.

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

Related

Rails 4 + Sprockets: Allowing the use of js.erb files

I am attempting to use ES6 syntax in my Rails 4 app and have had some success between the use of sprockets-es6 (0.9.2), sprockets-rails (3.0.4) and sprockets (3.6.0).
The only issue I'm having is that my files need to end in .es6 in order to enable proper compilation and I'd like to be able to use a .es6.erb or .js.erb file type to allow me to use embedded ruby <%= foo %>.
Does anyone know of a way around this?
This question is a few years old and the OP specifies Sprockets 3.6. But I'm guessing many will find this question when looking for a solution to using erb files with a more modern version of sprockets.
If you're using Sprockets 4 and want to use .js.erb you'll need to 'register_mime_type'.
e.g. add the following to a new file called ./config/initializer/register_mime_type.rb
Sprockets.register_mime_type 'application/javascript', extensions: ['.js.erb']
This is described in Extending Sprockets.

Overwrite haml-rails scaffold templates

I want to customize the controller views generated by haml-rails. According to the Rails guide I am supposed to put my customized templates (e.g. index.html.haml) into lib/templates/[subfolders].
In this case I tried several subfolders (e.g. lib/templates/haml/scaffold, lib/generators/haml/scaffold/templates) but I could not get my custom templates to be used.
I know that I could write another generator easily, but I am wondering if there is a more DRY way to do so. In theory it should be possible:
In Rails 3.0 and above, generators don't just look in the source root for templates, they also search for templates in other paths.
I am using Rails (4.2.5.2), haml (4.0.7) and haml-rails (0.9.0).
Holy moly. It worked after all. It is correct to put the templates into lib/templates/haml/scaffold. And now comes the catch: spring will cache the templates. Hence, you must either restart spring after changes or prepend DISABLE_SPRING to the generator command:
DISABLE_SPRING=true rails g scaffold ...

how to rewrite a path in an initializer in Rails 3.2 ( w assets )

I need to write that in an initializer in Rails 3.2 with assets mgt
Payday::Config.default.invoice_logo = "#{Rails.root}/public/images/store/logo.png"
it seems that asset_path("store/logo.png") is not working ..
I see two problems with what you're trying to do:
First, Rails 3.2 asset_path is pointing to app/assets/ therefore asset_path("images/store/logo.png") is looking in:
"#{Rails.root}/app/assets/images/store/logo.png"
Second, asset_path is available in your views and scss, not in your initializers. The solution to this problem depends a lot on what you're trying to accomplish with that default.invoice_logo. If you provide more context we may be able to help you farther.

Accessing Rails Models or Helpers in SCSS

I'm using Rails 3.1 and SCSS in the Asset Pipeline. Is there anyway to access Rails helpers or controller data in the SCSS file? Something like...
#main {
background-color: #{current_user.preferences.background_color}
}
I know I can set my own $variables but I'm not sure how I would populate them from the controller's data.
As far as I know this is not what Asset Pipeline was designed for.
Think about it, you have a rake assets:precompile command to convert all your .scss.erb files to a static .css file.
So how could you ever possibly access variables like current_user from that .scss.erb file?
In my opinion, it's not possible to get controller variables in .scss.erb or .coffee.erb.
You can chain template processors with Rails 3.1, so you can do my.css.scss.erb, and then embed your variables like so:
$user-background-color: <%= current_user.preferences.background_color %>
Then you can use the Sass variables throughout your SCSS.
I took a different approach to solving this problem for Rails 3.0: Using SASS with user-specified colors

How can I use option "--bare" in Rails 3.1 for CoffeeScript?

Someone know how can I use this option in Rails 3.1?
Now CoffeScript puts a function with .call(this) on each file, but I want to remove this.
EDIT:
"Can't find variableā€ error with Rails 3.1 and Coffeescript" and "Pattern for CoffeeScript modules" have what I want. I'll change my global vars to use #global scope.
I'd recommend against doing this. See my answer at Pattern for CoffeeScript modules for some of the reasons why. ("Making your CoffeeScript code incompatible with out-of-the-box Rails 3.1" is yet another reason.) Better to just use
window.a = b
or even
#a = b
instead of a = b when you're trying to export something to global scope.
In previous versions of Rails 3.1, bare compilation was enabled. This was classified as a bug, and fixed in RC1.
So while I strongly encourage you not to do this, here's how to turn bare compilation back on: Add
Tilt::CoffeeScriptTemplate.default_bare = true
to your environment.rb.
I do recommend taking advantage of CoffeeScript's closures and following a CommonJS module patter. But sometimes, just sometimes, it is OK to want to use the --bare option. In my case, when rendering a Jasmine spec helper so I could keep things at the top level and also take advantage of the include Sprockets directive in said Jasmine specs.
To that end, I created the "sprockets-blackcoffee" gem, which you can learn about here. https://github.com/metaskills/sprockets-blackcoffee

Resources