Reload the coffee files automatically?

49 views
Skip to first unread message

rcarr...@gmail.com

unread,
Dec 19, 2012, 4:45:48 PM12/19/12
to calatrav...@googlegroups.com
Just started playing around with calatrava.

As I test and update my pages/controllers, it'd be awesome if a page refresh would cause them to reload. Seems like I have to restart apache (or reload it) using the rake tasks to make that happen. I feel like I MustBeDoingItWrong. Am I?

Rick

ja...@jagregory.com

unread,
Mar 10, 2013, 11:17:27 PM3/10/13
to calatrav...@googlegroups.com, rcarr...@gmail.com

The easiest way to do this without needing to modify Calatrava is to use an out-of-process reloader. I've been using rerun (https://github.com/alexch/rerun).

rerun 'rake web:apache:start' --pattern '**/*.{coffee,js,html,css,sass,scss,haml,yml}'

And that'll automatically restart apache whenever any of those files change. It's not instant, but it's better than nothing.

priy...@thoughtworks.com

unread,
May 18, 2013, 2:31:04 AM5/18/13
to calatrav...@googlegroups.com, rcarr...@gmail.com, James Andrew Gregory

There is an easy and better way to do this. I have been doing it on my projects. I should probably compile and submit it as a patch. Here is what you need to do. (Similar to what James suggest below, but bit more targeted)

Add "filewatcher" to your Gemfile

bundle install

Create a file auto_update.rb (or whatever name you fancy) in your root directory. And add contents like

require 'filewatcher'

FileWatcher.new(["kernel/", "shell/"]).watch do |filename|
puts "Recompiling file " + filename
system "node_modules/coffee-script/bin/coffee --compile --output /<path_to_app>/web/public/scripts #{filename}"
end

This would mean that it would compile the coffeescript to the js file automagically whenever the file changes. You may have to add this for multiple directories by listing them in the comma separated way.

The best part is that apache will pick up changes in js files upon a browser refresh so you won't have to restart server or any of that, unless you change something that you have set up a file watcher for.

In an ideal work, we would like the rake tasks with calatrava to be exposed to do the individual setps and then call that rake tasks instead of compiling coffeescript files ourselves. In that case, the watcher can start off with apache and world will be beautiful again. :)

Let me know if you face issues with this.

priy...@thoughtworks.com

unread,
Jun 5, 2013, 10:16:09 AM6/5/13
to calatrav...@googlegroups.com, rcarr...@gmail.com
Here is the pull request for this, as promised in my last response.
https://github.com/calatrava/calatrava/pull/77
Reply all
Reply to author
Forward
0 new messages