Permalink
Browse files

Update Medici, serve static files.

  • Loading branch information...
1 parent e3b24e0 commit c53ee94fbe373dc0fc3ad0fa91c07f6420a88d91 Evan Miller committed Sep 30, 2009
View
@@ -1,4 +1,4 @@
-{"src/boss/*", [debug_info, {outdir, "ebin"}, {i, "/usr/local/lib/erlang/lib/xmerl-1.2/include"}]}.
-{"src/medici/*", [debug_info, {outdir, "ebin"}]}.
+{"src/boss/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
+{"src/medici/*", [debug_info, {outdir, "ebin"}, {d, "DEBUG", true}]}.
{"src/erlydtl/*", [debug_info, {outdir, "ebin"}]}.
{"src/mochiweb/*", [debug_info, {outdir, "ebin"}]}.
View
6 README
@@ -5,10 +5,14 @@ Dependencies:
* Erlang R13 -
http://www.erlang.org/download.html
+ Check with erlang:system_info(otp_release).
+
* Tokyo Tyrant -
http://1978th.net/tokyotyrant/
- You need Tyrant up and running with a Table database.
+ ** You need Tyrant up and running with a Table database. **
+
+Build Chicago Boss with "make".
Open up boss.config to set your database info and the port you want to run the
server on. When you're ready to rock and roll, run ./start-dev.sh in this
@@ -19,7 +19,10 @@ stop() ->
mochiweb_http:stop().
mochiweb_request(Req) ->
- Req:respond(process_request(Req)).
+ case Req:get(path) of
+ "/static/"++File -> Req:serve_file(File, "static");
+ _ -> Req:respond(process_request(Req))
+ end.
process_request(Req) ->
Result = case parse_path(Req:get(path)) of
@@ -71,7 +74,7 @@ trap_load_and_execute(Arg1, Arg2) ->
end.
load_and_execute({doc, ModelName}, _Req) ->
- case load_models() of
+ case load_dir(model_path(), fun compile_model/1) of
ok ->
{ModelName, Edoc} = boss_record_compiler:edoc_module(
model_path(atom_to_list(ModelName)++".erl"), [{private, true}]),
@@ -80,9 +83,9 @@ load_and_execute({doc, ModelName}, _Req) ->
Error
end;
load_and_execute({Controller, Action}, Req) ->
- case load_controller(Controller) of
+ case load_dir(controller_path(), fun compile_controller/1) of
ok ->
- case load_models() of
+ case load_dir(model_path(), fun compile_model/1) of
ok ->
execute_action({Controller, Action}, Req);
Else ->
@@ -145,11 +148,11 @@ process_action_result({_, Req, LocationTrail}, {action_other, OtherLocation}) ->
process_action_result(_, Else) ->
Else.
-compile_controller(Module, ModulePath) ->
+compile_controller(ModulePath) ->
CompileResult = compile:file(filename:rootname(ModulePath),
[{outdir, filename:join([root_dir(), "ebin"])}, return_errors]),
case CompileResult of
- {ok, _} ->
+ {ok, Module} ->
code:purge(Module),
{module, Module} = code:load_file(Module),
ok;
@@ -166,40 +169,28 @@ compile_view(Controller, Template) ->
compile_model(ModulePath) ->
boss_record_compiler:compile(ModulePath).
-load_controller(ModuleName) ->
- Module = list_to_atom(lists:concat([ModuleName, "_controller"])),
- case module_older_than(Module, [controller_path(Module)]) of
- true ->
- compile_controller(Module, controller_path(Module));
- _ ->
- ok
- end.
-
-load_models() ->
- {ok, Models} = file:list_dir(model_path()),
- ErrorList = lists:foldl(
- fun(Path, Errors) ->
- case filename:basename(Path, ".erl") of
- "." ++ _ ->
- Errors;
- ModuleName ->
- Module = list_to_atom(ModuleName),
- AbsPath = model_path(Path),
- case module_older_than(Module, [AbsPath]) of
- true ->
- case compile_model(AbsPath) of
- ok ->
- Errors;
- {error, Error} ->
- [Error | Errors];
- {error, NewErrors, _NewWarnings} when is_list(NewErrors) ->
- NewErrors ++ Errors
- end;
- _ ->
- Errors
- end
+load_dir(Dir, Compiler) ->
+ {ok, Files} = file:list_dir(Dir),
+ ErrorList = lists:foldl(fun
+ ("."++_, Errors) ->
+ Errors;
+ (File, Errors) ->
+ Module = list_to_atom(filename:basename(File, ".erl")),
+ AbsPath = filename:join([Dir, File]),
+ case module_older_than(Module, [AbsPath]) of
+ true ->
+ case Compiler(AbsPath) of
+ ok ->
+ Errors;
+ {error, Error} ->
+ [Error | Errors];
+ {error, NewErrors, _NewWarnings} when is_list(NewErrors) ->
+ NewErrors ++ Errors
+ end;
+ _ ->
+ Errors
end
- end, [], Models),
+ end, [], Files),
case length(ErrorList) of
0 ->
ok;
@@ -297,7 +288,6 @@ model_path() -> filename:join([root_dir(), "Model"]).
model_path(Model) -> filename:join([model_path(), Model]).
controller_path() -> filename:join([root_dir(), "Controller"]).
-controller_path(Module) -> filename:join([controller_path(), lists:concat([Module, ".erl"])]).
format_now(Time) ->
{{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(Time),
View
@@ -50,18 +50,18 @@ module_name_from_template(File) ->
list_to_atom("boss_doc_template_"++filename:basename(File, ".html")).
%% @spec get_vars( Template::string() ) -> [{Key::atom(), Value}]
-get_vars("api-view.html", InDir) ->
- {Module, EDoc} = edoc:get_doc("src/erlydtl/erlydtl_filters.erl", []),
+get_vars("api-view.html", _InDir) ->
+ {erlydtl_filters, EDoc} = edoc:get_doc("src/erlydtl/erlydtl_filters.erl", []),
Functions = extract_function_docs(EDoc),
[{filters, Functions}];
get_vars("api-record.html", InDir) ->
- {Module, EDoc} = boss_record_compiler:edoc_module(filename:join([InDir, "trivial_boss_record.erl"]),
+ {boss_record, EDoc} = boss_record_compiler:edoc_module(filename:join([InDir, "trivial_boss_record.erl"]),
[{private, true}, {hidden, true}]),
[{functions, extract_function_docs(EDoc)}];
-get_vars("api-db.html", InDir) ->
- {Module, EDoc} = edoc:get_doc("src/boss/boss_db.erl", []),
+get_vars("api-db.html", _InDir) ->
+ {boss_db, EDoc} = edoc:get_doc("src/boss/boss_db.erl", []),
[{functions, extract_function_docs(EDoc)}];
-get_vars(_, InDir) ->
+get_vars(_, _InDir) ->
[].
extract_function_docs(#xmlElement{name = module, content = Elements}) ->
View
@@ -21,8 +21,7 @@
%%% database.) If you need byte-order specific ops, want to register the
%%% controller with a different name, or want to run medici interfaces
%%% to multiple remote databases within the same erlang VM the you should
-%%% update these or make your own versions to make the appropriate calls
-%%% to the controller.
+%%% update these functions or just run gen_server:call() directly.
%%% @end
-module(medici).
@@ -34,13 +33,14 @@
-export([put/2, putkeep/2, putcat/2, putshl/3, putnr/2, out/1, get/1,
mget/1, vsiz/1, iterinit/0, iternext/0, fwmkeys/2, addint/2,
adddouble/2, adddouble/3, sync/0, vanish/0, rnum/0, size/0,
- stat/0, copy/1, restore/2, setmst/2]).
+ stat/0, copy/1, restore/2, setmst/2, optimize/1]).
%% Table API exports
-export([update/2, setindex/2, genuid/0, query_limit/2, query_limit/3,
query_add_condition/4, query_order/3, search/1, searchcount/1,
searchout/1]).
+-include("medici.hrl").
%% @spec start() -> {ok, Pid} | Error:term()
%%
@@ -67,102 +67,123 @@ start(StartupOptions) when is_list(StartupOptions) ->
stop() ->
application:stop(medici).
+%% NOTE TO THOSE WHO CHANGE THE CONTROLLER NAME:
+%%
+%% The following api calls are just simple wrappers around calls
+%% to gen_server. If you change the controller name in the app
+%% configuration options you will no longer be able to use this
+%% api, but can quite easily acheive the same effect by just using
+%% gen_server:call() directly with your controller name where this
+%% api uses the ?CONTROLLER_NAME macro.
+
put(Key, Value) ->
- gen_server:call(medici, {put, Key, Value}).
+ gen_server:call(?CONTROLLER_NAME, {put, Key, Value}).
putcat(Key, Value) ->
- gen_server:call(medici, {putcat, Key, Value}).
+ gen_server:call(?CONTROLLER_NAME, {putcat, Key, Value}).
putkeep(Key, Value) ->
- gen_server:call(medici, {putkeep, Key, Value}).
+ gen_server:call(?CONTROLLER_NAME, {putkeep, Key, Value}).
putshl(Key, Value, Width) ->
- gen_server:call(medici, {putshl, Key, Value, Width}).
+ gen_server:call(?CONTROLLER_NAME, {putshl, Key, Value, Width}).
putnr(Key, Value) ->
- gen_server:cast(medici, {putnr, Key, Value}).
+ gen_server:cast(?CONTROLLER_NAME, {putnr, Key, Value}).
out(Key) ->
- gen_server:call(medici, {out, Key}).
+ gen_server:call(?CONTROLLER_NAME, {out, Key}).
get(Key) ->
- gen_server:call(medici, {get, Key}).
+ gen_server:call(?CONTROLLER_NAME, {get, Key}).
mget(KeyList) ->
- gen_server:call(medici, {mget, KeyList}).
+ gen_server:call(?CONTROLLER_NAME, {mget, KeyList}).
vsiz(Key) ->
- gen_server:call(medici, {vsiz, Key}).
+ gen_server:call(?CONTROLLER_NAME, {vsiz, Key}).
iterinit() ->
- gen_server:call(medici, {iterinit}).
+ gen_server:call(?CONTROLLER_NAME, {iterinit}).
iternext() ->
- gen_server:call(medici, {iternext}).
+ gen_server:call(?CONTROLLER_NAME, {iternext}).
fwmkeys(Prefix, MaxKeys) ->
- gen_server:call(medici, {fwmkeys, Prefix, MaxKeys}).
+ gen_server:call(?CONTROLLER_NAME, {fwmkeys, Prefix, MaxKeys}).
addint(Key, Int) ->
- gen_server:call(medici, {addint, Key, Int}).
+ gen_server:call(?CONTROLLER_NAME, {addint, Key, Int}).
adddouble(Key, Double) ->
- gen_server:call(medici, {adddouble, Key, Double}).
+ gen_server:call(?CONTROLLER_NAME, {adddouble, Key, Double}).
adddouble(Key, IntPart, FracPart) ->
- gen_server:call(medici, {adddouble, Key, IntPart, FracPart}).
+ gen_server:call(?CONTROLLER_NAME, {adddouble, Key, IntPart, FracPart}).
sync() ->
- gen_server:call(medici, {sync}).
+ gen_server:call(?CONTROLLER_NAME, {sync}).
vanish() ->
- gen_server:call(medici, {vanish}).
+ gen_server:call(?CONTROLLER_NAME, {vanish}).
+
+optimize(TuningOptions) ->
+ gen_server:call(?CONTROLLER_NAME, {optimize, TuningOptions}).
rnum() ->
- gen_server:call(medici, {rnum}).
+ gen_server:call(?CONTROLLER_NAME, {rnum}).
size() ->
- gen_server:call(medici, {size}).
+ gen_server:call(?CONTROLLER_NAME, {size}).
stat() ->
- gen_server:call(medici, {stat}).
+ gen_server:call(?CONTROLLER_NAME, {stat}).
copy(PathName) ->
- gen_server:call(medici, {copy, PathName}).
+ gen_server:call(?CONTROLLER_NAME, {copy, PathName}).
restore(PathName, TimeStamp) ->
- gen_server:call(medici, {restore, PathName, TimeStamp}).
+ gen_server:call(?CONTROLLER_NAME, {restore, PathName, TimeStamp}).
setmst(HostName, Port) ->
- gen_server:call(medici, {setmst, HostName, Port}).
+ gen_server:call(?CONTROLLER_NAME, {setmst, HostName, Port}).
%% Additional table functions
update(Key, NewCols) ->
- gen_server:call(medici, {update, Key, NewCols}).
+ gen_server:call(?CONTROLLER_NAME, {update, Key, NewCols}).
setindex(Column, Type) ->
- gen_server:call(medici, {setindex, Column, Type}).
+ gen_server:call(?CONTROLLER_NAME, {setindex, Column, Type}).
genuid() ->
- gen_server:call(medici, {genuid}).
+ gen_server:call(?CONTROLLER_NAME, {genuid}).
query_limit(OldQuery, Max) ->
- gen_server:call(medici, {query_limit, OldQuery, Max}).
+ gen_server:call(?CONTROLLER_NAME, {query_limit, OldQuery, Max}).
query_limit(OldQuery, Max, Skip) ->
- gen_server:call(medici, {query_limit, OldQuery, Max, Skip}).
+ gen_server:call(?CONTROLLER_NAME, {query_limit, OldQuery, Max, Skip}).
query_add_condition(OldQuery, Column, Op, ExprList) ->
- gen_server:call(medici, {query_add_condition, OldQuery, Column, Op, ExprList}).
+ gen_server:call(?CONTROLLER_NAME, {query_add_condition, OldQuery, Column, Op, ExprList}).
query_order(OldQuery, Column, Type) ->
- gen_server:call(medici, {query_order, OldQuery, Column, Type}).
+ gen_server:call(?CONTROLLER_NAME, {query_order, OldQuery, Column, Type}).
search(Query) ->
- gen_server:call(medici, {search, Query}).
+ gen_server:call(?CONTROLLER_NAME, {search, Query}).
searchcount(Query) ->
- gen_server:call(medici, {searchcount, Query}).
+ gen_server:call(?CONTROLLER_NAME, {searchcount, Query}).
searchout(Query) ->
- gen_server:call(medici, {searchout, Query}).
+ gen_server:call(?CONTROLLER_NAME, {searchout, Query}).
+
+%% EUnit tests
+%%
+-ifdef(EUNIT).
+init_test() ->
+ ?MODULE:start(),
+ ?MODULE:stop(),
+ ok.
+-endif.
Oops, something went wrong.

0 comments on commit c53ee94

Please sign in to comment.