[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:
<?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 <style type="text/css" media="screen">@import url('style.css');</style>, loads into an array to be looped in the final blueprint process
function injectExternalStyle($url)
{
$this->externalStyle[]='<style type="text/css" media="screen"" >'.'@import url("'.$url.'");'.'</style>';
return true;
}
///outputs the entire Blueprint stuff, including the externally loaded scripts.
function igniteBlueprint()
{
$result= '<link rel="stylesheet" type="text/css" media="screen, projection" href="'.$this->externalBlueprint.'">';
foreach($this->externalStyle as $externalStyles){
$result.=$externalStyles;
}
return $result;
}
}
?>
controller
Code:
<?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);
}
}
?>
view
my_view.php
Code:
<html>
<head>
<title>My View</title>
//Echo the $css variable.
<?php if(isset($css)) echo $css; ?>
</head>
<body>
<p>I love Code Igniter!</p>
<p>Jamongkad</p>
</body>
</html>