PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/models/m_session.erl

https://code.google.com/p/zotonic/
Erlang | 51 lines | 17 code | 9 blank | 25 comment | 0 complexity | d82a0cac8ddf5012431b20f510ada439 MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2009 Marc Worrell
 3%% Date: 2009-11-20
 4%%
 5%% @doc Model for accessing the session variables from a template.
 6
 7%% Copyright 2009 Marc Worrell
 8%%
 9%% Licensed under the Apache License, Version 2.0 (the "License");
10%% you may not use this file except in compliance with the License.
11%% You may obtain a copy of the License at
12%% 
13%%     http://www.apache.org/licenses/LICENSE-2.0
14%% 
15%% Unless required by applicable law or agreed to in writing, software
16%% distributed under the License is distributed on an "AS IS" BASIS,
17%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18%% See the License for the specific language governing permissions and
19%% limitations under the License.
20
21-module(m_session).
22-author("Marc Worrell <marc@worrell.nl").
23
24-behaviour(gen_model).
25
26%% interface functions
27-export([
28    m_find_value/3,
29    m_to_list/2,
30    m_value/2
31]).
32
33-include_lib("zotonic.hrl").
34
35%% @doc Fetch the value for the key from a model source
36%% @spec m_find_value(Key, Source, Context) -> term()
37m_find_value(session_id, #m{value=undefined}, Context) ->
38    z_context:get(session_id, Context);
39m_find_value(Key, #m{value=undefined}, Context) ->
40    z_context:get_session(Key, Context).
41
42%% @doc Transform a m_config value to a list, used for template loops
43%% @spec m_to_list(Source, Context) -> List
44m_to_list(#m{value=undefined}, _Context) ->
45	[].
46
47%% @doc Transform a model value so that it can be formatted or piped through filters
48%% @spec m_value(Source, Context) -> term()
49m_value(#m{value=undefined}, _Context) ->
50	undefined.
51