Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed some old static/html functions

  • Loading branch information...
commit cb58744694a0ce742b453ae1d5666b64630bc69b 1 parent 3678f39
@tsloughter authored
View
6 lib/maru_models/src/maru_model_sessions.erl
@@ -44,10 +44,10 @@ delete(Key) ->
-spec is_valid(list()) -> true | false.
is_valid(SessionID) ->
case find({id, SessionID}) of
- not_found ->
- false;
[Session] ->
- not(expired(Session))
+ not(expired(Session));
+ _ ->
+ false
end.
%%%===================================================================
View
1  lib/maru_web/ebin/maru_web.app
@@ -8,7 +8,6 @@
maru_web_sup,
maru_web_utils,
- maru_web_static,
maru_web_base,
maru_web_sessions,
View
2  lib/maru_web/include/maru_web.hrl
@@ -1,2 +1,2 @@
--record(ctx, {session_id, user_id, docroot, fullpath, fileinfo, response_body, model}).
+-record(ctx, {session_id, user_id, fullpath, fileinfo, response_body, model}).
View
8 lib/maru_web/src/maru_resource_user.erl
@@ -16,7 +16,6 @@
resource_exists/2,
process_post/2,
to_json/2,
- to_html/2,
from_json/2]).
-include_lib("webmachine/include/webmachine.hrl").
@@ -29,9 +28,7 @@
%%%===================================================================
-spec init(term()) -> {ok, record(ctx)}.
init(_) ->
- {ok, {priv, App}} = application:get_env(host_dir),
- HostDir = filename:join(code:priv_dir(App), "user"),
- {ok, #ctx{model=?MODEL, docroot=HostDir}}.
+ {ok, #ctx{model=?MODEL}}.
content_types_provided(ReqData, Ctx) ->
maru_web_base:content_types_provided(ReqData, Ctx).
@@ -70,9 +67,6 @@ to_json(ReqData, Ctx) ->
end
end.
-to_html(ReqData, Ctx) ->
- maru_web_base:to_html(ReqData, Ctx).
-
from_json(ReqData, Ctx) ->
maru_web_base:from_json(ReqData, Ctx).
View
39 lib/maru_web/src/maru_web_static.erl
@@ -1,39 +0,0 @@
--module(maru_web_static).
-
--export([init/1,
- allowed_methods/2,
- resource_exists/2,
- content_types_provided/2,
- provide_content/2]).
-
--include_lib("maru_web/include/maru_web.hrl").
-
--include_lib("webmachine/include/webmachine.hrl").
--include_lib("kernel/include/file.hrl").
-
-init([]) ->
- {ok, {priv, App}} = application:get_env(host_dir),
- HostDir = code:priv_dir(App),
- {ok, #ctx{docroot=HostDir}}.
-
-allowed_methods(ReqData, Ctx) ->
- {['HEAD', 'GET'], ReqData, Ctx}.
-
-resource_exists(ReqData, Ctx) ->
- {true, ReqData, Ctx}.
-
-content_types_provided(ReqData, Ctx) ->
- Path = maru_web_utils:get_full_path(Ctx, wrq:disp_path(ReqData)),
- {[{webmachine_util:guess_mime(Path), provide_content}], ReqData, Ctx}.
-
-provide_content(ReqData, Ctx) ->
- %NewReqData = wrq:set_resp_header("X-Accel-Redirect", "/files/test.html", ReqData),
- %{"", NewReqData, Ctx}.
-
- case maru_web_utils:maybe_fetch_object(Ctx, wrq:disp_path(ReqData)) of
- {true, NewCtx} ->
- Body = NewCtx#ctx.response_body,
- {Body, ReqData, Ctx};
- {false, NewCtx} ->
- {error, ReqData, NewCtx}
- end.
View
74 lib/maru_web/src/maru_web_utils.erl
@@ -12,12 +12,7 @@
-include_lib("kernel/include/file.hrl").
%% API
--export([checkbox_value_to_bool/1,
- return_file/3,
- maybe_fetch_object/3,
- maybe_fetch_object/2,
- file_exists/2,
- get_full_path/2]).
+-export([checkbox_value_to_bool/1]).
%%%===================================================================
%%% API
@@ -30,73 +25,6 @@ checkbox_value_to_bool("on") ->
checkbox_value_to_bool("off") ->
false.
-return_file(Filename, ReqData, Ctx) ->
- case maru_web_utils:maybe_fetch_object(Ctx, Filename) of
- {true, NewCtx} ->
- Body = NewCtx#ctx.response_body,
- {Body, ReqData, NewCtx};
- {false, NewCtx} ->
- {error, ReqData, NewCtx}
- end.
-
-
-maybe_fetch_object(Ctx, Template, Path) ->
- % if returns {true, NewCtx} then NewCtx has response_body
- case Ctx#ctx.response_body of
- undefined ->
- case file_exists(Ctx, Path) of
- {true, FullPath} ->
- Value = render_content(Template, FullPath),
- {true, Ctx#ctx{response_body=Value}};
- false ->
- {false, Ctx}
- end;
- _Body ->
- {true, Ctx}
- end.
-
-maybe_fetch_object(Ctx, Path) ->
- % if returns {true, NewCtx} then NewCtx has response_body
- case Ctx#ctx.response_body of
- undefined ->
- case file_exists(Ctx, Path) of
- {true, FullPath} ->
- {ok, Value} = file:read_file(FullPath),
- {true, Ctx#ctx{response_body=Value}};
- false ->
- {false, Ctx}
- end;
- _Body ->
- {true, Ctx}
- end.
-
-file_exists(Ctx, Path) ->
- FPath = get_full_path(Ctx, Path),
- case filelib:is_regular(filename:absname(FPath)) of
- true ->
- {true, FPath};
- false ->
- false
- end.
-
-get_full_path(Ctx, Path) ->
- Root = Ctx#ctx.docroot,
- case mochiweb_util:safe_relative_path(Path) of
- undefined -> undefined;
- RelPath ->
- FullPath = filename:join([Root, RelPath]),
- case filelib:is_dir(FullPath) of
- true ->
- filename:join([FullPath, "index.html"]);
- false ->
- FullPath
- end
- end.
-
%%%===================================================================
%%% Internal functions
%%%===================================================================
-
-render_content(Base, FullPath) ->
- {ok, Content} = file:read_file(FullPath),
- sgte:render(Base, [{content, Content}]).
Please sign in to comment.
Something went wrong with that request. Please try again.