Skip to content
This repository
Browse code

more custom tags cleanup

  • Loading branch information...
commit 8587b90fd7570969ae405ffa977c4ae11f0eb226 1 parent ec2ad17
Paul Armstrong authored September 24, 2011

Showing 1 changed file with 4 additions and 15 deletions. Show diff stats Hide diff stats

  1. 19  docs/custom-tags.md
19  docs/custom-tags.md
Source Rendered
@@ -6,16 +6,6 @@ First, make sure to include your node.js file that declares your tags in the swi
6 6
 
7 7
     swig.init({ tags: require('mytags') });
8 8
 
9  
-Each tag will be executed with its scope bound to the tag token object. A token for a tag will look like this:
10  
-
11  
-    // Assume your template has {% mytag foo bar %}{% endmytag %}
12  
-    var token = {
13  
-        type: LOGIC_TOKEN,      // Used internally by the parser. It will always be the same, no matter what tag.
14  
-        name: 'mytag',
15  
-        args: ['foo', 'bar'],
16  
-        compile: tag_function
17  
-    };
18  
-
19 9
 ## Requirements
20 10
 
21 11
 First, include the Swig parser and helpers.
@@ -30,7 +20,7 @@ Define your tag and whether or not it requires an "end" tag:
30 20
     };
31 21
     exports.mytag.ends = true;
32 22
 
33  
-## Something Really Simple
  23
+## A Really Simple Tag
34 24
 
35 25
 To parse a swig variable with or without filters into a variable token, eg. `bar` or `foo|lowercase`
36 26
 
@@ -40,7 +30,7 @@ To parse a swig variable with or without filters into a variable token, eg. `bar
40 30
     };
41 31
     exports.mytag.ends = true;
42 32
 
43  
-Use a parsed variable token with `helpers.setVar()` to bind a variable in your current scope into the templates scope:
  33
+Use a parsed variable token with `helpers.setVar()` to bind a variable in your current scope into the templates scope. The `setVar` method cleans up variable output, applies filters and escaping for clean output:
44 34
 
45 35
     exports.mytag = function (indent) {
46 36
         var myArg = parser.parseVariable(this.args[0]),
@@ -50,7 +40,7 @@ Use a parsed variable token with `helpers.setVar()` to bind a variable in your c
50 40
     };
51 41
     exports.mytag.ends = true;
52 42
 
53  
-To parse the inner content of a tag for outputting:
  43
+To parse the inner content of a tag for outputting, use `parser.compile.call(this, indent)`:
54 44
 
55 45
     exports.mytag = function (indent) {
56 46
         var myArg = parser.parseVariable(this.args[0]),
@@ -65,7 +55,6 @@ To parse the inner content of a tag for outputting:
65 55
         output.push(parser.compile.call(this, indent + '    '));
66 56
         output.push('</p>');
67 57
 
68  
-
69 58
         return output.join('\n' + indent);
70 59
     };
71 60
     exports.mytag.ends = true;
@@ -83,4 +72,4 @@ Output:
83 72
 
84 73
 ## Write Your Own
85 74
 
86  
-To best understand how to write your own tag, reference `swig/lib/tags.js` to see how the internal tags are written. These will give you a pretty clear indication of how to write your own.
  75
+To best understand how to write your own tag, reference [`swig/lib/tags.js`](../lib/tags.js) to see how the internal tags are written. These will give you a pretty clear indication of how to write your own.

0 notes on commit 8587b90

Please sign in to comment.
Something went wrong with that request. Please try again.