1 fsharp comment (***************************************************************************
3 fsharp comment * The Parser is free software: you can redistribute it and/or modify
4 fsharp comment * it under the terms of the GNU Lesser General Public License as published by
5 fsharp comment * the Free Software Foundation, either version 3 of the License, or
6 fsharp comment * (at your option) any later version.
8 fsharp comment ***************************************************************************)
10 fsharp code namespace Tags
12 fsharp code open System
13 fsharp code open System.Reflection;
14 fsharp code open System.Runtime.CompilerServices;
15 fsharp code open System.Runtime.InteropServices;
17 fsharp code module internal Filter =
19 fsharp code let FILTER_VARIABLE_NAME = "$filter"
21 fsharp code type FilterNode(provider, token, filter: FilterExpression, node_list) =
22 fsharp code inherit TagNode(provider, token)
24 fsharp code override this.walk manager walker =
25 fsharp code let reader =
26 fsharp code new NDjango.ASTWalker.Reader (manager, {walker with parent=None; nodes=node_list; context=walker.context})
27 fsharp code match filter.ResolveForOutput manager
28 fsharp code {walker with context=walker.context.add(FILTER_VARIABLE_NAME, (reader.ReadToEnd():>obj))}
30 fsharp code | Some w -> w
31 fsharp code | None -> walker
33 fsharp comment /// Filters the contents of the block through variable filters.
35 fsharp comment /// Filters can also be piped through each other, and they can have
36 fsharp comment /// arguments -- just like in variable syntax.
38 fsharp comment /// Sample usage::
40 fsharp comment /// {% filter force_escape|lower %}
41 fsharp comment /// This text will be HTML-escaped, and will appear in lowercase.
42 fsharp comment /// {% endfilter %}
43 fsharp code type FilterTag() =
44 fsharp code interface ITag with
45 fsharp code member this.Perform token provider tokens =
46 fsharp code match token.Args with
47 fsharp code | filter::[] ->
48 fsharp code let filter_expr = new FilterExpression(provider, Block token, FILTER_VARIABLE_NAME + "|" + filter)
49 fsharp code let node_list, remaining = (provider :?> IParser).Parse (Some token) tokens ["endfilter"]
50 fsharp code (new FilterNode(provider, token, filter_expr, node_list) :> INodeImpl), remaining
51 fsharp code | _ -> raise (SyntaxError ("'filter' tag requires one argument"))