PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/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
14%% Copyright 2009 Marc Worrell
15%%
16%% Licensed under the Apache License, Version 2.0 (the "License");
17%% you may not use this file except in compliance with the License.
18%% You may obtain a copy of the License at
19%% 
20%%     http://www.apache.org/licenses/LICENSE-2.0
21%% 
22%% Unless required by applicable law or agreed to in writing, software
23%% distributed under the License is distributed on an "AS IS" BASIS,
24%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25%% See the License for the specific language governing permissions and
26%% limitations under the License.
27
28-export([init/1, to_html/2, service_available/2, charsets_provided/2]).
29
30-include_lib("webmachine_resource.hrl").
31-include_lib("include/zotonic.hrl").
32
33init(DispatchArgs) -> 
34    {ok, DispatchArgs}.
35
36service_available(ReqData, DispatchArgs) when is_list(DispatchArgs) ->
37    Context  = z_context:new(ReqData, ?MODULE),
38    Context1 = z_context:set(DispatchArgs, Context),
39    ?WM_REPLY(true, Context1).
40
41charsets_provided(ReqData, Context) ->
42    {[{"utf-8", fun(X) -> X end}], ReqData, Context}.
43
44to_html(ReqData, Context) ->
45    Context1 = ?WM_REQ(ReqData, Context),
46    Context2 = z_context:ensure_all(Context1),
47    {Result, ResultContext} = html(Context2),
48    ?WM_REPLY(Result, ResultContext).