Skip to content

Commit 6e32f2e

Browse files
committed
initial examples generation script
1 parent ae1ff39 commit 6e32f2e

298 files changed

Lines changed: 410 additions & 66908 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?ini_set('memory_limit', -1);/*** define paths to includes ***/define('BASEDIR', dirname(__FILE__).'/');define('TEMPLATEDIR', BASEDIR.'templates/');define('CONTENTDIR', BASEDIR.'content/');define('GENERATEDIR', BASEDIR.'generate/');define('DOMITDIR', GENERATEDIR.'domit/');define('GENLIBDIR', GENERATEDIR.'lib/');define('REFERENCEDIR', BASEDIR.'reference/');define('DISTDIR', BASEDIR.'distribution/');require_once(DOMITDIR.'xml_domit_include.php');require_once(GENLIBDIR.'xhtml.class.php');require_once(GENLIBDIR.'functions.inc.php');require_once(TEMPLATEDIR.'template.php');// Name, Encoding, Alphabetize, URL$domain = "http://processing.org/reference/";$LANGUAGES = array( 'en' => array('English', 'utf-8', true, $domain), 'zh' => array('Chinese Traditional', 'big5', false, $domain."zh/"), 'zh-cn' => array('Chinese Simplified', 'GB2312', false, $domain."zh-cn/"), 'fr' => array('French', 'utf-8', true, $domain."fr/"), 'id' => array('Indonesian', 'utf-8', false, $domain."id/"), 'it' => array('Italian', 'utf-8', true, $domain."it/"), 'jp' => array('Japanese', 'Shift_JIS', false, 'http://stage.itp.tsoa.nyu.edu/~tk403/proce55ing_reference_jp/'), 'kn' => array('Korean', 'utf-8', false, 'http://www.nabi.or.kr/processing/'), 'es' => array('Spanish', 'utf-8', true, $domain."es/"), 'tr' => array('Turkish', 'ISO-8859-9', true, $domain."tr/"), 'he' => array('Hebrew', 'Windows-1255', false, ''), 'ru' => array('Russian', 'ISO-8859-5', false, ''), 'pl' => array('Polish', 'ISO-8859-2', false, '') );// Langauges with finished references available to the public$FINISHED = array('en'); // for reference index formatting$break_before = array('Shape', 'Color');?>
1+
<?ini_set('memory_limit', -1);/*** define paths to includes ***/define('BASEDIR', dirname(__FILE__).'/');define('TEMPLATEDIR', BASEDIR.'templates/');define('CONTENTDIR', BASEDIR.'content/');define('GENERATEDIR', BASEDIR.'generate/');define('DOMITDIR', GENERATEDIR.'domit/');define('GENLIBDIR', GENERATEDIR.'lib/');define('REFERENCEDIR', BASEDIR.'reference/');define('DISTDIR', BASEDIR.'distribution/');define('EXAMPLESDIR', BASEDIR.'learning/examples/');require_once(DOMITDIR.'xml_domit_include.php');require_once(GENLIBDIR.'xhtml.class.php');require_once(GENLIBDIR.'functions.inc.php');require_once(TEMPLATEDIR.'template.php');// Name, Encoding, Alphabetize, URL$domain = "http://processing.org/reference/";$LANGUAGES = array( 'en' => array('English', 'utf-8', true, $domain), 'zh' => array('Chinese Traditional', 'big5', false, $domain."zh/"), 'zh-cn' => array('Chinese Simplified', 'GB2312', false, $domain."zh-cn/"), 'fr' => array('French', 'utf-8', true, $domain."fr/"), 'id' => array('Indonesian', 'utf-8', false, $domain."id/"), 'it' => array('Italian', 'utf-8', true, $domain."it/"), 'jp' => array('Japanese', 'Shift_JIS', false, 'http://stage.itp.tsoa.nyu.edu/~tk403/proce55ing_reference_jp/'), 'kn' => array('Korean', 'utf-8', false, 'http://www.nabi.or.kr/processing/'), 'es' => array('Spanish', 'utf-8', true, $domain."es/"), 'tr' => array('Turkish', 'ISO-8859-9', true, $domain."tr/"), 'he' => array('Hebrew', 'Windows-1255', false, ''), 'ru' => array('Russian', 'ISO-8859-5', false, ''), 'pl' => array('Polish', 'ISO-8859-2', false, '') );// Langauges with finished references available to the public$FINISHED = array('en'); // for reference index formatting$break_before = array('Shape', 'Color');?>

