Index: trunk/parsers/wikidom/tests/index.html |
— | — | @@ -14,6 +14,7 @@ |
15 | 15 | <script src="../lib/qunit.js" type="text/javascript"></script> |
16 | 16 | <script src="../lib/wiki.js" type="text/javascript"></script> |
17 | 17 | <script src="../lib/wiki.util.js" type="text/javascript"></script> |
| 18 | + <script src="../lib/wiki.Context.js" type="text/javascript"></script> |
18 | 19 | <script src="../lib/wiki.AnnotationRenderer.js" type="text/javascript"></script> |
19 | 20 | <script src="../lib/wiki.HtmlRenderer.js" type="text/javascript"></script> |
20 | 21 | <script src="../lib/wiki.WikitextRenderer.js" type="text/javascript"></script> |
Index: trunk/parsers/wikidom/tests/wiki.test.js |
— | — | @@ -1,8 +1,10 @@ |
2 | 2 | module( 'Wiki DOM Serialization' ); |
3 | 3 | |
| 4 | +var context = new wiki.Context(); |
| 5 | + |
4 | 6 | function assertSerializations( tests ) { |
5 | | - var htmlRenderer = new wiki.HtmlRenderer(); |
6 | | - var wikitextRenderer = new wiki.WikitextRenderer(); |
| 7 | + var htmlRenderer = new wiki.HtmlRenderer( context ); |
| 8 | + var wikitextRenderer = new wiki.WikitextRenderer( context ); |
7 | 9 | for ( var i = 0; i < tests.length; i++ ) { |
8 | 10 | equals( |
9 | 11 | htmlRenderer.render( tests[i].dom ), |
Index: trunk/parsers/wikidom/lib/wiki.Context.js |
— | — | @@ -1,24 +1,81 @@ |
2 | | -wiki.Context = function() { |
| 2 | +wiki.Context = function( options ) { |
3 | 3 | |
4 | 4 | /* Private Members */ |
5 | 5 | |
6 | | - var params = {}; |
| 6 | + // Constants are used for behavioral switches, or other non-parametric inclusions |
| 7 | + var constants = options && options.constants ? options.constants : {}; |
| 8 | + // Parameters are used during transclusion for template expansion |
| 9 | + var parameters = options && options.parameters ? options.parameters : {}; |
7 | 10 | |
8 | 11 | /* Methods */ |
9 | 12 | |
| 13 | + /** |
| 14 | + * Checks if a page exists, used for rendering "new" links. |
| 15 | + * |
| 16 | + * This method delegates to the pageExists option passed through the constructor. If no such |
| 17 | + * option was given, this method will always return false. |
| 18 | + * |
| 19 | + * @param name String: Page namespace |
| 20 | + * @param name String: Page title |
| 21 | + * @return Boolean: True if page exists |
| 22 | + */ |
10 | 23 | this.pageExists = function( namespace, title ) { |
11 | | - return false; |
| 24 | + return typeof options.pageExists === 'function' |
| 25 | + ? options.pageExists( namespace, title ) : false; |
12 | 26 | }; |
13 | 27 | |
| 28 | + /** |
| 29 | + * Gets the Document Object Model of a page. |
| 30 | + * |
| 31 | + * This method delegates to the getPageDom option passed through the constructor. If no such |
| 32 | + * option was given, this method will always return null. |
| 33 | + * |
| 34 | + * @param name String: Page namespace |
| 35 | + * @param name String: Page title |
| 36 | + * @return Object: Page DOM (document object) |
| 37 | + */ |
14 | 38 | this.getPageDom = function( namespace, title ) { |
15 | | - return ''; |
| 39 | + return typeof options.pageExists === 'function' |
| 40 | + ? options.pageExists( namespace, title ) : null; |
16 | 41 | }; |
17 | 42 | |
18 | | - this.setParam = function( name, document ) { |
19 | | - params[name] = document; |
| 43 | + /** |
| 44 | + * Sets a constant. |
| 45 | + * |
| 46 | + * @param name String: Constant name |
| 47 | + * @param value String: Constant value |
| 48 | + */ |
| 49 | + this.setConstant = function( name, value ) { |
| 50 | + constants[name] = value; |
20 | 51 | }; |
21 | 52 | |
22 | | - this.getParam = function( name ) { |
23 | | - return name in params ? params[name] : null; |
| 53 | + /** |
| 54 | + * Gets a constant. |
| 55 | + * |
| 56 | + * @param name String: Constant name |
| 57 | + * @return String: Constant value |
| 58 | + */ |
| 59 | + this.getConstant = function( name ) { |
| 60 | + return name in constants ? constants[name] : null; |
24 | 61 | }; |
| 62 | + |
| 63 | + /** |
| 64 | + * Sets a parameter. |
| 65 | + * |
| 66 | + * @param name String: Parameter name |
| 67 | + * @param value Object: Parameter value (document object) |
| 68 | + */ |
| 69 | + this.setParameter = function( name, value ) { |
| 70 | + parameters[name] = value; |
| 71 | + }; |
| 72 | + |
| 73 | + /** |
| 74 | + * Gets a parameter. |
| 75 | + * |
| 76 | + * @param name String: Parameter name |
| 77 | + * @return Object: Parameter value (document object) |
| 78 | + */ |
| 79 | + this.getParameter = function( name ) { |
| 80 | + return name in parameters ? parameters[name] : null; |
| 81 | + }; |
25 | 82 | }; |