forked from benoitc/couchapp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle .couchappignore. While I'm here, add the possibility to set
global patterns to ignore in ~/.couchapp.conf .
- Loading branch information
benoitc
committed
Dec 4, 2010
1 parent
3fb099e
commit f5fea28
Showing
7 changed files
with
386 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
%%% -*- erlang -*- | ||
%%% | ||
%%% This file is part of couchapp released under the Apache 2 license. | ||
%%% See the NOTICE for more information. | ||
|
||
-module(couchapp_ignore). | ||
|
||
-author('Benoît Chesneau <benoitc@e-engura.org>'). | ||
|
||
-include("couchapp.hrl"). | ||
|
||
|
||
-export([init/2, | ||
ignore/2]). | ||
|
||
%% ==================================================================== | ||
%% Public API | ||
%% ==================================================================== | ||
|
||
init(AppDir, #config{ignore=OldIgnore}=Config) -> | ||
IgnoreFile = filename:join(AppDir, ".couchappignore"), | ||
Ignore = case filelib:is_regular(IgnoreFile) of | ||
true -> | ||
load(IgnoreFile); | ||
_ -> | ||
[] | ||
end, | ||
Config#config{ignore=OldIgnore ++ Ignore}. | ||
|
||
ignore(Path, #config{ignore=Ignore}) -> | ||
ignore1(Ignore, Path). | ||
|
||
ignore1([], _Path) -> | ||
false; | ||
ignore1([Pattern|Rest], Path) -> | ||
case re:run(Path, Pattern, [global, caseless, unicode, multiline, | ||
{capture, all, binary}]) of | ||
nomatch -> | ||
ignore1(Rest, Path); | ||
_ -> | ||
?DEBUG("File '~p' ignored.~n", [Path]), | ||
true | ||
end. | ||
|
||
%% ==================================================================== | ||
%% Internal functions | ||
%% ==================================================================== | ||
|
||
load(File) -> | ||
case file:read_file(File) of | ||
{ok, Bin} -> | ||
Bin1 = remove_comments(Bin), | ||
couchbeam_util:json_decode(Bin1); | ||
Error -> | ||
?ERROR("can't read '~p' [~p]~n", [File, Error]), | ||
[] | ||
end. | ||
|
||
|
||
remove_comments(Content) -> | ||
P = "(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)", | ||
re:replace(Content, P, ""). | ||
|
Oops, something went wrong.