blog comments 0 del.icio.us bookmarks 0 diggs 0 Google results 0

2.3
PostRank

Cappin' that Stat

Err the Blog - Home From Err the Blog - Home, 1 year ago, 0 views

vJot’s a public code base, so I saw it unbecoming of an open-source guy to add my stats html to the repo. No worries, I’ll just add it with a little help via the wonder library, Capistrano:

task :after_symlink, :roles => :app do
  stats = <<-JS
    <script src="http://www.google-analytics.com/urchin.js">
    </script>
    <script type="text/javascript">
    _uacct = "UA-104904-8";
    urchinTracker();
    </script>
  JS
  layout = "#{current_path}/app/views/layouts/application.html.erb" 
  run "cat #{layout} | sed 's?</body>?#{stats}</body>?' > ~/app.tmp" 
  run "mv ~/app.tmp #{layout}" 
end

The code appends my Analytics’ javascript to the layout file and voilà, instant stats!

The secret sauce is that if you’ve defined an after_symlink task, Capistrano will run it during your regularly scheduled cap deploy. As a matter of fact, it has before_ and after_ hooks for all its tasks, including any tasks that you’ve written. Schweet.

I’m all ears as to why the following doesn’t work if someone would enlighten me:
run "cat #{layout} | sed 's?</body>?#{stats}</body>?' > #{layout}" 

comments

No comments yet.

You must be logged in to add your own comment.