r88906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88905‎ | r88906 | r88907 >
Date:17:21, 26 May 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added more features and documentation to wiki.Context.
Modified paths:
  • /trunk/parsers/wikidom/lib/wiki.Context.js (modified) (history)
  • /trunk/parsers/wikidom/tests/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/wiki.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/index.html
@@ -14,6 +14,7 @@
1515 <script src="../lib/qunit.js" type="text/javascript"></script>
1616 <script src="../lib/wiki.js" type="text/javascript"></script>
1717 <script src="../lib/wiki.util.js" type="text/javascript"></script>
 18+ <script src="../lib/wiki.Context.js" type="text/javascript"></script>
1819 <script src="../lib/wiki.AnnotationRenderer.js" type="text/javascript"></script>
1920 <script src="../lib/wiki.HtmlRenderer.js" type="text/javascript"></script>
2021 <script src="../lib/wiki.WikitextRenderer.js" type="text/javascript"></script>
Index: trunk/parsers/wikidom/tests/wiki.test.js
@@ -1,8 +1,10 @@
22 module( 'Wiki DOM Serialization' );
33
 4+var context = new wiki.Context();
 5+
46 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 );
79 for ( var i = 0; i < tests.length; i++ ) {
810 equals(
911 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 ) {
33
44 /* Private Members */
55
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 : {};
710
811 /* Methods */
912
 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+ */
1023 this.pageExists = function( namespace, title ) {
11 - return false;
 24+ return typeof options.pageExists === 'function'
 25+ ? options.pageExists( namespace, title ) : false;
1226 };
1327
 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+ */
1438 this.getPageDom = function( namespace, title ) {
15 - return '';
 39+ return typeof options.pageExists === 'function'
 40+ ? options.pageExists( namespace, title ) : null;
1641 };
1742
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;
2051 };
2152
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;
2461 };
 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+ };
2582 };

Status & tagging log