Last active
December 20, 2015 11:59
-
-
Save nzaillian/6127613 to your computer and use it in GitHub Desktop.
cache_digests dependency dump rake task updated for Rails 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The functionality from the cache_digests gem (https://github.com/rails/cache_digests) | |
# has been merged into actionpack for Rails 4, | |
# but the handy rake task to dump the template dependency hierarchy for a given template | |
# to the console didn't. Here's the rake task from DHH's cache_digests project tree, updated | |
# for ActionView in Rails 4. Copy it to your project's lib/tasks directory as "cache_digests.rake" | |
namespace :cache_digests do | |
desc 'Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)' | |
task :nested_dependencies => :environment do | |
raise 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present? | |
template, format = ENV['TEMPLATE'].split(".") | |
format ||= :html | |
puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).nested_dependencies | |
end | |
desc 'Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)' | |
task :dependencies => :environment do | |
raise 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present? | |
template, format = ENV['TEMPLATE'].split(".") | |
format ||= :html | |
puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).dependencies | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment