Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use couchbeam_ejson wrapper. fix #27

  • Loading branch information...
commit 7e75f2e13eb9c84c5db43735c2b64dce698ebaae 1 parent 8de52da
@benoitc authored
View
6 bootstrap
@@ -9,7 +9,7 @@ main(Args) ->
%% Add ebin/ to our path
true = code:add_path("ebin"),
true = code:add_path("deps/mochiweb/ebin"),
- true = code:add_path("deps/ejson/ebin"),
+ true = code:add_path("deps/jiffy/ebin"),
true = code:add_path("deps/ibrowse/ebin"),
true = code:add_path("deps/oauth/ebin"),
true = code:add_path("deps/couchbeam/ebin"),
@@ -25,8 +25,8 @@ main(Args) ->
%% works properly.
Files = load_files("*", "ebin")
++ load_files("*", "deps/mochiweb/ebin")
- ++ load_files("*", "deps/ejson/ebin")
- ++ load_files("*", "deps/ejson/priv")
+ ++ load_files("*", "deps/jiffy/ebin")
+ ++ load_files("*", "deps/jiffy/priv")
++ load_files("*", "deps/ibrowse/ebin")
++ load_files("*", "deps/oauth/ebin")
++ load_files("*", "deps/couchbeam/ebin")
View
BIN  rebar
Binary file not shown
View
6 src/erica.app.src
@@ -1,15 +1,15 @@
%%% -*- erlang -*-
%%%
-%%% This file is part of erica released under the Apache 2 license.
+%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.
{application, erica,
[{description, "erica: Couchdb Application Tool"},
- {vsn, "0.2"},
+ {vsn, "0.2.1"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]},
- {included_applications, [crypto, sasl, ibrowse, ejson, couchbeam]},
+ {included_applications, [crypto, sasl, ibrowse, jiffy, couchbeam]},
{env, [
%% default log level
{log_level, error},
View
4 src/erica_clone.erl
@@ -141,7 +141,7 @@ doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
{[_|_]} ->
case proplists:get_value(Path, Manifest) of
".json"=Ext ->
- JsonValue = ejson:encode(Value),
+ JsonValue = couchbeam_ejson:encode(Value),
file:write_file(Path ++ Ext, JsonValue),
doc_to_fs(Rest, Dir, Manifest, Objects, Depth);
_ ->
@@ -172,7 +172,7 @@ doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
file:write_file(Path1, Value1),
doc_to_fs(Rest, Dir, Manifest, Objects, Depth);
_ ->
- JsonValue = ejson:encode(Value),
+ JsonValue = couchbeam_ejson:encode(Value),
Path1 = case proplists:get_value(Path, Manifest) of
undefined ->
View
4 src/erica_config.erl
@@ -24,7 +24,7 @@ new(Options) ->
UserConf = case filelib:is_regular(UserConfFile) of
true ->
{ok, Bin} = file:read_file(UserConfFile),
- ejson:decode(Bin);
+ couchbeam_ejson:decode(Bin);
false ->
{[]}
end,
@@ -46,7 +46,7 @@ update(AppDir, #config{dbs=Dbs, hooks=Hooks, extensions=Extensions,
AppConf = case filelib:is_regular(RcFile) of
true ->
{ok, Bin} = file:read_file(RcFile),
- ejson:decode(Bin);
+ couchbeam_ejson:decode(Bin);
false ->
{[]}
end,
View
2  src/erica_ignore.erl
@@ -41,7 +41,7 @@ load(File) ->
case file:read_file(File) of
{ok, Bin} ->
Bin1 = remove_comments(Bin),
- ejson:decode(Bin1);
+ couchbeam_ejson:decode(Bin1);
Error ->
?ERROR("can't read '~p' [~p]~n", [File, Error]),
[]
View
2  src/erica_init.erl
@@ -24,4 +24,4 @@ init([Path|_], Config) ->
init1(Path, _Config) ->
ok = erica_util:make_dir(Path),
RcPath = filename:join(Path, ".couchapprc"),
- file:write_file(RcPath, ejson:encode({[]})).
+ file:write_file(RcPath, couchbeam_ejson:encode({[]})).
View
4 src/erica_macros.erl
@@ -139,7 +139,7 @@ apply_json_macros1([Match|Rest], Source, Doc, AppDir) ->
Path = filename:join(AppDir, JsonPath1),
Values = obj_from_dir(filelib:wildcard(Path), AttDir, []),
lists:flatten(["var _attachments = ",
- ejson:encode({Values}), ";\n"]);
+ couchbeam_ejson:encode({Values}), ";\n"]);
_ ->
Props = [list_to_binary(P) || P <- string:tokens(binary_to_list(JsonPath),
".")],
@@ -148,7 +148,7 @@ apply_json_macros1([Match|Rest], Source, Doc, AppDir) ->
[VarName|Fields] = Props,
Value1 = nested_value(Fields, Value),
lists:flatten(["var ", VarName, " = ",
- ejson:encode(Value1), ";\n"]);
+ couchbeam_ejson:encode(Value1), ";\n"]);
_Error ->
?ERROR("json macro: can't find ~p~n", [JsonPath]),
""
View
2  src/erica_push.erl
@@ -365,7 +365,7 @@ process_file(File, Fname) ->
{ok, Bin} = file:read_file(Fname),
Value = case Ext of
".json" ->
- ejson:decode(Bin);
+ couchbeam_ejson:decode(Bin);
_ ->
Bin
end,
View
72 src/erica_web.erl
@@ -49,7 +49,7 @@ do_web(Path, Config) ->
%% get port from params, default to autodetect
Port = list_to_integer(erica_config:get_global(port, "0")),
Ip = erica_config:get_global(ip, "127.0.0.1"),
-
+
%% docid of document
DocId = erica_push:id_from_path(Path, Config),
<<"_design/", AppName/binary>> = DocId,
@@ -59,7 +59,7 @@ do_web(Path, Config) ->
apply(?MODULE, dispatch, [Req, Path, Config, DocId,
AppName, StaticFiles, Templates])
end,
-
+
Options = [
{port, Port},
{ip, Ip},
@@ -71,17 +71,17 @@ do_web(Path, Config) ->
port)),
Location = binary_to_list(
iolist_to_binary(["http://127.0.0.1:", PortStr])),
-
+
case erica_config:get_global(browser, "0") of
"0" -> ok;
"false" -> ok;
_ ->
- %% open browser if browser var is 1 or true
+ %% open browser if browser var is 1 or true
erica_webbrowser:open_location(Location)
end,
?CONSOLE("Erica Web started on ~p~n", [Location]),
-
+
receive
http_stop ->
Pid ! stop
@@ -105,7 +105,7 @@ dispatch(MochiReq, AppPath, Config, DocId, AppName, StaticFiles, Templates) ->
config = Config,
static_files = StaticFiles,
templates = Templates},
- try
+ try
handle_request(Req)
catch
_:forbidden ->
@@ -121,7 +121,7 @@ handle_request(#httpd{path_parts=[], app_name=Name, app_dir=Dir}=Req) ->
Tree = [dict:from_list(Props) || Props <- tree(Dir, Dir)],
Actions = render(Req, "tree_actions.html", [{rel_path, ""}]),
- render_template(Req, "index.html",
+ render_template(Req, "index.html",
[{app_name, binary_to_list(Name)},
{actions, Actions},
{tree, Tree}]);
@@ -133,18 +133,18 @@ handle_request(#httpd{path_parts=["push"], app_dir=Dir, config=Config,
'POST' ->
case MochiReq:get_primary_header_value("content-type") of
"application/json" ->
- {Props} = ejson:decode(MochiReq:recv_body()),
+ {Props} = couchbeam_ejson:decode(MochiReq:recv_body()),
DbKey = proplists:get_value(<<"url">>, Props),
Db = erica_util:db_from_key(Config,
binary_to_list(DbKey)),
try erica_push:do_push(Dir, Db, DocId, Config) of
- {ok, DisplayUrl0} ->
+ {ok, DisplayUrl0} ->
DisplayUrl = iolist_to_binary(DisplayUrl0),
JsonObj = {[
{<<"ok">>, true},
{<<"url">>, DisplayUrl}]},
MochiReq:ok({<<"application/json">>, [],
- ejson:encode(JsonObj)})
+ couchbeam_ejson:encode(JsonObj)})
catch
_:Reason ->
?ERROR("web push error: ~p~n", [Reason]),
@@ -153,7 +153,7 @@ handle_request(#httpd{path_parts=["push"], app_dir=Dir, config=Config,
_ ->
json_error(MochiReq, 406, "Content-Type not
accepted")
- end;
+ end;
_ ->
json_error(MochiReq, 405, "only POST is accepted")
end;
@@ -165,16 +165,16 @@ handle_request(#httpd{path_parts=["upload"], app_dir=Dir, mochi_req=MochiReq}) -
Form = mochiweb_multipart:parse_form(MochiReq),
?INFO("got ~p~n", [Form]),
RelPath = proplists:get_value("path", Form),
-
+
{Name, {_ContentType, _}, Bin} = proplists:get_value("file",
Form),
-
+
FName = RelPath ++ "/" ++ Name,
AName = ?UNQUOTE(filename:absname(FName, Dir)),
?DEBUG("Upload file ~p~n", [AName]),
ok = check_path(AName, Dir),
case filelib:ensure_dir(AName) of
- ok ->
+ ok ->
ok;
_ ->
DirName = filename:dirname(AName),
@@ -188,7 +188,7 @@ handle_request(#httpd{path_parts=["upload"], app_dir=Dir, mochi_req=MochiReq}) -
_ ->
ok = file:write_file(AName, Bin)
end,
-
+
json_ok(MochiReq);
_ ->
json_error(MochiReq, 405, "only POST is accepted")
@@ -199,7 +199,7 @@ handle_request(#httpd{path_parts=["create"], app_dir=Dir, mochi_req=MochiReq}) -
'POST' ->
case MochiReq:get_primary_header_value("content-type") of
"application/json" ->
- {Props0} = ejson:decode(MochiReq:recv_body()),
+ {Props0} = couchbeam_ejson:decode(MochiReq:recv_body()),
Actions = proplists:get_value(<<"actions">>, Props0),
?DEBUG("actions ~p~n", [Actions]),
@@ -221,7 +221,7 @@ handle_request(#httpd{path_parts=["create"], app_dir=Dir, mochi_req=MochiReq}) -
ok = check_path(AName, Dir),
case filelib:ensure_dir(AName) of
- ok ->
+ ok ->
ok;
_ ->
DirName = filename:dirname(AName),
@@ -245,7 +245,7 @@ handle_request(#httpd{path_parts=["create"], app_dir=Dir, mochi_req=MochiReq}) -
_ ->
json_error(MochiReq, 406, "Content-Type not
accepted")
- end;
+ end;
_ ->
json_error(MochiReq, 405, "only POST is accepted")
end;
@@ -255,7 +255,7 @@ handle_request(#httpd{path_parts=["delete"], app_dir=Dir, mochi_req=MochiReq}) -
'POST' ->
case MochiReq:get_primary_header_value("content-type") of
"application/json" ->
- {Props} = ejson:decode(MochiReq:recv_body()),
+ {Props} = couchbeam_ejson:decode(MochiReq:recv_body()),
Files = proplists:get_value(<<"files">>, Props),
lists:foreach(fun(File) ->
FName =
@@ -271,7 +271,7 @@ handle_request(#httpd{path_parts=["delete"], app_dir=Dir, mochi_req=MochiReq}) -
_ ->
json_error(MochiReq, 406, "Content-Type not
accepted")
- end;
+ end;
_ ->
json_error(MochiReq, 405, "only POST is accepted")
end;
@@ -300,7 +300,7 @@ handle_request(#httpd{path_parts=["tree"|PathParts], app_name=Name,
false ->
[FileName|Rest] = lists:reverse(PathParts),
BreadCrumb = breadcrumb(lists:reverse(Rest)),
-
+
Ext = filename:extension(FName),
{ok, #file_info{size=S, mode=M}} = file:read_file_info(FName),
@@ -315,7 +315,7 @@ handle_request(#httpd{path_parts=["tree"|PathParts], app_name=Name,
{size, S},
{mode, M}]),
[{content, Content}];
-
+
false ->
{ok, Bin0} = file:read_file(FName),
Bin = mochiweb_html:escape(Bin0),
@@ -340,7 +340,7 @@ handle_request(#httpd{path_parts=["tree"|PathParts], app_name=Name,
render_template(Req, Tmpl, Ctx);
-handle_request(#httpd{method='GET', path_parts=["edit"|PathParts],
+handle_request(#httpd{method='GET', path_parts=["edit"|PathParts],
app_name=Name, app_dir=Dir, mochi_req=MochiReq, path=Path}=Req) ->
FName = ?UNQUOTE(filename:join([Dir|PathParts])),
@@ -369,7 +369,7 @@ handle_request(#httpd{method='GET', path_parts=["edit"|PathParts],
{breadcrumb, BreadCrumb}])
end;
-handle_request(#httpd{method='POST', path_parts=["edit"|PathParts],
+handle_request(#httpd{method='POST', path_parts=["edit"|PathParts],
app_dir=Dir, mochi_req=MochiReq}) ->
FName = ?UNQUOTE(filename:join([Dir|PathParts])),
@@ -382,7 +382,7 @@ handle_request(#httpd{method='POST', path_parts=["edit"|PathParts],
ReqBody = MochiReq:recv_body(),
case MochiReq:get_primary_header_value("content-type") of
"application/json" ->
- {Props} = ejson:decode(ReqBody),
+ {Props} = couchbeam_ejson:decode(ReqBody),
Data = proplists:get_value(<<"data">>,
Props, ""),
@@ -416,8 +416,8 @@ json_respond(MochiReq, Status, JsonObj) ->
json_respond(MochiReq, Status, ExtraHeaders, JsonObj) ->
Headers = [{"Content-Type", "application/json"}] ++ ExtraHeaders,
- MochiReq:respond({Status, Headers, ejson:encode(JsonObj)}).
-
+ MochiReq:respond({Status, Headers, couchbeam_ejson:encode(JsonObj)}).
+
json_error(MochiReq, Status, Error) when is_list(Error) ->
json_error(MochiReq, Status, list_to_binary(Error));
@@ -433,7 +433,7 @@ json_ok(MochiReq) ->
json_ok(MochiReq, Extra) ->
JsonProps = [{<<"ok">>, true}] ++ Extra,
MochiReq:ok({<<"application/json">>, [],
- ejson:encode({JsonProps})}).
+ couchbeam_ejson:encode({JsonProps})}).
host_headers(MochiReq) ->
[ V || V <- [MochiReq:get_header_value(H)
@@ -464,15 +464,15 @@ render(#httpd{templates=Templates},Name, Ctx0) ->
%% inneficient method to remove trailing new line.
case lists:reverse(Rendered) of
- [$\n|Rendered1] ->
+ [$\n|Rendered1] ->
lists:reverse(Rendered1);
- _ ->
+ _ ->
Rendered
end;
_ ->
""
end.
-
+
render_template(Req, Name, Ctx0) ->
Ctx = dict:from_list(Ctx0),
@@ -488,9 +488,9 @@ render_template(Req, Name, Ctx0) ->
%% inneficient method to remove trailing new line.
Bin1 = case lists:reverse(Rendered) of
- [$\n|Rendered1] ->
+ [$\n|Rendered1] ->
lists:reverse(Rendered1);
- _ ->
+ _ ->
Rendered
end,
ContentType = mochiweb_util:guess_mime(Name),
@@ -583,8 +583,8 @@ breadcrumb(PathParts) ->
Active = if length(Paths) =:= length(PathParts) -> "active";
true -> ""
end,
-
- Prop = [{href, fix_evently(Href1)},
+
+ Prop = [{href, fix_evently(Href1)},
{name, Path},
{active, Active}],
{Href1, [dict:from_list(Prop)|Paths]}
@@ -637,7 +637,7 @@ check_path(Path, CouchappDir) ->
S = size(CouchappDir),
case Path1 of
<<CouchappDir:S/binary, _/binary>> ->
-
+
ok;
_ ->
throw({forbidden, Path1})
Please sign in to comment.
Something went wrong with that request. Please try again.