PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/src/support/z_path.erl

https://code.google.com/p/zotonic/
Erlang | 58 lines | 22 code | 9 blank | 27 comment | 0 complexity | c854b6c6bdb6437d9868ef85509e31f2 MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2009 Marc Worrell
 3%% Date: 2009-08-05
 4%% @doc Defines all paths for files and directories of a site.
 5
 6%% Copyright 2009 Marc Worrell
 7%%
 8%% Licensed under the Apache License, Version 2.0 (the "License");
 9%% you may not use this file except in compliance with the License.
10%% You may obtain a copy of the License at
11%% 
12%%     http://www.apache.org/licenses/LICENSE-2.0
13%% 
14%% Unless required by applicable law or agreed to in writing, software
15%% distributed under the License is distributed on an "AS IS" BASIS,
16%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17%% See the License for the specific language governing permissions and
18%% limitations under the License.
19
20-module(z_path).
21-author("Marc Worrell <marc@worrell.nl").
22
23-export([
24    site_dir/1,
25    media_preview/1,
26    media_archive/1,
27    files_subdir/2,
28    files_subdir_ensure/2
29]).
30
31-include("zotonic.hrl").
32
33%% @doc Return the path to the site folder of the given context.
34%% @spec site_dir(#context{}) -> filename()
35site_dir(#context{host=Host}) ->
36        filename:join([z_utils:lib_dir(priv), "sites", Host]).
37
38%% @doc Return the path to the media preview directory
39%% @spec media_preview(#context{}) -> filename()
40media_preview(Context) ->
41    files_subdir("preview", Context).
42
43%% @doc Return the path to the media archive directory
44%% @spec media_archive(#context{}) -> filename()
45media_archive(Context) ->
46    files_subdir("archive", Context).
47
48%% @doc Return the path to a files subdirectory
49%% @spec files_subdir(SubDir::filename(), #context{}) -> filename()
50files_subdir(SubDir, #context{host=Host}) ->
51        filename:join([z_utils:lib_dir(priv), "sites", Host, "files", z_convert:to_list(SubDir)]).
52
53%% @doc Return the path to a files subdirectory and ensure that the directory is present
54%% @spec files_subdir_ensure(SubDir::filename(), #context{}) -> filename()
55files_subdir_ensure(SubDir, Context) ->
56    Dir = files_subdir(SubDir, Context),
57    ok = filelib:ensure_dir(filename:join([Dir, ".empty"])),
58    Dir.