Printable SVN Userguide

[eluser]Pascal Kriete[/eluser]
So today I finally got sick of having 10 billion tabs and windows open on my 13 inch screen when I'm coding. So I looked around for a printable userguide, and there are quite a few Versions and what not, but they're usually not for 1.6, and it's mostly pdfs - I needed something flexible, since the SVN code gets updated frequently. So with all due respect, I made my own.

It uses my local copy of the SVN user guide to dynamically generate one big html page with proper page breaks for printing. I also added a function to rewrite the table of contents links to just scroll to the proper anchor (web 1.0 - hell, yeah).

My hosting is having issues, so I'll just post the code:
class Test extends Controller {

    function Test()
    function index()
        echo "test controller";
    function userguide()
        /* Things we'll need */
        $main_dir = "/Applications/MAMP/htdocs/user_guide/";         //user_guide root WITH trailing slash
        /* These are sent out in the order listed */
        $individual_files = array('index.html', 'toc.html', 'license.html', 'installation/index.html');
        $directories = array('', 'general/', 'libraries/', 'helpers/');
        /* Make css inline */
        $header['css'] = file_get_contents($main_dir.'userguide.css');
        $this->load->view('userguide/header', $header);
        $mainpage = $main_dir.'index.html';
        /* Go through folders and get contents */
        foreach($directories as $folder) {
            $this_dir = $main_dir.$folder;
            $current_dir = opendir($this_dir);
            $files_in_dir = array();
            //Individual files come from the root folder
            if ($folder == '')
                $files_in_dir = $individual_files;
            while($file = readdir($current_dir)) {
                $files_in_dir[] = $file;
            foreach($files_in_dir as $file) {
                if (!is_dir($file)) {
                    $file_path = $this_dir.$file;
                    //Turn the non-junk into a view variable
                    if ($file == 'toc.html')
                        $data['contents'] = $this->_change_toc($file_path);
                        $data['contents'] = $this->_extract_contents($file_path);

                    $data['anchor'] = $folder.$file;
                    $this->load->view('userguide/content', $data);
    function _change_toc($path)
        $contents = $this->_extract_contents($path);
        /* Change links */
        $contents = str_replace('./', '#', $contents);
        return $contents;
    function _extract_contents($file_path)
        /* Things we need */
        $start = '<div id="content">';
        $end = '&lt;!-- END CONTENT --&gt;';
        /* Get that first file */
        $file_content = file_get_contents($file_path);
        /* Remove the junk */
        $start_pos = strpos($file_content, $start);
        $end_pos = strpos($file_content, $end);
        $pos_diff = $end_pos - $start_pos;

        /* Give back the non-junk */
        $contents = substr($file_content, $start_pos, $pos_diff);
        return $contents;

&lt;?php //SVN Userguide changes frequently -- keep the cache clean
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
&lt;html xmlns="" xml:lang="en" lang="en"&gt;

&lt;title&gt;CodeIgniter User Guide&lt;/title&gt;

&lt;style type="text/css" media="screen,print"&gt;

#content {
    page-break-after: always;

#masthead {
    margin-top: 20px;

&lt;style type="text/css" media="screen"&gt;
    #content {
        margin-bottom: 100px;
        padding-bottom: 100px;
        border-bottom: 3px solid black;

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;meta http-equiv='expires' content='-1' /&gt;
&lt;meta http-equiv= 'pragma' content='no-cache' /&gt;
&lt;meta name='robots' content='all' /&gt;
&lt;meta name='author' content='ExpressionEngine Dev Team' /&gt;
&lt;meta name='description' content='CodeIgniter User Guide' /&gt;


<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<td><h1>CodeIgniter User Guide Version 1.6.0</h1></td>

<br clear="all" />

<div class="center"><img src="" width="150" height="164" border="0" alt="CodeIgniter" /></div>
&lt;!-- START CONTENT --&gt;

<a name="&lt;?=$anchor;?&gt;"></a>

&lt;!-- END CONTENT --&gt;

<div id="footer">
<p><a href="">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright © 2008 &nbsp;&middot;&nbsp; <a href="">Ellislab, Inc.</a></p>

[eluser]Derek Allard[/eluser]
Wow, very clever sir. But you know that if you don't have the userguide burned into your brain then you just aren't spending enough time with CI right... Smile

[eluser]Pascal Kriete[/eluser]
Oh gee, I better get on that. *Starts memorizing database class*.

On another note, I've fixed the code - I forgot to actually display the anchor tags. I also changed the copyright to 2008, since I have a hunch that will be updated soon (yes, I'm clairvoyant). And one last thing I noticed is that the benchmark examples {elapsed_time} and {memory_usage} get parsed, is there an easy way around this?

Wow, inparo this is fantastic.

In fact it's so good I was able to print a pdf from the CI 1.6.2 User Guide.

Many thanks inparo. Wink

Here is an updated version of Pascal's (Inparo's) printable user guide as a CI application. Download the attached Zip application file which includes the controller and view files.

The code is in the zip file.

Thanks for this script!

It was very useful in creating an output for my Kindle to have something to read when offline!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.