Skip to content

Instantly share code, notes, and snippets.

@nzaillian
Last active December 20, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzaillian/6127613 to your computer and use it in GitHub Desktop.
Save nzaillian/6127613 to your computer and use it in GitHub Desktop.
cache_digests dependency dump rake task updated for Rails 4
# 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