chrismccord/sync — pull request #41 by aaronjensen (2013-05-22 05:22:48+00:00)
Title: Use with cache_digests

I may turn this into a pull request in a few, but on my project I used this to get cache digests paying attention to `sync` calls:

In `lib/sync_tracker.rb`:
```ruby
require 'action_view/dependency_tracker'

class SyncTracker < ActionView::DependencyTracker::ERBTracker
# Matches:
# sync partial: "comment", collection: commentable.comments
# sync partial: "comment", resource: comment
SYNC_DEPENDENCY = /
sync\s* # sync, followed by optional whitespace
\(?\s* # start an optional parenthesis for the sync call
(?:partial:|:partial\s+=>)\s* # naming the partial, used with collection
["']([a-z][a-z_\/]+)["']\s* # the template name itself -- 1st capture
,\s* # comma separating parameters
:?(?:resource|collection)(?::|\s+=>)\s* # resource or collection identifier
@?(?:[a-z]+\.)*([a-z]+) # the resource or collection itself -- 2nd capture
/x

def self.call(name, template)
new(name, template).dependencies
end

def dependencies
(sync_dependencies + super).uniq
end

private

def source
template.source
end

def sync_dependencies
source.scan(SYNC_DEPENDENCY).
collect { |template, resource| "sync/#{resource.pluralize}/#{template}" }
end
end
```

In `config/initializers/cache_digests.rb`:
```ruby
require 'action_view/dependency_tracker'
ActionView::DependencyTracker.register_tracker :haml, SyncTracker
ActionView::DependencyTracker.register_tracker :erb, SyncTracker
```