CodeIgniter Forums
Blueprint Class library release - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Blueprint Class library release (/showthread.php?tid=2600)



Blueprint Class library release - El Forum - 08-14-2007

[eluser]Jamongkad[/eluser]
Hi all I figured I've leeched enough from this community, so as a token of thanks to the wonderful and patient denizens of CI forums I would like to submit my very first library!

Recently I pounced upon the Blueprint CSS framework. And I must say it's quite good! so I decided to make a library for Code Igniter. I personally use this as a means of rapid development. I know it's far from finished but I will try my best to stick close and churn out updates.

I based the code off of some research from the Jquery.php class library thank you to cvfoss for giving me a template to work from...

Ok here we go before anything please make a css folder in your application directory. So that you got a placed to drop the Blueprint folder in. If there are any corrections please let me know!

Blueprint.php <-----This goes to the library.
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blueprint {

    var $externalBlueprint='';

    var $externalStyle=array();
    
    //php4 constructor points to php5 constructor
    function Blueprint()
    {
         $this->__constructor();
    }
    //php5 constructor
    function __constructor()
    {}
    
    //set the url of Blueprint //
    function injectBlueprint($url)
    {
         $this->externalBlueprint = $url;
    }
    //add external style like &lt;style type="text/css" media="screen"&gt;@import url('style.css');&lt;/style&gt;, loads into an array to be looped in the final blueprint process
    function injectExternalStyle($url)
    {
        $this->externalStyle[]='&lt;style type="text/css" media="screen"" &gt;'.'@import url("'.$url.'");'.'&lt;/style&gt;';
        return true;
    }
    
    ///outputs the entire Blueprint stuff, including the externally loaded scripts.
    function igniteBlueprint()
    {
     $result= '&lt;link rel="stylesheet" type="text/css" media="screen, projection" href="'.$this-&gt;externalBlueprint.'">';
        
        foreach($this->externalStyle as $externalStyles){
            $result.=$externalStyles;
        }
        
        return $result;
    }
    
}

?&gt;

controller
Code:
&lt;?php

class Home extends Controller {

    function Home()
    {
     parent::Controller();    
     $this->load->library('blueprint');
    }
    
    function index()
    {
     //testing out the excellent Blueprint library!
      
     //this loads the screen.css indicate where the css/blueprint directory is placed in.    
     $this->blueprint->injectBlueprint('css/blueprint/screen.css');

     //this loads the print.css indicate where the css/blueprint directory is placed in.
     $this->blueprint->injectExternalStyle('css/blueprint/print.css');
    
     //this fires up the library to be thrown into the view
     $data['css'] = $this->blueprint->igniteBlueprint();
    
     $this->load->view('my_view.php',$data);
    }
}
?&gt;

view
my_view.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My View&lt;/title&gt;

//Echo the $css variable.
&lt;?php if(isset($css)) echo $css; ?&gt;

&lt;/head&gt;
&lt;body&gt;
  <p>I love Code Igniter!</p>
  <p>Jamongkad</p>


&lt;/body&gt;
&lt;/html&gt;