Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add support to cache digests

  • Loading branch information...
commit fbe59f96be6089167e8b31600ccedcfe09b515cc 1 parent e397387
@leogalmeida leogalmeida authored
Showing with 37 additions and 3 deletions.
  1. +11 −2 README.md
  2. +25 −0 lib/slim-rails.rb
  3. +1 −1  lib/slim-rails/version.rb
View
13 README.md
@@ -1,6 +1,15 @@
# slim-rails
-slim-rails provides Slim generators for Rails 3 and 4. It was based on [haml-rails](http://github.com/indirect/haml-rails) and it does basically the same: configures Slim as the template engine automatically for your rails app.
+slim-rails provides Slim generators for Rails 3 and 4. It was based on
+[haml-rails](http://github.com/indirect/haml-rails) and it does basically the
+same:
+
+* Any time you generate a controller or scaffold, you'll get Slim templates
+ (instead of ERB)
+* When your Rails application loads, Slim will be loaded and initialized
+ automatically
+* Slim templates will be respected by the view template cache digestor
+
To use it, add this line to your Gemfile:
```ruby
@@ -11,4 +20,4 @@ And that's it.
From the version 0.2.0, there is no need to include gem "slim" in your Gemfile.
-Every time you generate a controller or scaffold, you'll get Slim templates.
+Every time you generate a controller or scaffold, you'll get Slim templates.
View
25 lib/slim-rails.rb
@@ -9,6 +9,31 @@ class Railtie < ::Rails::Railtie
else
config.generators.template_engine :slim
end
+
+ initializer 'slim_rails.configure_template_digestor' do
+ ActiveSupport.on_load(:action_view) do
+ ActiveSupport.on_load(:after_initialize) do
+ begin
+ 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
+ elsif ::Rails.version.to_s >= '4.0'
+ # 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
+ ActionView::Base.cache_template_loading = false if ::Rails.env.development?
+ end
+ rescue
+ # likely this version of Rails doesn't support dependency tracking
+ end
+ end
+ end
+ end
end
end
end
View
2  lib/slim-rails/version.rb
@@ -1,5 +1,5 @@
module Slim
module Rails
- VERSION = "2.0.4"
+ VERSION = "2.1.0"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.