css/style.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ div.ref-col { width: 30%;
277277
.ref-col h3+h5 { margin-top: 0; }
278278
.category { margin-bottom: 30px; }
279279

280+
.ref-col p { margin-top: 0; margin-bottom: 1.5em; }
281+
280282
/**************************************************************** updates, courses, happenings ***/
281283
#Courses .content, #Updates .content, #Happenings .content {
282284
width: 595px;

generate/examples.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?
2+
3+
require('../config.php');
4+
require('lib/Example.class.php');
5+
6+
$cat_order = array(
7+
'Structure',
8+
'Form',
9+
'Data',
10+
'Control',
11+
'Math',
12+
'Drawing',
13+
'Typography',
14+
'.',
15+
'Image',
16+
'Color',
17+
'Transform',
18+
'Motion',
19+
'Input',
20+
'GUI',
21+
'Simulate',
22+
'.',
23+
'3D-Form',
24+
'3D-Transform',
25+
'3D-Image',
26+
'3D-Typography',
27+
'3D-Lights',
28+
'3D-Camera',
29+
'Library-Video',
30+
'Library-Net',
31+
'Library-Serial',
32+
'Library-OpenGL'
33+
);
34+
35+
36+
$dir = CONTENTDIR.'examples/';
37+
38+
foreach ($cat_order as $cat) {
39+
if ($cat != '.' && $dp = opendir($dir.$cat)) {
40+
while ($fp = readdir($dp)) {
41+
if (substr($fp, 0, 1) != '.') {
42+
$categories[$cat][] = $fp;
43+
$ex = new Example($fp, $cat);
44+
$ex->output_file();
45+
}
46+
}
47+
}
48+
}
49+
50+
$page = new Page('Examples', 'Examples');
51+
$page->subtemplate('template.examples.html');
52+
53+
$html = "<div class=\"ref-col\">\n";
54+
foreach ($cat_order as $cat) {
55+
if ($cat != '.') {
56+
$html .= "<h3><img src=\"images/".strtolower(removesymbols($cat)).".gif\" alt=\"$cat\" /></h3>\n<p>";
57+
foreach ($categories[$cat] as $file) {
58+
$html .= "\t<a href=\"examples\"".strtolower($file).".html\">$file</a><br />\n";
59+
}
60+
echo '</p>';
61+
} else {
62+
$html .= "</div><div class=\"ref-col\">";
63+
}
64+
}
65+
$html .= "</div>";
66+
67+
function removesymbols($str)
68+
{
69+
return preg_replace("/\W/", "", $str);
70+
}
71+
72+
$page->content($html);
73+
writeFile('learning/index.html', $page->out());
74+
75+
?>

generate/lib/Example.class.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?
2+
3+
class Example
4+
{
5+
var $name;
6+
var $cat;
7+
var $file;
8+
var $applet;
9+
var $doc;
10+
var $code;
11+
12+
function Example($name, $cat)
13+
{
14+
$this->name = $name;
15+
$this->cat = $cat;
16+
$this->file = file_get_contents(CONTENTDIR.'examples/'.$cat.'/'.$name.'/'.$name.'.pde');
17+
$this->applet = CONTENTDIR.'examples/'.$cat.'/'.$name.'/applet/'.$name.'.jar';
18+
$this->split_file();
19+
}
20+
21+
function split_file()
22+
{
23+
$lines = explode("\n", $this->file);
24+
$doc_lines = array();
25+
$code_lines = array();
26+
$doc = true;
27+
foreach ($lines as $line) {
28+
if (!preg_match("/^\W/", $line) && $doc) {
29+
$doc = false;
30+
}
31+
if ($doc) {
32+
$doc_lines[] = $line;
33+
} else {
34+
$code_lines[] = $line;
35+
}
36+
}
37+
$this->doc = implode("\n", $doc_lines);
38+
$this->code = implode("\n", $code_lines);
39+
}
40+
41+
function display()
42+
{
43+
$html = "\n<div class=\"example\">";
44+
if (file_exists($this->applet)) {
45+
$html .= "\n<div class=\"applet\">\n\t";
46+
$html .= '<applet code="'.$this->name.'" archive="media/'.$this->name.'.jar" width="200" height="200"></applet>';
47+
$html .= "\n</div>";
48+
49+
$html .= "\n<p class=\"doc-float\">";
50+
} else {
51+
$html .= "\n<p class=\"doc\">";
52+
}
53+
54+
$html .= nl2br($this->doc);
55+
$html .= "</p>\n";
56+
57+
$html .= "\n<p class=\"code\"><pre>";
58+
$html .= $this->code;
59+
$html .= "</pre></p>\n\n";
60+
61+
$html .= "\n</div>\n";
62+
return $html;
63+
}
64+
65+
function output_file()
66+
{
67+
$page = new Page($this->name . ' \ Examples', 'Examples');
68+
$page->subtemplate('template.example.html');
69+
$page->content($this->display());
70+
writeFile("learning/examples/".strtolower($this->name).".html", $page->out());
71+
$this->copy_media();
72+
}
73+
74+
function copy_media()
75+
{
76+
if (file_exists($this->applet)) {
77+
if (!copy($this->applet, EXAMPLESDIR.'media/'.$this->name.'.jar')) {
78+
echo "Could not copy {$this->applet} to .";
79+
}
80+
}
81+
}
82+
}
83+
84+
?>

generate/lib/functions.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ function getXMLFiles($dir)
259259
*****************************************************************/
260260
function writeFile($filename, $content)
261261
{
262+
echo $filename.'<br/>';
262263
make_necessary_directories(BASEDIR.$filename);
263264
$fp = fopen(BASEDIR.$filename, 'w');
264265
fwrite($fp, $content);

0 commit comments

Comments
 (0)