summaryrefslogtreecommitdiff
path: root/tools/texbuilder/build.php
diff options
context:
space:
mode:
Diffstat (limited to 'tools/texbuilder/build.php')
-rw-r--r--tools/texbuilder/build.php218
1 files changed, 218 insertions, 0 deletions
diff --git a/tools/texbuilder/build.php b/tools/texbuilder/build.php
new file mode 100644
index 00000000..0cea6aee
--- /dev/null
+++ b/tools/texbuilder/build.php
@@ -0,0 +1,218 @@
+<?php
+//page root location
+$base = realpath(dirname(__FILE__).'/../../demos/quickstart/protected/pages/');
+
+//list page into chapters
+$pages['Getting Started'] = array(
+ 'GettingStarted/Introduction.page',
+ 'GettingStarted/AboutPrado.page',
+ 'GettingStarted/Installation.page');
+
+$pages['Fundamentals'] = array(
+ 'Fundamentals/Architecture.page',
+ 'Fundamentals/Components.page',
+ 'Fundamentals/Controls.page',
+ 'Fundamentals/Pages.page',
+ 'Fundamentals/Modules.page',
+ 'Fundamentals/Services.page',
+ 'Fundamentals/Applications.page',
+ 'Fundamentals/HelloWorld.page',
+ 'Fundamentals/Hangman.page');
+
+$pages['Configurations'] = array(
+ 'Configurations/Overview.page',
+ 'Configurations/Templates1.page',
+ 'Configurations/Templates2.page',
+ 'Configurations/Templates3.page',
+ 'Configurations/AppConfig.page',
+ 'Configurations/PageConfig.page');
+
+$pages['Controls'] = array(
+ 'Controls/Overview.page',
+ 'Controls/Simple.page',
+ 'Controls/List.page',
+ 'Controls/Validation.page',
+ 'Controls/DataList.page',
+ 'Controls/DataGrid.page');
+
+
+//-------------- END CONFIG ------------------
+
+
+function escape_verbatim($matches)
+{
+ return "\begin{verbatim}".str_replace('\$', '$', $matches[2])."\end{verbatim}\n";
+}
+
+function include_image($matches)
+{
+ global $current_path;
+ $image = dirname($current_path).'/'.$matches[1];
+ $file = realpath($image);
+ $info = getimagesize($file);
+ switch($info[2])
+ {
+ case 1:
+ $im = imagecreatefromgif($file);
+ break;
+ case 2: $im = imagecreatefromjpeg($file); break;
+ case 3: $im = imagecreatefrompng($file); break;
+ }
+ global $base;
+
+ if(isset($im))
+ {
+ $prefix = strtolower(str_replace(realpath($base), '', $file));
+ $filename = preg_replace('/\\\|\//', '_', substr($prefix,1));
+ $filename = substr($filename, 0, strrpos($filename,'.')).'.png';
+ $newfile = dirname(__FILE__).'/'.$filename;
+ imagepng($im,$newfile);
+ imagedestroy($im);
+
+ return include_figure($info, $filename);
+ }
+}
+
+function include_figure($info, $filename)
+{
+ $width = sprintf('%0.2f', $info[0]/(135/2.54));
+ return '
+\begin{figure}[ht]
+ \centering
+ \includegraphics[width='.$width.'cm]{'.$filename.'}
+ \label{fig:'.$filename.'}
+\end{figure}
+';
+}
+
+function anchor($matches)
+{
+ $page = get_current_path();
+ return '\hypertarget{'.$page.'/'.$matches[1].'}{}';
+}
+
+function get_current_path()
+{
+ global $current_path, $base;
+ $page = strtolower(substr(str_replace($base, '', $current_path),1));
+ return $page;
+}
+
+function make_link($matches)
+{
+ if(is_int(strpos($matches[1], '#')))
+ {
+ if(strpos($matches[1],'?') ===false)
+ {
+ $target = get_current_path().'/'.substr($matches[1],1);
+ return '\hyperlink{'.$target.'}{'.$matches[2].'}';
+ }
+ else
+ {
+ $page = strtolower(str_replace('?page=', '', $matches[1]));
+ $page = str_replace('.','/',$page);
+ $page = str_replace('#','.page/',$page);
+ return '\hyperlink{'.$page.'}{'.$matches[2].'}';
+ }
+ }
+ else if(is_int(strpos($matches[1],'?')))
+ {
+ $page = str_replace('?page=','',$matches[1]);
+ return '\hyperlink{'.$page.'}{'.$matches[2].'}';
+ }
+ return '\href{'.$matches[1].'}{'.$matches[2].'}';
+}
+
+function parse_html($page,$html)
+{
+ $html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html);
+ $html = preg_replace('/<\/?p>/m', '', $html);
+
+ //headings
+ $html = preg_replace('/<h1[^>]*>([^<]+)<\/h1>/', '\section{$1}', $html);
+ $html = preg_replace('/<h2[^>]*>([^<]+)<\/h2>/', '\subsection{$1}', $html);
+ $html = preg_replace('/<h3[^>]*>([^<]+)<\/h3>/', '\subsubsection{$1}', $html);
+
+ //codes
+ $html = str_replace('$', '\$', $html);
+ $html = preg_replace('/<com:TTextHighlighter[^>]*>/', '`1`', $html);
+ $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html);
+ $html = preg_replace_callback('/(`1`)([^`]*)(`2`)/m', 'escape_verbatim', $html);
+ $html = preg_replace_callback('/(<div class="source">)([^<]*)(<\/div>)/', 'escape_verbatim', $html);
+
+
+ $html = preg_replace_callback('/<img\s+src="<%~([^"]*)%>"[^\\/]*\/>/', 'include_image', $html);
+
+ //runbar
+ $html = preg_replace('/<com:RunBar\s+PagePath="([^"]*)"\s+\/>/',
+ 'Try, \texttt{http://../quickstart/index.php?page=$1}', $html);
+
+
+ //text modifiers
+ $html = preg_replace('/<b>([^>]*)<\/b>/', '\textbf{$1}', $html);
+ $html = preg_replace('/<i>([^>]*)<\/i>/', '\emph{$1}', $html);
+ $html = preg_replace('/<tt>([^>]*)<\/tt>/', '\texttt{$1}', $html);
+
+ //links
+ $html = preg_replace_callback('/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/',
+ 'make_link', $html);
+ //anchor
+ $html = preg_replace_callback('/<a[^>]+name="([^"]*)"[^>]*><\/a>/', 'anchor', $html);
+
+ //item lists
+ $html = preg_replace('/<ol>/', '\begin{itemize}', $html);
+ $html = preg_replace('/<\/ol>/', '\end{itemize}', $html);
+ $html = preg_replace('/<ul>/', '\begin{enumerate}', $html);
+ $html = preg_replace('/<\/ul>/', '\end{enumerate}', $html);
+ $html = preg_replace('/<li>/', '\item ', $html);
+ $html = preg_replace('/<\/li>/', '', $html);
+
+ $html = html_entity_decode($html);
+
+
+ return $html;
+}
+
+function get_chapter_label($chapter)
+{
+ return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}';
+}
+
+function get_section_label($section)
+{
+ $section = str_replace('.page', '', $section);
+ return '\hypertarget{'.str_replace('/', '.', $section).'}{}';
+}
+
+//--------------- BEGIN PROCESSING -------------------
+
+$count = 1;
+$current_path = '';
+echo "Compiling .page files to Latex files\n\n";
+foreach($pages as $chapter => $sections)
+{
+ $content = '\chapter{'.$chapter.'}'.get_chapter_label($chapter);
+ echo "Creating ch{$count}.txt => Chapter {$count}: {$chapter}\n";
+ echo str_repeat('-',60)."\n";
+ foreach($sections as $section)
+ {
+ echo " Adding $section\n";
+ $page = $base.'/'.$section;
+ $current_path = $page;
+ $content .= get_section_label($section);
+ $content .= parse_html($page,file_get_contents($page));
+ }
+
+ //var_dump($content);
+ file_put_contents("ch{$count}.tex", $content);
+ $count++;
+ echo "\n";
+}
+
+if($count > 1)
+{
+ echo "** Use Latex and pdfText to compile the main tex file. **\n";
+}
+
+
+?> \ No newline at end of file