Welcome Guest, Not a member yet? Register   Sign In
Printable SVN Userguide
#1

[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:
Controller:
Code:
class Test extends Controller {

    function Test()
    {
        parent::Controller();    
    }
    
    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;
            else
            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);
                    else
                        $data['contents'] = $this->_extract_contents($file_path);

                    $data['anchor'] = $folder.$file;
                    $this->load->view('userguide/content', $data);
                }
            }
            closedir($current_dir);
        }
        $this->load->view('userguide/footer');
    }
    
    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;
    }
}
Views:

Header:
Code:
&lt;?php //SVN Userguide changes frequently -- keep the cache clean
         session_start();
?&gt;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;

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

&lt;style type="text/css" media="screen,print"&gt;
&lt;!--
&lt;?=$css?&gt;

#content {
    page-break-after: always;
}

#masthead {
    margin-top: 20px;
}
--&gt;
&lt;/style&gt;

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

&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;

&lt;/head&gt;
&lt;body&gt;

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

<br clear="all" />

<div class="center"><img src="http://dev.ellislab.com/svn/CodeIgniter/trunk/user_guide/images/ci_logo_flame.jpg" width="150" height="164" border="0" alt="CodeIgniter" /></div>
&lt;!-- START CONTENT --&gt;

Content:
Code:
<a name="&lt;?=$anchor;?&gt;"></a>
&lt;?=$contents?&gt;

Footer:
Code:
&lt;!-- END CONTENT --&gt;

<div id="footer">
<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright © 2008 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
</div>
&lt;/body&gt;
&lt;/html&gt;
#2

[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
#3

[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?
#4

[eluser]wiredesignz[/eluser]
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
#5

[eluser]wiredesignz[/eluser]
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.

EDIT:
The code is in the zip file.
#6

[eluser]Unknown[/eluser]
Thanks for this script!

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




Theme © iAndrew 2016 - Forum software by © MyBB