Enable @example for jsduck index
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 26 Jun 2013 23:33:51 +0000 (16:33 -0700)
committerKrinkle <krinklemail@gmail.com>
Thu, 4 Jul 2013 02:17:39 +0000 (02:17 +0000)
Change-Id: Ifa38338b797413b6ad54c49f508cabe21c1565ea

maintenance/jsduck/config.json
maintenance/jsduck/eg-iframe.html
maintenance/mwjsduck-gen
resources/mediawiki/mediawiki.js

index 60522c5..2a40f29 100644 (file)
@@ -3,6 +3,7 @@
        "--footer": "Documentation for MediaWiki core. Generated on {DATE} by {JSDUCK} {VERSION}.",
        "--categories": "./categories.json",
        "--meta-tags": "./MetaTags.rb",
+       "--eg-iframe": "./eg-iframe.html",
        "--warnings": ["-no_doc"],
        "--builtin-classes": true,
        "--output": "../../docs/js",
index f53b404..86eae4b 100644 (file)
@@ -2,19 +2,87 @@
 <html>
 <head>
     <meta charset="utf-8">
-    <title>MediaWiki Examples</title>
+    <title>MediaWiki Code Example</title>
+    <script src="modules/startup.js"></script>
     <script>
-        function loadInlineExample(code, options, callback) {
+        function startUp() {
+            mw.config = new mw.Map();
+        }
+    </script>
+    <script src="modules/jquery/jquery.js"></script>
+    <script src="modules/mediawiki/mediawiki.js"></script>
+    <style>
+        .mw-jsduck-log {
+            position: relative;
+            min-height: 3em;
+            margin-top: 2em;
+            background: #f7f7f7;
+            border: 1px solid #e4e4e4;
+        }
+
+        .mw-jsduck-log::after {
+            position: absolute;
+            bottom: 100%;
+            right: -1px;
+            padding: 0.5em;
+            background: #fff;
+            border: 1px solid #e4e4e4;
+            border-bottom: 0;
+            border-radius: 0.5em 0.5em 0 0;
+            font: normal 0.5em sans-serif;
+            content: 'console';
+        }
+
+        .mw-jsduck-log-line {
+            padding: 0.2em 0.5em;
+            white-space: pre-wrap;
+        }
+
+        .mw-jsduck-log-line:nth-child(odd) {
+            background: #fff;
+        }
+    </style>
+</head>
+<body>
+    <script>
+        /**
+         * Basic log console for the example iframe in documentation pages.
+         */
+        ( function () {
+            var pre;
+            mw.log = function () {
+                var str, i, len, line;
+                if ( !pre ) {
+                    pre = document.createElement( 'pre' );
+                    pre.className = 'mw-jsduck-log';
+                    document.body.appendChild( pre );
+                }
+                str = [];
+                for ( i = 0, len = arguments.length; i < len; i++ ) {
+                    str.push( String( arguments[ i ] ) );
+                }
+                line = document.createElement( 'div' );
+                line.className = 'mw-jsduck-log-line';
+                line.appendChild(
+                    document.createTextNode( str.join( ' , ' ) + '\n' )
+                );
+                pre.appendChild( line );
+            };
+        }() );
+
+        /**
+         * Method called by jsduck to execute the example code.
+         */
+        function loadInlineExample( code, options, callback ) {
             try {
-                document.body.innerHTML = '';
-                eval(code);
-                callback && callback(true);
+                eval( code );
+                callback && callback( true );
             } catch (e) {
-                document.body.innerHTML = document.createTextNode(e);
-                callback && callback(false, e);
+                mw.log( 'Uncaught exception: ' + e );
+                callback && callback( false, e );
+                throw e;
             }
         }
     </script>
-</head>
-<body></body>
+</body>
 </html>
index cccc715..bc10bc2 100755 (executable)
@@ -11,7 +11,11 @@ then
        exit 1
 fi
 
+MWCORE_DIR=$(cd $(dirname $0)/..; pwd)
+
 jsduck \
---config=$(cd $(dirname $0)/..; pwd)/maintenance/jsduck/config.json \
+--config=$MWCORE_DIR/maintenance/jsduck/config.json \
 --footer="Documentation for MediaWiki core ($JSDUCK_MWVERSION). Generated on {DATE} by {JSDUCK} {VERSION}." \
 && echo 'JSDuck execution finished.'
+
+ln -s ../../resources $MWCORE_DIR/docs/js/modules
index 0d1fbb7..8409d45 100644 (file)
@@ -1648,6 +1648,17 @@ var mw = ( function ( $, undefined ) {
 
                /**
                 * HTML construction helper functions
+                *
+                *     @example
+                *
+                *     var Html, output;
+                *
+                *     Html = mw.html;
+                *     output = Html.element( 'div', {}, new Html.Raw(
+                *         Html.element( 'img', { src: '<' } )
+                *     ) );
+                *     mw.log( output ); // <div><img src="&lt;"/></div>
+                *
                 * @class mw.html
                 * @singleton
                 */
@@ -1688,12 +1699,6 @@ var mw = ( function ( $, undefined ) {
                                 *  - this.Cdata: The value attribute is included, and an exception is
                                 *   thrown if it contains an illegal ETAGO delimiter.
                                 *   See http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.3.2
-                                *
-                                * Example:
-                                *      var h = mw.html;
-                                *      return h.element( 'div', {},
-                                *              new h.Raw( h.element( 'img', {src: '<'} ) ) );
-                                * Returns <div><img src="&lt;"/></div>
                                 */
                                element: function ( name, attrs, contents ) {
                                        var v, attrName, s = '<' + name;