/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
- %% @author Marc Worrell <marc@worrell.nl>
- %% @copyright 2009 Marc Worrell
- %% Date: 2009-11-20
- %%
- %% @doc Model for accessing the session variables from a template.
- %% Copyright 2009 Marc Worrell
- %%
- %% Licensed under the Apache License, Version 2.0 (the "License");
- %% you may not use this file except in compliance with the License.
- %% You may obtain a copy of the License at
- %%
- %% http://www.apache.org/licenses/LICENSE-2.0
- %%
- %% Unless required by applicable law or agreed to in writing, software
- %% distributed under the License is distributed on an "AS IS" BASIS,
- %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- %% See the License for the specific language governing permissions and
- %% limitations under the License.
- -module(m_session).
- -author("Marc Worrell <marc@worrell.nl").
- -behaviour(gen_model).
- %% interface functions
- -export([
- m_find_value/3,
- m_to_list/2,
- m_value/2
- ]).
- -include_lib("zotonic.hrl").
- %% @doc Fetch the value for the key from a model source
- %% @spec m_find_value(Key, Source, Context) -> term()
- m_find_value(session_id, #m{value=undefined}, Context) ->
- z_context:get(session_id, Context);
- m_find_value(Key, #m{value=undefined}, Context) ->
- z_context:get_session(Key, Context).
- %% @doc Transform a m_config value to a list, used for template loops
- %% @spec m_to_list(Source, Context) -> List
- m_to_list(#m{value=undefined}, _Context) ->
- [].
- %% @doc Transform a model value so that it can be formatted or piped through filters
- %% @spec m_value(Source, Context) -> term()
- m_value(#m{value=undefined}, _Context) ->
- undefined.