Skip to content
Browse files

s/couchapp/erlca

  • Loading branch information...
1 parent d5e62e9 commit e26fa50610922edccb2168303991dac36ed642df @benoitc committed May 28, 2011
View
4 .gitignore
@@ -1,7 +1,6 @@
*.gem
*.swp
*.pyc
-Couchapp.egg-info
build
dist
setuptools-*
@@ -11,5 +10,4 @@ setuptools-*
deps
ebin/*
erl_crash.dump
-debian/python-couchapp
-debian/couchapp
+erlca
View
6 bootstrap
@@ -13,8 +13,8 @@ main(Args) ->
- %% Run couchapp to do proper .app validation and such
- couchapp:main(["compile"] ++ Args),
+ %% Run erlca to do proper .app validation and such
+ erlca:main(["compile"] ++ Args),
%% Read the contents of the files in ebin and templates; note that we place
@@ -58,7 +58,7 @@ main(Args) ->
io:format("Congratulations! You now have a self-contained script called \"erlca\" in\n"
"your current working directory. Place this script anywhere in your path\n"
"and you can use build and push your design docs and docs
- like couchapp.\n").
+ like erlca.\n").
load_files(Wildcard, Dir) ->
[read_file(Filename, Dir) || Filename <- filelib:wildcard(Wildcard,
View
4 couchapp.bat
@@ -1,4 +0,0 @@
-@echo off
-set couchappscript=%0
-escript.exe %couchappscript:.bat=% %*
-
View
4 erlca.bat
@@ -0,0 +1,4 @@
+@echo off
+set erlca=%0
+escript.exe %erlca:.bat=% %*
+
View
14 include/couchapp.hrl → include/erlca.hrl
@@ -1,6 +1,6 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
-record(config, { dir,
@@ -14,18 +14,18 @@
-define(FAIL, throw({error, failed})).
--define(ABORT(Str, Args), couchapp_util:abort(Str, Args)).
+-define(ABORT(Str, Args), erlca_util:abort(Str, Args)).
-define(CONSOLE(Str, Args), io:format(Str, Args)).
--define(DEBUG(Str, Args), couchapp_log:log(debug, Str, Args)).
--define(INFO(Str, Args), couchapp_log:log(info, Str, Args)).
--define(WARN(Str, Args), couchapp_log:log(warn, Str, Args)).
--define(ERROR(Str, Args), couchapp_log:log(error, Str, Args)).
+-define(DEBUG(Str, Args), erlca_log:log(debug, Str, Args)).
+-define(INFO(Str, Args), erlca_log:log(info, Str, Args)).
+-define(WARN(Str, Args), erlca_log:log(warn, Str, Args)).
+-define(ERROR(Str, Args), erlca_log:log(error, Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
--record(couchapp, {
+-record(erlca, {
config,
path,
att_dir,
View
2 rebar.config
@@ -6,7 +6,7 @@
{i, "deps/couchbeam/include"},
debug]}.
-{app_bin, ["priv/couchapp"]}.
+{app_bin, ["priv/elrca"]}.
{deps, [
%% couchbeam client
View
16 src/couchapp.app.src → src/erlca.app.src
@@ -1,11 +1,11 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
-{application, couchapp,
- [{description, "Couchapp: Couchdb Application Tool"},
- {vsn, "0.8.0"},
+{application, erlca,
+ [{description, "erlca: Couchdb Application Tool"},
+ {vsn, "0.1.0"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]},
@@ -16,8 +16,8 @@
%% list of commands modules
{modules, [
- couchapp_init,
- couchapp_generate,
- couchapp_push,
- couchapp_clone]}
+ erlca_init,
+ erlca_generate,
+ erlca_push,
+ erlca_clone]}
]}]}.
View
4 src/erlca.erl
@@ -1,6 +1,6 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
-module(erlca).
@@ -9,7 +9,7 @@
-export([main/1]).
main(Args) ->
- case catch(couchapp_core:run(Args)) of
+ case catch(erlca_core:run(Args)) of
ok ->
ok;
{error, failed} ->
View
26 src/couchapp_clone.erl → src/erlca_clone.erl
@@ -1,11 +1,11 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_clone).
+-module(erlca_clone).
--include("couchapp.hrl").
+-include("erlca.hrl").
-export([clone/2]).
@@ -18,7 +18,7 @@ clone([Url], Config) ->
clone([Url, Path|_], Config) ->
clone1(filename:absname(Path), Url, Config);
clone(_, _) ->
- ?ERROR("missing arguments. Command line should be :'couchapp clone "
+ ?ERROR("missing arguments. Command line should be :'erlca clone "
++ "URL [CouchappDir]", []),
halt(1).
@@ -27,17 +27,17 @@ clone(_, _) ->
%% ====================================================================
clone1(Path, Url, Config) ->
- case couchapp_util:parse_couchapp_url(Url) of
+ case erlca_util:parse_erlca_url(Url) of
{ok, Db, AppName, DocId} ->
Path1 = case Path of
"." ->
- filename:join(couchapp_util:get_cwd(), AppName);
+ filename:join(erlca_util:get_cwd(), AppName);
_ ->
filename:absname(Path)
end,
- case couchapp_util:in_couchapp(Path1) of
+ case erlca_util:in_erlca(Path1) of
{ok, _} ->
- ?ERROR("Can't clone in an existing couchapp.~n",
+ ?ERROR("Can't clone in an existing erlca.~n",
[]),
halt(1);
_ ->
@@ -50,10 +50,10 @@ clone1(Path, Url, Config) ->
do_clone(Path, DocId, Db, Config) ->
case couchbeam:open_doc(Db, DocId) of
{ok, Doc} ->
- % initialize the couchapp directory
+ % initialize the erlca directory
ok = filelib:ensure_dir(Path),
?DEBUG("path ~p~n", [Path]),
- couchapp_init:init([Path], Config),
+ erlca_init:init([Path], Config),
AttDir = filename:join(Path, "_attachments"),
{Atts} = couchbeam_doc:get_value(<<"_attachments">>, Doc,
@@ -98,7 +98,7 @@ attachments_to_fs([AttName|Rest], Db, DocId, AttDir) ->
AttName1 = binary_to_list(AttName),
Path = filename:join(AttDir, filename:nativename(AttName1)),
Dir = filename:dirname(Path),
- ok = couchapp_util:make_dir(Dir),
+ ok = erlca_util:make_dir(Dir),
%% we stream attachments.
{ok, Fd} = file:open(Path, [write]),
@@ -134,7 +134,7 @@ doc_to_fs([{<<"_attachments">>, _}|Rest], Dir, Manifest, Objects,
doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
Path = filename:join(Dir, binary_to_list(PropName)),
Dir1 = filename:dirname(Path),
- ok = couchapp_util:make_dir(Dir1),
+ ok = erlca_util:make_dir(Dir1),
case Value of
{[_|_]} ->
case proplists:get_value(Path, Manifest) of
@@ -155,7 +155,7 @@ doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
{Path, V};
Ext when Ext =:= ".js" ->
SourceId = list_to_binary(
- couchapp_macros:get_source_id(Value)),
+ erlca_macros:get_source_id(Value)),
V1 = case proplists:get_value(SourceId,
Objects) of
undefined ->
View
30 src/couchapp_config.erl → src/erlca_config.erl
@@ -1,12 +1,12 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_config).
+-module(erlca_config).
-include("deps/couchbeam/include/couchbeam.hrl").
--include("couchapp.hrl").
+-include("erlca.hrl").
-export([new/0, new/1,
update/2,
@@ -15,12 +15,12 @@
set/3,
set_global/2, get_global/2]).
new() ->
- #config { dir = couchapp_util:get_cwd(),
+ #config { dir = erlca_util:get_cwd(),
opts = [] }.
new(Options) ->
- UserConfFile = filename:join(couchapp_util:user_path(),
- ".couchapp.conf"),
+ UserConfFile = filename:join(erlca_util:user_path(),
+ ".erlca.conf"),
UserConf = case filelib:is_regular(UserConfFile) of
true ->
{ok, Bin} = file:read_file(UserConfFile),
@@ -30,7 +30,7 @@ new(Options) ->
end,
{Dbs, Hooks, Extensions, Ignore} = parse_conf(UserConf),
- #config { dir = couchapp_util:get_cwd(),
+ #config { dir = erlca_util:get_cwd(),
opts = Options,
dbs = Dbs,
hooks = Hooks,
@@ -40,9 +40,9 @@ new(Options) ->
update(AppDir, #config{dbs=Dbs, hooks=Hooks, extensions=Extensions,
ignore=Ignore}=Config) ->
- RcFile = filename:join(AppDir, ".couchapprc"),
+ RcFile = filename:join(AppDir, ".erlcarc"),
- %% load .couchapprc
+ %% load .erlcarc
AppConf = case filelib:is_regular(RcFile) of
true ->
{ok, Bin} = file:read_file(RcFile),
@@ -51,25 +51,25 @@ update(AppDir, #config{dbs=Dbs, hooks=Hooks, extensions=Extensions,
{[]}
end,
- %% update conf from .couchapprc
+ %% update conf from .erlcarc
{Dbs1, Hooks1, Extensions1, Ignore1} = parse_conf(AppConf),
Config1 = Config#config { dbs = Dbs ++ Dbs1,
hooks = Hooks ++ Hooks1,
extensions = Extensions ++ Extensions1,
ignore = Ignore ++ Ignore1},
%% get ignore file patterns.
- couchapp_ignore:init(AppDir, Config1).
+ erlca_ignore:init(AppDir, Config1).
get_db(Config, DbString) ->
proplists:get_value(DbString, Config#config.dbs).
set_global(Key, Value) ->
- application:set_env(couchapp_global, Key, Value).
+ application:set_env(erlca_global, Key, Value).
get_global(Key, Default) ->
- case application:get_env(couchapp_global, Key) of
+ case application:get_env(erlca_global, Key) of
undefined ->
Default;
{ok, Value} ->
@@ -96,7 +96,7 @@ parse_conf(Conf) ->
Extensions = case couchbeam_doc:get_value(<<"extensions">>, Conf) of
undefined -> [];
{Ext} ->
- [{couchapp_util:v2a(Mod), couchapp_util:v2a(Command)}
+ [{erlca_util:v2a(Mod), erlca_util:v2a(Command)}
|| {Mod, Command} <- Ext]
end,
Hooks = case couchbeam_doc:get_value(<<"hooks">>, Conf) of
@@ -120,7 +120,7 @@ get_config_dbs([{Name, Obj}|Rest], Dbs) ->
undefined ->
get_config_dbs(Rest, Dbs);
DbString ->
- Db = couchapp_util:db_from_string(binary_to_list(DbString)),
+ Db = erlca_util:db_from_string(binary_to_list(DbString)),
Db1 = case couchbeam_doc:get_value(<<"oauth">>, Obj) of
undefined ->
Db;
View
40 src/couchapp_core.erl → src/erlca_core.erl
@@ -1,12 +1,12 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_core).
+-module(erlca_core).
-author('Benoît Chesneau <benoitc@e-engura.org>').
--include("couchapp.hrl").
+-include("erlca.hrl").
-export([run/1]).
@@ -16,11 +16,11 @@ run(["help"]) ->
help(),
ok;
run(["version"]) ->
- ok = application:load(couchapp),
+ ok = application:load(erlca),
version(),
ok;
run(RawArgs) ->
- ok = application:load(couchapp),
+ ok = application:load(erlca),
%% parse arguments
{Options, Commands} = parse_args(RawArgs),
@@ -29,29 +29,29 @@ run(RawArgs) ->
{ok, _} = couchbeam:start(),
%% Initialize logging system
- couchapp_log:init(),
+ erlca_log:init(),
%% Determine the location of the rebar executable; important for pulling
%% resources out of the escript
- couchapp_config:set_global(escript, filename:absname(escript:script_name())),
- ?DEBUG("Couchapp location: ~p\n", [couchapp_config:get_global(escript, undefined)]),
+ erlca_config:set_global(escript, filename:absname(escript:script_name())),
+ ?DEBUG("Couchapp location: ~p\n", [erlca_config:get_global(escript, undefined)]),
%% Note the top-level directory for reference
- couchapp_config:set_global(base_dir, filename:absname(couchapp_util:get_cwd())),
+ erlca_config:set_global(base_dir, filename:absname(erlca_util:get_cwd())),
process_commands(Commands, Options).
process_commands([Command|Args], Options) ->
- {ok, Modules} = application:get_env(couchapp, modules),
- Config = couchapp_config:new(Options),
+ {ok, Modules} = application:get_env(erlca, modules),
+ Config = erlca_config:new(Options),
execute(list_to_atom(Command), Args, Modules, Config).
execute(Command, Args, Modules, Config) ->
case select_modules(Modules, Command, []) of
[] ->
?WARN("'~p' unkown command", [Command]);
TargetModules ->
- Dir = couchapp_util:get_cwd(),
+ Dir = erlca_util:get_cwd(),
?CONSOLE("==> ~s (~s)\n", [filename:basename(Dir), Command]),
case catch(run_modules(TargetModules, Command, Args, Config)) of
ok ->
@@ -135,7 +135,7 @@ set_global_flag(Options, Flag) ->
false ->
"0"
end,
- couchapp_config:set_global(Flag, Value).
+ erlca_config:set_global(Flag, Value).
%%
%% show info and maybe halt execution
@@ -169,27 +169,27 @@ show_info_maybe_halt(Opts, NonOptArgs) ->
end.
help() ->
OptSpecList = option_spec_list(),
- getopt:usage(OptSpecList, "couchapp",
+ getopt:usage(OptSpecList, "erlca",
"[...] <command,...>",
[{"command", "Command to run (e.g. push)"}]).
%%
%% print known commands
%%
commands() ->
S = <<"
-init initialize a couchapp
+init initialize a erlca
push [options...] [dir] dest push a document to couchdb
clone [option] source dir clone a document from couchdb
pushapps [option] source dest push all CouchApps in a folder
to couchdb
pushdocs [option] source dest push all docs in a folder to
couchdb
-generate [option] func [dir] name generate a new couchapp or a
+generate [option] func [dir] name generate a new erlca or a
function from a template
vendor install or update a vendor
install [opts] dir src
update [opts] dir src
-browse display the couchapp in the
+browse display the erlca in the
browser.
help Show the program options
@@ -206,8 +206,8 @@ version Show version information
%% show version information and halt
%%
version() ->
- {ok, Vsn} = application:get_key(couchapp, vsn),
- ?CONSOLE("couchapp version: ~s\n", [Vsn]).
+ {ok, Vsn} = application:get_key(erlca, vsn),
+ ?CONSOLE("erlca version: ~s\n", [Vsn]).
%%
@@ -222,7 +222,7 @@ filter_flags([Item | Rest], Commands) ->
filter_flags(Rest, [Command | Commands]);
[KeyStr, Value] ->
Key = list_to_atom(KeyStr),
- couchapp_config:set_global(Key, Value),
+ erlca_config:set_global(Key, Value),
filter_flags(Rest, Commands);
Other ->
?CONSOLE("Ignoring command line argument: ~p\n", [Other]),
View
4 src/couchapp_generate.erl → src/erlca_generate.erl
@@ -1,9 +1,9 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_generate).
+-module(erlca_generate).
generate([AppName]) ->
generate_app(AppName, ".");
View
8 src/couchapp_ignore.erl → src/erlca_ignore.erl
@@ -1,13 +1,13 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_ignore).
+-module(erlca_ignore).
-author('Benoît Chesneau <benoitc@e-engura.org>').
--include("couchapp.hrl").
+-include("erlca.hrl").
-export([init/2,
ignore/2]).
@@ -21,7 +21,7 @@
%% ====================================================================
init(AppDir, #config{ignore=OldIgnore}=Config) ->
- IgnoreFile = filename:join(AppDir, ".couchappignore"),
+ IgnoreFile = filename:join(AppDir, ".erlcaignore"),
Ignore = case filelib:is_regular(IgnoreFile) of
true ->
load(IgnoreFile);
View
10 src/couchapp_init.erl → src/erlca_init.erl
@@ -1,9 +1,9 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_init).
+-module(erlca_init).
-author('Benoît Chesneau <benoitc@e-engura.org>').
-export([init/2]).
@@ -13,7 +13,7 @@
%% ====================================================================
init([], Config) ->
- init1(couchapp_util:get_cwd(), Config);
+ init1(erlca_util:get_cwd(), Config);
init([Path|_], Config) ->
init1(Path, Config).
@@ -22,6 +22,6 @@ init([Path|_], Config) ->
%% ====================================================================
init1(Path, _Config) ->
- ok = couchapp_util:make_dir(Path),
- RcPath = filename:join(Path, ".couchapprc"),
+ ok = erlca_util:make_dir(Path),
+ RcPath = filename:join(Path, ".erlcarc"),
file:write_file(RcPath, ejson:encode({[]})).
View
12 src/couchapp_log.erl → src/erlca_log.erl
@@ -1,9 +1,9 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_log).
+-module(erlca_log).
-export([init/0,
set_level/1, get_level/0,
@@ -14,7 +14,7 @@
%% ===================================================================
init() ->
- case couchapp_config:get_global(verbose, "0") of
+ case erlca_config:get_global(verbose, "0") of
"1" ->
set_level(debug);
_ ->
@@ -23,18 +23,18 @@ init() ->
set_level(Level) ->
- ok = application:set_env(couchapp, log_level, Level).
+ ok = application:set_env(erlca, log_level, Level).
get_level() ->
- case application:get_env(couchapp, log_level) of
+ case application:get_env(erlca, log_level) of
undefined ->
error;
{ok, Value} ->
Value
end.
log(Level, Str, Args) ->
- {ok, LogLevel} = application:get_env(couchapp, log_level),
+ {ok, LogLevel} = application:get_env(erlca, log_level),
case should_log(LogLevel, Level) of
true ->
io:format(log_prefix(Level) ++ Str, Args);
View
6 src/couchapp_macros.erl → src/erlca_macros.erl
@@ -1,13 +1,13 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_macros).
+-module(erlca_macros).
-author('Benoît Chesneau <benoitc@e-engura.org>').
--include("couchapp.hrl").
+-include("erlca.hrl").
-export([process_macros/2,
get_source_id/1]).
View
92 src/couchapp_push.erl → src/erlca_push.erl
@@ -1,19 +1,19 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_push).
+-module(erlca_push).
-author('Benoît Chesneau <benoitc@e-engura.org>').
-include_lib("kernel/include/file.hrl").
--include("couchapp.hrl").
+-include("erlca.hrl").
-include("couchbeam.hrl").
-export([push/2]).
--export([make_doc/1, couchapp_from_fs/1, process_signatures/1]).
+-export([make_doc/1, erlca_from_fs/1, process_signatures/1]).
%% ====================================================================
%% Public API
@@ -23,25 +23,25 @@
push([], Config) ->
push(["default"], Config);
push([DbKey], Config) ->
- push1(couchapp_util:get_cwd(), DbKey, Config);
+ push1(erlca_util:get_cwd(), DbKey, Config);
push([Path, DbKey|_], Config) ->
push1(Path, DbKey, Config).
push1(Path, DbKey, Config) ->
Path1 = filename:absname(Path),
- case couchapp_util:in_couchapp(Path1) of
+ case erlca_util:in_erlca(Path1) of
{ok, CouchappDir} ->
- %% load app conf from .couchapprc and initialize ignore
+ %% load app conf from .erlcarc and initialize ignore
%% patterns.
- Config1 = couchapp_config:update(CouchappDir, Config),
+ Config1 = erlca_config:update(CouchappDir, Config),
- Db = couchapp_util:db_from_key(Config1, DbKey),
+ Db = erlca_util:db_from_key(Config1, DbKey),
?DEBUG("push ~p to ~p~n", [DbKey, CouchappDir]),
do_push(CouchappDir, Db, Config1);
{error, not_found} ->
- ?ERROR("Can't find initialized couchapp in '~p'~n", [Path]),
+ ?ERROR("Can't find initialized erlca in '~p'~n", [Path]),
halt(1)
end.
@@ -57,7 +57,7 @@ do_push(Path, #db{server=Server}=Db, DocId, Config) ->
{[]}
end,
- Couchapp = #couchapp{
+ Couchapp = #erlca{
config=Config,
path=Path,
att_dir=filename:join(Path, "_attachments"),
@@ -66,26 +66,26 @@ do_push(Path, #db{server=Server}=Db, DocId, Config) ->
old_doc = OldDoc
},
- {ok, Couchapp1} = couchapp_from_fs(Couchapp),
+ {ok, Couchapp1} = erlca_from_fs(Couchapp),
%% clean attachments and process signatures
Couchapp2 = process_signatures(Couchapp1),
- case couchapp_config:get(Config, atomic) of
+ case erlca_config:get(Config, atomic) of
true ->
FinalCouchapp = process_attachments(Couchapp2),
Doc = make_doc(FinalCouchapp),
{ok, _} = couchbeam:save_doc(Db, Doc);
false ->
Doc = make_doc(Couchapp2),
Doc1 = couchbeam:save_doc(Db, Doc),
- send_attachments(Db, Couchapp2#couchapp{doc=Doc1})
+ send_attachments(Db, Couchapp2#erlca{doc=Doc1})
end,
CouchappUrl = couchbeam:make_url(Server, couchbeam:doc_url(Db,
DocId), []),
% log info
- couchapp_log:log(info, "~p has been pushed from ~s.~n", [CouchappUrl,
+ erlca_log:log(info, "~p has been pushed from ~s.~n", [CouchappUrl,
Path]),
ok.
@@ -96,10 +96,10 @@ id_from_path(Path, Config) ->
{ok, Bin} = file:read_file(IdFile),
Bin;
false ->
- case couchapp_config:get(Config, docid) of
+ case erlca_config:get(Config, docid) of
undefined ->
Fname = list_to_binary(filename:basename(Path)),
- case couchapp_config:get(Config, is_ddoc) of
+ case erlca_config:get(Config, is_ddoc) of
true ->
<<"_design/", Fname/binary>>;
false ->
@@ -110,13 +110,13 @@ id_from_path(Path, Config) ->
end
end.
-couchapp_from_fs(#couchapp{path=Path}=Couchapp) ->
+erlca_from_fs(#erlca{path=Path}=Couchapp) ->
Files = filelib:wildcard("*", Path),
process_path(Files, Path, Couchapp).
-process_signatures(#couchapp{attachments=[]}=Couchapp) ->
+process_signatures(#erlca{attachments=[]}=Couchapp) ->
Couchapp;
-process_signatures(#couchapp{att_dir=AttDir, doc=Doc, old_doc=OldDoc,
+process_signatures(#erlca{att_dir=AttDir, doc=Doc, old_doc=OldDoc,
attachments=Atts}=Couchapp) ->
Signatures = case couchbeam_doc:get_value(<<"couchapp">>, OldDoc) of
@@ -134,15 +134,15 @@ process_signatures(#couchapp{att_dir=AttDir, doc=Doc, old_doc=OldDoc,
{Removed, NewAtts} = process_signatures1(Signatures, [], Atts,
AttDir),
- NewSignatures = [{couchapp_util:relpath(F, AttDir), S}
+ NewSignatures = [{erlca_util:relpath(F, AttDir), S}
|| {F, S} <- Atts],
{OldAtts} = couchbeam_doc:get_value(<<"_attachments">>, OldDoc, {[]}),
case Removed of
[] ->
Doc1 = couchbeam_doc:set_value(<<"_attachments">>,
{OldAtts}, Doc),
- Couchapp#couchapp{
+ Couchapp#erlca{
doc=Doc1,
attachments=NewAtts,
signatures=NewSignatures
@@ -151,25 +151,25 @@ process_signatures(#couchapp{att_dir=AttDir, doc=Doc, old_doc=OldDoc,
OldAtts1 = clean_old_attachments(Removed, OldAtts),
Doc1 = couchbeam_doc:set_value(<<"_attachments">>,
{OldAtts1}, Doc),
- Couchapp#couchapp{
+ Couchapp#erlca{
doc=Doc1,
attachments=NewAtts,
signatures=NewSignatures
}
end.
-process_attachments(#couchapp{att_dir=AttDir, doc=Doc,
+process_attachments(#erlca{att_dir=AttDir, doc=Doc,
attachments=Atts}=Couchapp) ->
NewDoc = attach_files(Atts, Doc, AttDir),
- Couchapp#couchapp{doc=NewDoc}.
+ Couchapp#erlca{doc=NewDoc}.
-send_attachments(Db, #couchapp{att_dir=AttDir, doc=Doc,
+send_attachments(Db, #erlca{att_dir=AttDir, doc=Doc,
attachments=Atts}=Couchapp) ->
NewDoc = send_attachments1(Atts, Doc, Db, AttDir),
- Couchapp#couchapp{doc=NewDoc}.
+ Couchapp#erlca{doc=NewDoc}.
make_doc(Couchapp) ->
- #couchapp{
+ #erlca{
path=AppDir,
doc=Doc,
old_doc=OldDoc,
@@ -184,7 +184,7 @@ make_doc(Couchapp) ->
couchbeam_doc:get_rev(OldDoc), Doc)
end,
- %% set manifest an signatures in couchapp object
+ %% set manifest an signatures in erlca object
Doc2 = case couchbeam_doc:get_value(<<"couchapp">>, Doc1) of
undefined ->
couchbeam_doc:set_value(<<"couchapp">>, {[
@@ -197,7 +197,7 @@ make_doc(Couchapp) ->
Signatures, Meta1),
couchbeam_doc:set_value(<<"couchapp">>, FinalMeta, Doc1)
end,
- couchapp_macros:process_macros(Doc2, AppDir).
+ erlca_macros:process_macros(Doc2, AppDir).
clean_old_attachments([],OldAtts) ->
OldAtts;
@@ -237,7 +237,7 @@ send_attachments1([{Fname, _Signature}|Rest], Doc, Db, AttDir) ->
{content_length, FileInfo#file_info.size},
{rev, couchbeam_doc:get_rev(Doc)}
],
- RelPath = couchapp_util:relpath(Fname, AttDir),
+ RelPath = erlca_util:relpath(Fname, AttDir),
{ok, Doc1} = couchbeam:put_attachment(Db, couchbeam_doc:get_id(Doc),
RelPath, Fun, Params),
send_attachments1(Rest, Doc1, Db, AttDir).
@@ -246,26 +246,26 @@ attach_files([], Doc, _AttDir) ->
Doc;
attach_files([{Fname, _Signature}|Rest], Doc, AttDir) ->
{ok, Content} = file:read_file(Fname),
- RelPath = couchapp_util:relpath(Fname, AttDir),
+ RelPath = erlca_util:relpath(Fname, AttDir),
Doc1 = couchbeam_attachments:add_inline(Doc, Content,
encode_path(RelPath)),
attach_files(Rest, Doc1, AttDir).
process_path([], _Dir, Couchapp) ->
{ok, Couchapp};
-process_path([".couchapprc"|Rest], Dir, Couchapp) ->
+process_path([".erlcarc"|Rest], Dir, Couchapp) ->
process_path(Rest, Dir, Couchapp);
-process_path([".couchappignore"|Rest], Dir, Couchapp) ->
+process_path([".erlcaignore"|Rest], Dir, Couchapp) ->
process_path(Rest, Dir, Couchapp);
-process_path([File|Rest], Dir, #couchapp{config=Config, path=Path,
+process_path([File|Rest], Dir, #erlca{config=Config, path=Path,
doc=Doc, manifest=Manifest}=Couchapp) ->
Fname = filename:join(Dir, File),
- case couchapp_ignore:ignore(couchapp_util:relpath(Fname, Path), Config) of
+ case erlca_ignore:ignore(erlca_util:relpath(Fname, Path), Config) of
true ->
process_path(Rest, Dir, Couchapp);
false ->
File1 = list_to_binary(File),
- RelPath = list_to_binary(couchapp_util:relpath(Fname, Path)),
+ RelPath = list_to_binary(erlca_util:relpath(Fname, Path)),
Couchapp1 = case filelib:is_dir(Fname) of
true ->
case File1 of
@@ -281,12 +281,12 @@ process_path([File|Rest], Dir, #couchapp{config=Config, path=Path,
Doc),
Manifest1 = [<<RelPath/binary, "/">>|Manifest]
++ SubManifest,
- Couchapp#couchapp{doc=Doc1, manifest=Manifest1}
+ Couchapp#erlca{doc=Doc1, manifest=Manifest1}
end;
false ->
{PropName, Value} = process_file(File, Fname),
Doc1 = couchbeam_doc:set_value(PropName, Value, Doc),
- Couchapp#couchapp{doc=Doc1, manifest=[RelPath|Manifest]}
+ Couchapp#erlca{doc=Doc1, manifest=[RelPath|Manifest]}
end,
process_path(Rest, Dir, Couchapp1)
@@ -296,13 +296,13 @@ process_dir([], _Dir, _Path, _Config, Doc, Manifest) ->
{Doc, Manifest};
process_dir([File|Rest], Dir, Path, Config, Doc, Manifest) ->
Fname = filename:join(Dir, File),
- case couchapp_ignore:ignore(couchapp_util:relpath(Fname, Path), Config) of
+ case erlca_ignore:ignore(erlca_util:relpath(Fname, Path), Config) of
true ->
process_dir(Rest, Dir, Path, Config, Doc, Manifest);
false ->
File1 = list_to_binary(File),
- RelPath = list_to_binary(couchapp_util:relpath(Fname, Path)),
+ RelPath = list_to_binary(erlca_util:relpath(Fname, Path)),
{Doc1, Manifest1} = case filelib:is_dir(Fname) of
true ->
Files = filelib:wildcard("*", Fname),
@@ -338,17 +338,17 @@ process_file(File, Fname) ->
{list_to_binary(PropName), Value}
end.
-attachments_from_fs(#couchapp{path=Path}=Couchapp) ->
+attachments_from_fs(#erlca{path=Path}=Couchapp) ->
AttPath = filename:join(Path, "_attachments"),
Files = filelib:wildcard("*", AttPath),
Attachments = attachments_from_fs1(Files, AttPath, Couchapp, []),
- Couchapp#couchapp{attachments=Attachments}.
+ Couchapp#erlca{attachments=Attachments}.
attachments_from_fs1([], _Dir, _Couchapp, Att) ->
Att;
-attachments_from_fs1([F|R], Dir, #couchapp{path=Root, config=Conf}=Couchapp, Att) ->
+attachments_from_fs1([F|R], Dir, #erlca{path=Root, config=Conf}=Couchapp, Att) ->
Path = filename:join(Dir, F),
- case couchapp_ignore:ignore(couchapp_util:relpath(Path, Root), Conf) of
+ case erlca_ignore:ignore(erlca_util:relpath(Path, Root), Conf) of
true ->
attachments_from_fs1(R, Dir, Couchapp, Att);
false ->
@@ -358,7 +358,7 @@ attachments_from_fs1([F|R], Dir, #couchapp{path=Root, config=Conf}=Couchapp, Att
SubAtt = attachments_from_fs1(Files, Path, Couchapp, []),
Att ++ SubAtt;
false ->
- {ok, Md5} = couchapp_util:md5_file(Path),
+ {ok, Md5} = erlca_util:md5_file(Path),
Md5Hash = lists:flatten([io_lib:format("~.16b",[N])
|| N <-binary_to_list(Md5)]),
[{Path, list_to_binary(Md5Hash)}|Att]
View
34 src/couchapp_util.erl → src/erlca_util.erl
@@ -1,12 +1,12 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of couchapp released under the Apache 2 license.
+%%% This file is part of erlca released under the Apache 2 license.
%%% See the NOTICE for more information.
--module(couchapp_util).
+-module(erlca_util).
-include("ibrowse.hrl").
--include("couchapp.hrl").
+-include("erlca.hrl").
-define(BLOCKSIZE, 32768).
-define(SEPARATOR, $\/).
@@ -17,13 +17,13 @@
find_executable/1,
normalize_path/1,
user_path/0,
- in_couchapp/1,
+ in_erlca/1,
db_from_string/1,
db_from_config/2,
db_from_key/2,
v2a/1,
relpath/2,
- parse_couchapp_url/1,
+ parse_erlca_url/1,
make_dir/1]).
@@ -67,7 +67,7 @@ db_from_string(DbString) ->
%% @doc fetch a couchbeam database handler by being given a url or
%% a key to lookup the url from the config
db_from_key(Config, Key) ->
- case couchapp_config:get_db(Config, list_to_binary(Key)) of
+ case erlca_config:get_db(Config, list_to_binary(Key)) of
undefined ->
db_from_string(Key);
Doc ->
@@ -79,7 +79,7 @@ db_from_key(Config, Key) ->
db_from_config(Config, DbString) ->
case couchbeam_util:urlsplit(DbString) of
{[], [], _Path, _, _} ->
- case couchapp_config:get_db(Config, DbString) of
+ case erlca_config:get_db(Config, DbString) of
undefined ->
db_from_string(DbString);
Db ->
@@ -89,11 +89,11 @@ db_from_config(Config, DbString) ->
db_from_string(DbString)
end.
-parse_couchapp_url(AppUrl) ->
+parse_erlca_url(AppUrl) ->
Url = ibrowse_lib:parse_url(AppUrl),
PathParts = string:tokens(Url#url.path, "/"),
- case parse_couchapp_path(PathParts) of
+ case parse_erlca_path(PathParts) of
{DbName, AppName, DocId} ->
Server = couchbeam:server_connection(Url#url.host,
Url#url.port),
@@ -114,15 +114,15 @@ parse_couchapp_url(AppUrl) ->
Error
end.
-in_couchapp("/") ->
+in_erlca("/") ->
{error, not_found};
-in_couchapp(Path) ->
- RcPath = filename:join(Path, ".couchapprc"),
+in_erlca(Path) ->
+ RcPath = filename:join(Path, ".erlcarc"),
case filelib:is_regular(RcPath) of
true ->
{ok, Path};
false ->
- in_couchapp(normalize_path(filename:join(Path, "../")))
+ in_erlca(normalize_path(filename:join(Path, "../")))
end.
user_path() ->
@@ -219,12 +219,12 @@ md5_file(File) ->
%% ====================================================================
-parse_couchapp_path([DbName, "_design", AppName|_]) ->
+parse_erlca_path([DbName, "_design", AppName|_]) ->
{DbName, AppName, "_design/" ++ AppName};
-parse_couchapp_path([DbName, DocId]) ->
+parse_erlca_path([DbName, DocId]) ->
{DbName, DocId, DocId};
-parse_couchapp_path(_) ->
- invalid_couchapp_url.
+parse_erlca_path(_) ->
+ invalid_erlca_url.
normalize_path1([], Acc) ->
lists:reverse(Acc);

0 comments on commit e26fa50

Please sign in to comment.
Something went wrong with that request. Please try again.