Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update sync_utils:get_src_dir to include a Nitrogen mode, which keeps…

… it backwards compatible with existing Nitrogen installations
  • Loading branch information...
commit b159a83121183869b6cafc51db13ef749af1649b 1 parent 222631a
@choptastic choptastic authored
Showing with 36 additions and 9 deletions.
  1. +7 −0 README.markdown
  2. +29 −9 src/sync_utils.erl
View
7 README.markdown
@@ -24,6 +24,13 @@ Sync also periodically checks the last modified date of any beam files, and auto
The scanning process adds 1% to 2% CPU load on a running Erlang VM. Much care has been taken to keep this low. Shouldn't have to say this, but this is for development mode only, don't run it in production.
+## Using it with Nitrogen
+
+If you are running sync with the [Nitrogen Web Framework](http://www.nitrogenproject.com), be sure to add the following line to your etc/vm.args file:
+
+ -sync sync_mode nitrogen
+
+
## Growl Notifications
If you are running a Mac and have [Growl](http://growl.info) and the **growlnotify** utility installed, Sync will pop up Growl notifications with compilation results:
View
38 src/sync_utils.erl
@@ -46,19 +46,39 @@ get_options_from_module(Module) ->
end.
-get_src_dir(Dir) when Dir == ""; Dir == "/"; Dir == "." ->
- undefined;
+%% @private Find the src directory for the specified Directory
get_src_dir(Dir) ->
+ Mode = get_env(sync_mode,normal),
+ get_src_dir(Mode,Dir).
+
+get_src_dir(_,Dir) when Dir == ""; Dir == "/"; Dir == "." ->
+ undefined;
+
+%% @private Find's the src directory for the directory using the normal method or the original method which is compatible with Nitrogen
+%% Will drop back in the directory tree until it finds either a src, ebin, or include directory and return the parent directory with "src" appended
+get_src_dir(nitrogen,Dir) ->
+ IsCodeDir = filelib:is_dir(filename:join(Dir, "src"))
+ orelse filelib:is_dir(filename:join(Dir, "ebin"))
+ orelse filelib:is_dir(filename:join(Dir, "include")),
+
+ if
+ IsCodeDir ->
+ {ok, filename:join(Dir, "src")};
+ true -> get_src_dir(nitrogen,filename:dirname(Dir))
+ end;
+
+%% Normal method is smarter and returns exactly any path that has .erl or .hrl files in it
+%% With Nitrogen, or any structure in which -include("something.hrl") specifies an implied directory, this will give "unable to find include file" errors
+get_src_dir(normal,Dir) ->
HasCode =
filelib:wildcard("*.erl", Dir) /= [] orelse
filelib:wildcard("*.hrl", Dir) /= [],
-
- case HasCode of
- true ->
- {ok, Dir};
- false ->
- get_src_dir(filename:dirname(Dir))
- end.
+ if
+ HasCode -> {ok,Dir};
+ true -> get_src_dir(filename:dirname(Dir))
+ end;
+get_src_dir(OtherMode,_Dir) ->
+ throw({unknown_mode,OtherMode}).
%% @private Return all files in a directory matching a regex.
wildcard(Dir, Regex) ->
Please sign in to comment.
Something went wrong with that request. Please try again.