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

Support template dependency tracking in Rails 4 #456

Closed
jlecour opened this issue Oct 31, 2013 · 4 comments
Closed

Support template dependency tracking in Rails 4 #456

jlecour opened this issue Oct 31, 2013 · 4 comments

Comments

@jlecour
Copy link

jlecour commented Oct 31, 2013

Hi,

I've noticed that nested partials were not used in the dependency tracking for Rails 4 caching.

With cache enabled, Rails is hashing each template to detect changes and change the cache key. It is also configured to look inside ERB templates and partials for inclusion of other templates of partials. The problem is that Rails is only looking inside *.erb files. When using Slim, only the top template is analyzed.

In the [indirect/haml-rails](https://github.com/indirect/haml-rails/] project, there is a railtie that registers the tracker for *.haml templates.

I guess Slim should do something similar.

I've added a basic initializer in my app and it works :

if defined?(CacheDigests::DependencyTracker)
  # 'cache_digests' gem being used (overrides Rails 4 implementation)
  CacheDigests::DependencyTracker.register_tracker :slim, CacheDigests::DependencyTracker::ERBTracker

  if ::Rails.env.development?
    # recalculate cache digest keys for each request
    CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new
  end
else
  # will only apply if Rails 4, which includes 'action_view/dependency_tracker'
  require 'action_view/dependency_tracker'
  ActionView::DependencyTracker.register_tracker :slim, ActionView::DependencyTracker::ERBTracker
end
@minad
Copy link
Member

minad commented Oct 31, 2013

Should this be part of slim-rails or slim?

@jlecour
Copy link
Author

jlecour commented Oct 31, 2013

@minad Since Slim claims that slim-rails is not needed to use it with Rails (just for generators) I guess it should be part of slim.

That said, I think that everything related to frameworks integration should be in a separate gem, with only the templating parts in slim.

@clemensg
Copy link

@minad Maybe slim-rails is the best choice, because this is an optional enhancement. You can use slim with Rails without slim-rails, but if you do use slim-rails, you get dependency tracking in the template cache.

I would really like slim to take advantage of dependency tracking.

@minad
Copy link
Member

minad commented Dec 15, 2013

moved issue to slim-rails

@minad minad closed this as completed Dec 15, 2013
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

No branches or pull requests

3 participants