/include/resource_html.hrl

https://code.google.com/p/zotonic/ · Erlang · 48 lines · 16 code · 7 blank · 25 comment · 0 complexity · 019c592e62c5ab2076b10da8115825bb MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% @doc Empty HTML resource, defining the basic callbacks needed for a html page. All is needed is the 'html' function.
  4. %% Make a new resource (resource_plop.erl) by:
  5. %%
  6. %% -module(resource_plop).
  7. %% -author("Your Name <me@example.com>").
  8. %% -include_lib("resource_html.hrl").
  9. %%
  10. %% html(Context) ->
  11. %% Html = z_template:render("plop.tpl", Context),
  12. %% z_context:output(Html, Context).
  13. %% Copyright 2009 Marc Worrell
  14. %%
  15. %% Licensed under the Apache License, Version 2.0 (the "License");
  16. %% you may not use this file except in compliance with the License.
  17. %% You may obtain a copy of the License at
  18. %%
  19. %% http://www.apache.org/licenses/LICENSE-2.0
  20. %%
  21. %% Unless required by applicable law or agreed to in writing, software
  22. %% distributed under the License is distributed on an "AS IS" BASIS,
  23. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. %% See the License for the specific language governing permissions and
  25. %% limitations under the License.
  26. -export([init/1, to_html/2, service_available/2, charsets_provided/2]).
  27. -include_lib("webmachine_resource.hrl").
  28. -include_lib("include/zotonic.hrl").
  29. init(DispatchArgs) ->
  30. {ok, DispatchArgs}.
  31. service_available(ReqData, DispatchArgs) when is_list(DispatchArgs) ->
  32. Context = z_context:new(ReqData, ?MODULE),
  33. Context1 = z_context:set(DispatchArgs, Context),
  34. ?WM_REPLY(true, Context1).
  35. charsets_provided(ReqData, Context) ->
  36. {[{"utf-8", fun(X) -> X end}], ReqData, Context}.
  37. to_html(ReqData, Context) ->
  38. Context1 = ?WM_REQ(ReqData, Context),
  39. Context2 = z_context:ensure_all(Context1),
  40. {Result, ResultContext} = html(Context2),
  41. ?WM_REPLY(Result, ResultContext).