Skip to content

Commit

Permalink
update sync_utils:get_src_dir to include a Nitrogen mode, which keeps…
Browse files Browse the repository at this point in the history
… it backwards compatible with existing Nitrogen installations
  • Loading branch information
choptastic committed Oct 4, 2011
1 parent 222631a commit b159a83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.markdown
Expand Up @@ -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:
Expand Down
38 changes: 29 additions & 9 deletions src/sync_utils.erl
Expand Up @@ -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) ->
Expand Down

0 comments on commit b159a83

Please sign in to comment.