PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/modules/mod_base/filters/filter_member.erl

https://code.google.com/p/zotonic/
Erlang | 41 lines | 19 code | 6 blank | 16 comment | 0 complexity | 9662c85fd17fda12fb92b19ee058cb87 MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2010 Marc Worrell
 3%% @doc 'member' filter, test if an element is part of a list
 4
 5%% Copyright 2010 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
19-module(filter_member).
20-export([member/3]).
21
22
23member(_S, undefined, _Context) ->
24    false;
25member(S, [H|_] = L, _Context) when is_list(S) andalso is_binary(H) ->
26    lists:member(list_to_binary(S), L);
27member(S, [H|_] = L, _Context) when is_list(S) andalso is_integer(H) ->
28    try
29        lists:member(list_to_integer(S), L)
30    catch
31        _:_ -> false
32    end;
33member(S, L, _Context) when is_list(L) ->
34    lists:member(S, L);
35member(S, Value, Context) ->
36	case erlydtl_runtime:to_list(Value, Context) of
37		L when is_list(L) -> member(S, L, Context);
38		_ -> undefined
39	end.
40
41