1/**
2 * !class TextTemplate
3 * !declaration class TextTemplate extends Template
4 * !brief Provides a basic text output for feritedoc
5 * !extends Template
6 */
7class TextTemplate extends Template
8{
9   /**
10    * !function TextTemplate
11    * !brief The constructor
12    * !declaration function TextTemplate( string args )
13    * !param string args The arguements to be passed to the template
14    */
15   function constructor( string args )
16   {
17       super( "Text Template", args );
18//       .print( "We are alive!" );
19   }
20
21   function processClass( object klass )
22   {
23       number i = 0;
24
25       Console.println( "+-----------------------------------------------------" );
26       if( klass.mods == "" )
27       {
28           Console.println( "| class ${klass.name}" );
29           Console.println( "| extends ${klass.exts}" );
30       }
31       else
32         Console.println( "| class modifies ${klass.mods}" );
33       Console.println( "+-----------------------------------------------------" );
34       .processAll( klass );
35
36       for( i = 0; i < Array.size(klass.items); i++ )
37       {
38           if( klass.items[i] instanceof DocFunction )
39             .processFunction( klass.items[i] );
40           if( klass.items[i] instanceof DocVariable )
41             .processVariable( klass.items[i] );
42       }
43       Console.println( "+-----------------------------------------------------" );
44   }
45
46   function processNamespace( object space )
47   {
48       number i = 0;
49
50       Console.println( "+-----------------------------------------------------" );
51       if( space.mods == "" )
52         Console.println( "| namespace ${space.name}" );
53       else
54         Console.println( "| namespace modifies ${space.mods}");
55       Console.println( "+-----------------------------------------------------" );
56       .processAll( space );
57       for( i = 0; i < Array.size(space.items); i++ )
58       {
59           if( space.items[i] instanceof DocFunction )
60             .processFunction( space.items[i] );
61           else if( space.items[i] instanceof DocVariable )
62             .processVariable( space.items[i] );
63	   else if( space.items[i] instanceof DocClass )
64	     .processClass( space.items[i] );
65           else if( space.items[i] instanceof DocNamespace )
66               .processNamespace( space.items[i] );
67       }
68       Console.println( "+-----------------------------------------------------" );
69   }
70
71   function processFunction( object func )
72   {
73       number i = 0;
74       string type, name, meaning;
75
76       Console.println( "+-----------------------------------------------------" );
77       Console.println( "| function ${func.name}" );
78       Console.println( "+-----------------------------------------------------" );
79
80       if( Array.size(func.parameters) > 0 )
81       {
82           Console.println( "+- parameters ----------------------------------------" );
83           for( i = 0; i < Array.size(func.parameters); i++ )
84           {
85	       object match, regexp = new Regexp("([^ ]+)[\n\t ]+([^ ]+)[\n\t ]+(.*)", "i");
86               type = name = meaning = "";
87	       match = regexp.match(func.parameters[i]);
88
89               if(match != null)
90               {
91		   type = match.capture(0);
92		   name = match.capture(1);
93                   meaning = match.capture(2);
94               }
95               Console.println( "| Parameter #${(i+1)}: '$name', type: $type" );
96               if( meaning != "" )
97                 Console.println( "|  $meaning" );
98           }
99           Console.println( "+-----------------------------------------------------" );
100       }
101       .processAll( func );
102       if( func.return_type != "" )
103       {
104           Console.println( "| returns ${func.return_type}" );
105           Console.println( "+-----------------------------------------------------" );
106       }
107   }
108
109   function processVariable( object var )
110   {
111       Console.println( "+-----------------------------------------------------" );
112       Console.println( "| Variable ${var.name}, type '${var.type}'" );
113       Console.println( "+-----------------------------------------------------" );
114
115       .processAll( var );
116   }
117
118   function processAll( object var )
119   {
120       if( var.brief != "" )
121       {
122           Console.println( "+- brief ---------------------------------------------" );
123           Console.println( "| ${var.brief}" );
124           Console.println( "+-----------------------------------------------------" );
125       }
126       if( var.description != "" )
127       {
128           Console.println( "+- description ---------------------------------------" );
129           Console.println( "| ${var.description}" );
130           Console.println( "+-----------------------------------------------------" );
131       }
132   }
133}
134/**
135 * !end
136 */
137
138return new TextTemplate( template_args );
139