Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use font-url path for proper asset compiling #20

Merged
merged 1 commit into from Mar 3, 2014

Conversation

brianpattison
Copy link
Contributor

font-url should be used so that the Asset Pipeline can point to the compiled version of the font.

supercodepoet added a commit that referenced this pull request Mar 3, 2014
Use font-url path for proper asset compiling
@supercodepoet supercodepoet merged commit 1ba7fac into FortAwesome:master Mar 3, 2014
@brianpattison brianpattison deleted the fix-font-urls branch March 3, 2014 17:36
@lightswitch05
Copy link

This fixes the problem with asset compiling, but breaks URLs for applications deployed under a subdirectoy.

For example, this is the path to my compiled application.css file:

http://example.com/my_app/assets/application-8a96057c1fcea5be889198e7b377a24b.css

within application.css:

src:url(/assets/fontawesome-webfont-3b53a5ecdb9473016ee097f74f4f16c0.eot?v=4.0.3);

which gets a 404 error because its not within the parent my_app. Using font-url as a relative path would fix the problem.

@brianpattison
Copy link
Contributor Author

@lightswitch05 The font-url helper is not using an absolute path, but you will need to update your Asset Pipeline configuration to have your app in a subdirectory:

rails/rails#3946

@lightswitch05
Copy link

@brianpattison - I believe that this would be a valid work-around. However, all my other assets (css, js, png, etc) are able to load correctly without setting the relative root param. Since my root is variable (based on the name of the war file), I would really hate to limit the path to a static name, especially since I regularly deploy different versions of the app to the same server for testing purposes. Perhaps this is a bug in warbler for fonts.

@brianpattison
Copy link
Contributor Author

@lightswitch05 I wasn't trying to give you a work-around. I was trying to point you toward the proper solution. Asset Pipeline is generating the URL, so your issue is not with this gem but instead with how asset pipeline is generating the URLs for your Rails app. The font-awesome-sass gem is simply using your configuration for the asset pipeline.

@lightswitch05
Copy link

@brianpattison thank you for trying to point me in the right direction. Setting the RAILS_RELATIVE_URL_ROOT does not work for me since I need the root to be dynamic based on the war name. I ended up overriding _path.scss to prepend ./ to font-url. This fixed my problem by making the URLs relative to application.css - matching the behavior of previous font-awesome-sass releases - while keeping the fix for asset compiling.

@brianpattison
Copy link
Contributor Author

@lightswitch05 Glad figured out a solution. The reason that ./ isn't used here is because we don't want to use the relative URL, we want to use whatever Asset Pipeline says to use. The stylesheet where you include require font-awesome might not be in the same directory as the font, so we let asset pipeline handle writing the URL.

I feel like there's a better solution to your problem than what you're doing, but I honestly don't know what it is. The asset pipeline is kind of crazy. :)

@lightswitch05
Copy link

@brianpattison - I ended up removing my hack because it wasn't actually working. I added: config.action_controller.relative_url_root = 'my_app' - which broke everything.

The problem is that I'm deploying on a java server using jRuby. a war file sets the context of the application, so during runtime, the app knows that it is within a directory my_app and can respond properly. However, the asset pipeline is not able to know this during precompilation. When setting relative_url_root, rails tries to do a directory within its own context - meaning the asset url ends up looking like this example.com/my_app/my_app/assets/application-38cac4372aa1f12a5a4a07dd8d9f9cf3.css, which is obviously wrong. But then again, if I look at the compiled application.css - it finally has the correct URL for font-awesome.

I don't think forcing font-awesome-sass users to set relative_url_root is a valid option here. The URLs are always going to be defined within application.css - if application.css is being loaded correctly in the first place, then changing relative_url_root only makes the problem worse.

I don't know what the best solution for this is. Perhaps we could change it to be a relative URL and then add a sass variable to adjust that relative path for anyone who has it installed in a strange location. I don't know how to make use of the asset pipeline while keeping it a relative path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants