File: fs1.fs

package info (click to toggle)
ohcount 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,712 kB
  • ctags: 3,205
  • sloc: ansic: 6,524; ruby: 2,560; perl: 2,041; erlang: 350; lisp: 272; sh: 244; pascal: 196; vhdl: 150; haskell: 149; asm: 128; cs: 124; awk: 98; java: 92; php: 73; tcl: 58; xml: 57; fortran: 54; makefile: 32; python: 31; ada: 30; objc: 30; jsp: 28; sql: 18; cobol: 13; ml: 9; cpp: 3
file content (51 lines) | stat: -rw-r--r-- 2,154 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(***************************************************************************
 * 
 *  The Parser is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 ***************************************************************************)

namespace Tags

open System
open System.Reflection;
open System.Runtime.CompilerServices;
open System.Runtime.InteropServices;

module internal Filter =

    let FILTER_VARIABLE_NAME = "$filter"

    type FilterNode(provider, token, filter: FilterExpression, node_list) =
        inherit TagNode(provider, token)

        override this.walk manager walker = 
            let reader = 
                new NDjango.ASTWalker.Reader (manager, {walker with parent=None; nodes=node_list; context=walker.context}) 
            match filter.ResolveForOutput manager
                     {walker with context=walker.context.add(FILTER_VARIABLE_NAME, (reader.ReadToEnd():>obj))}
                with
            | Some w -> w
            | None -> walker

    /// Filters the contents of the block through variable filters.
    /// 
    /// Filters can also be piped through each other, and they can have
    /// arguments -- just like in variable syntax.
    /// 
    /// Sample usage::
    /// 
    ///     {% filter force_escape|lower %}
    ///         This text will be HTML-escaped, and will appear in lowercase.
    ///     {% endfilter %}
    type FilterTag() =
        interface ITag with
            member this.Perform token provider tokens =
                match token.Args with
                | filter::[] ->
                    let filter_expr = new FilterExpression(provider, Block token, FILTER_VARIABLE_NAME + "|" + filter)
                    let node_list, remaining = (provider :?> IParser).Parse (Some token) tokens ["endfilter"]
                    (new FilterNode(provider, token, filter_expr, node_list) :> INodeImpl), remaining
                | _ -> raise (SyntaxError ("'filter' tag requires one argument"))