deface icon indicating copy to clipboard operation
deface copied to clipboard

Deface precompile fails on HAML partials

Open matfiz opened this issue 12 years ago • 10 comments

Hi,

I was really glad to see the precompile option added to deface. I use deface quite widely for Spree Commerce and the precompile would certainly give a great boost - GREAT JOB Deface Team!

However, recently I've added several haml partials rendered through deface. When I try to precompile it on server using:

bundle exec rake deface:precompile

I got an error:

uninitialized constant Deface::HamlConverter

Do you have any idea how to correct it?

matfiz avatar May 03 '12 19:05 matfiz

@matfiz it might just be that Deface can't find the haml engine when loading (so it doesn't require the hamlconverter). Can you confirm that haml is required when running the precompile rake?

I'll try testing the same locally.

BDQ avatar May 14 '12 10:05 BDQ

Any progress on this?

NathanielWroblewski avatar Nov 06 '13 23:11 NathanielWroblewski

@NathanielWroblewski Not that I know of. Do you have some steps that would reproduce this issue? I could probably take a look at it next week for you.

radar avatar Nov 08 '13 05:11 radar

I'll try to whip something up. Thanks, @radar.

NathanielWroblewski avatar Nov 11 '13 18:11 NathanielWroblewski

@radar, I'm able to circumvent this by appending the .deface suffix to my haml partials. I'm not too familiar with this gem though, so I'll try to spin up a simple application that reproduces this error in case there are underlying issues.

NathanielWroblewski avatar Nov 11 '13 19:11 NathanielWroblewski

I'm seeing another Haml related issue which may be related to this one: #119.

radar avatar Nov 15 '13 02:11 radar

The reason is here https://github.com/spree/deface/blob/master/lib/deface/railtie.rb#L58

haml_converter required only if deface is enabled by config, but if you want to use deface precompilation you need to disable deface... Paradox

arturtr avatar Dec 24 '14 10:12 arturtr

How do other people solve this issue?

For reference this seems to work for me. I just create a deface_precompile.rake file and override the precompile rake task like this:

require 'deface'

# checks if haml is loaded and enables support
if defined?(Haml)
  Rails.application.config.deface = Deface::Environment.new
  Rails.application.config.deface.haml_support = true
  require 'deface/haml_converter'
end

namespace :deface do
  desc "Precompiles overrides into template files"
  task :precompile => [:environment, :clean] do |t, args|
    require "deface/action_view_extensions"
    Deface::Precompiler.precompile()
  end
end

ChrisLusted avatar Jun 05 '15 09:06 ChrisLusted

I solve it with precompile on capistrano deploy by rake task

arturtr avatar Jun 05 '15 09:06 arturtr

@arturtr something like this?

namespace :deface do
  desc 'Precompile deface templates'
  task :precompile do
    on roles(:app) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'deface:precompile'
        end
      end
    end
  end
end

after 'deploy:updated', 'deface:precompile'

ChrisLusted avatar Jun 05 '15 10:06 ChrisLusted