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