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}"
No comments yet.
You must be logged in to add your own comment.