Merge "Implement inline documentation examples."

This commit is contained in:
jenkins-bot 2013-02-09 01:50:44 +00:00 committed by Gerrit Code Review
commit 8d274c19e6
8 changed files with 86 additions and 30 deletions

View file

@ -2,6 +2,7 @@
"--title": "VisualEditor Code Documentation",
"--categories": "../.docs/categories.json",
"--meta-tags": "../.docs/MetaTags.rb",
"--eg-iframe": "../.docs/eg-iframe.html",
"--warnings": ["-no_doc"],
"--builtin-classes": true,
"--output": "../docs",

View file

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>VisualEditor Examples</title>
<script>
function loadInlineExample(code, options, callback) {
try {
document.body.innerHTML = '';
eval(code);
callback && callback(true);
} catch (e) {
document.body.innerHTML = document.createTextNode(e);
callback && callback(false, e);
}
}
</script>
</head>
<body></body>
</html>

32
.docs/eg-iframe.tpl Normal file
View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>VisualEditor Examples</title>
<head>
{{VE-LOAD-HEAD}}
<script>
function loadInlineExample(code, options, callback) {
try {
eval(code);
callback && callback(true);
} catch (e) {
document.body.appendChild(document.createTextNode(e));
callback && callback(false, e);
}
}
</script>
<style>
body {
margin: 0;
padding: 0;
overflow-y: scroll;
background: #fff;
font: normal 1em/1.5 sans-serif;
}
</style>
</head>
<body>
{{VE-LOAD-BODY}}
</body>
</html>

21
.docs/generate.sh Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
cd $(cd $(dirname $0); pwd)
(
while IFS='' read -r l
do
if [[ "$l" =~ {{VE-LOAD-BODY}} ]]
then
php ../maintenance/makeStaticLoader.php --section=body --ve-path=../modules/
elif [[ "$l" =~ {{VE-LOAD-HEAD}} ]]
then
php ../maintenance/makeStaticLoader.php --section=head --ve-path=../modules/
else
echo "$l"
fi
done
) < eg-iframe.tpl | php > eg-iframe.html
jsduck --config=config.json
rm eg-iframe.html
cd - > /dev/null

View file

@ -31,7 +31,7 @@ $ gem install jsduck
#### Run
```
$ cd VisualEditor
$ jsduck --config=.docs/config.json
$ .docs/generate.sh
# open http://localhost/VisualEditor/docs/
```

View file

@ -6,13 +6,11 @@
*/
body {
font-family: Arial;
font-size: 1em;
width: 100%;
margin: 1em 0;
margin: 0;
padding: 0;
overflow-y: scroll;
background-color: #fff;
background: #fff;
font: normal 1em/1.5 sans-serif;
}
/* Demo */

View file

@ -1,6 +1,6 @@
<?php
$path = '../..';
$path = __DIR__ . '/../../..';
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
$path = getenv( 'MW_INSTALL_PATH' );
@ -16,6 +16,7 @@ class MakeStaticLoader extends Maintenance {
$this->addOption( 'target', 'Which target to use ("demo" or "test"). Default: false', false, true );
$this->addOption( 'indent', 'Indentation prefix to use (number of tabs or a string)', false, true );
$this->addOption( 've-path', 'Override path to "/modules/". Default by --target', false, true );
$this->addOption( 'section', 'head, body or both', false, true );
}
public function execute() {
@ -24,6 +25,7 @@ class MakeStaticLoader extends Maintenance {
$wgHtml5 = true;
$wgWellFormedXml = false;
$section = $this->getOption( 'section', 'both' );
$target = $this->getOption( 'target', 'demo' );
$indent = $this->getOption( 'indent', 2 );
if ( is_numeric( $indent ) ) {
@ -54,10 +56,18 @@ class MakeStaticLoader extends Maintenance {
've/init/sa/ve.init.sa.js',
've/init/sa/ve.init.sa.Platform.js',
),
'headAdd' => '
<script>
if ( window.devicePixelRatio > 1 ) {
document.write( \'<link rel="stylesheet" href="' . $vePath . 've/ui/styles/ve.ui.Icons-vector.css">\' );
} else {
document.write( \'<link rel="stylesheet" href="' . $vePath . 've/ui/styles/ve.ui.Icons-raster.css">\' );
}
</script>',
'bodyAdd' => '<script>
<?php
require( \'' . $vePath . '../VisualEditor.i18n.php\' );
echo \'ve.init.platform.addMessages( \' . json_encode( $messages[\'en\'] ) . \');\';
echo \'ve.init.platform.addMessages( \' . json_encode( $messages[\'en\'] ) . \');\' . "\n";
?>
ve.init.platform.setModulesUrl( \'' . $vePath . '\' );
</script>'
@ -112,10 +122,18 @@ class MakeStaticLoader extends Maintenance {
}
}
if ( $head ) {
if ( $section === 'both' ) {
echo "<head>\n\n$indent<!-- Generated by $self -->\n$head\n\n</head>";
} elseif ( $section === 'head' ) {
echo $head;
}
}
if ( $body ) {
if ( $section === 'both' ) {
echo "<body>\n\n$indent<!-- Generated by $self -->\n$body\n\n</body>\n";
} elseif ( $section === 'body' ) {
echo $body;
}
}
}
}

View file

@ -10,6 +10,12 @@
*
* A surface is a top-level object which contains both a surface model and a surface view.
*
* @example
* new ve.Surface(
* $( '<div>' ).appendTo( document.body ),
* $( '<p>Hello world.</p>' )[0]
* );
*
* @class
* @constructor
* @param {string} parent Selector of element to attach to