7

I've got a problem with my font assets being served without digest in production. As soon as I do rake assets:precompile I get:

 5futurebit-webfont-c133dbefd9e1ca208741ed53c7396062.eot

I was trying to link it with font-face in scss with asset-url, asset-path, font-url and font-path but all of them end up outputting path:

 /assets/5futurebit-webfont.eot

For now I'm copying assets from /app/assets/fonts straight to /public/assets/ but it doesn't feel like that's the way to do it.

Anton
  • 137
  • 8
  • 1
    I believe this question may be relevant http://stackoverflow.com/questions/10905905/using-fonts-with-rails-asset-pipeline – Chris Nicola Oct 13 '13 at 17:21

3 Answers3

2

I've been looking at a similar issue and am currently using the non-stupid-digest-assets gem: https://github.com/alexspeller/non-stupid-digest-assets

For more info on how you can use it, see here. Correct use of non-stupid-digest-assets gem

Now that being said, the link provided by Chris (specifically, https://stackoverflow.com/a/17367264/291640) seems like it may accomplish the same as the gem without the gem itself. I know I need to look into it further.

Community
  • 1
  • 1
whoughton
  • 1,395
  • 11
  • 21
1

Make sure you have the exact filename WITH extention name of the font in your font-url declaration like:

Correct:

@font-face{
  font-family: 'Sawasdee';
  src: font-url('Sawasdee.ttf') format('truetype');
}

Wrong:

@font-face{
  font-family: 'Sewasdee';
  src: font-url('Sewasdee') format('truetype');
}

My font folder:

fonts
 |_ Sewasdee.ttf
 |_ Otherfont.ttf
Norly Canarias
  • 1,736
  • 1
  • 21
  • 19
0

Here is our solution, that is based partially on what Sprocets does. It is working with Rails4. It automatically generates a nondigest version for all assets, that were listed in config.assets.precompile, after precompilation was done.

# lib/tasks/assets_nondigest.rake
require 'fileutils'

namespace "assets:precompile" do
  desc "Create nondigest versions of defined assets"
  task :nondigest => :environment do
    sprocket_task = Sprockets::Rails::Task.new ::Rails.application
    assets = ::Rails.application.config.assets.precompile

    paths = sprocket_task.index.each_logical_path(assets).to_a +
      assets.select { |asset| Pathname.new(asset).absolute? if asset.is_a?(String)}

    paths.each do |path|
      if asset = sprocket_task.index.find_asset(path)
        copy_target = File.join(sprocket_task.output, asset.digest_path)
        target = File.join(sprocket_task.output, asset.logical_path)

        sprocket_task.logger.info "Writing #{target}"
        asset.write_to target
        asset.write_to "#{target}.gz" if asset.is_a?(Sprockets::BundledAsset)
      end
    end
  end
end

Rake::Task['assets:precompile'].enhance do
  Rake::Task['assets:precompile:nondigest'].invoke
end
Max
  • 2,063
  • 2
  • 17
  • 16