Skip to content

Commit a735265

Browse files
committed
First Commit
0 parents  commit a735265

File tree

13 files changed

+919
-0
lines changed

13 files changed

+919
-0
lines changed

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
NEAT Layout Manager:
2+
--------------------
3+
Neat is a cakephp like layout manager , you can find in this repository Neat library
4+
with an example of how to use it.
5+
6+
Instalation:
7+
------------
8+
Download CodeIgniter from the project webpage
9+
Extract Project content into you codeigniter folder - Take care there is an example called Home.
10+
In autload config add Neat library -- $autoload['libraries'] = array('Neat');
11+
In autload config add url and html helpers -- $autoload['helper'] = array('url','html');
12+
13+
Usage:
14+
------
15+
In Neat configuration file define your layout , your webroot folder and elements folder.
16+
Ex:
17+
$neat_lm['default_layout'] = 'default';
18+
$neat_lm['elements_folder'] = 'elements';
19+
$neat_lm['HTML_WEBROOT'] = base_url().'webroot/';
20+
21+
22+
define you layout use:
23+
$this->neat->setLayout('default');
24+
25+
Render View use :
26+
$this->neat->render('home/index', $data_sample);
27+
28+
using CSS Or Javascript use:
29+
30+
$this->neat->css('css/bs.min.css'); OR $this->neat->css('http://wwww.URL');
31+
$this->neat->js('js/jq.min.js'); OR $this->neat->js('http://wwww.URL');
32+
33+
Use Elements:
34+
$this->neat->get_elements('home/hello',$sample1);
35+
36+
Use Metatags:
37+
$this->neat->meta_tag_link('description','Neat Template Manager');
38+
39+
40+
In your Layout file:
41+
--------------------
42+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
43+
<html xmlns="http://www.w3.org/1999/xhtml">
44+
45+
<head>
46+
<title>Neat Template Manager</title>
47+
<?php $this->neat->get_elements('neat/header_script_for_layout'); ?>
48+
</head>
49+
50+
<body>
51+
52+
<h1 style="color: blue;"> Here is the Layout Header </h1>
53+
54+
<?php echo $content_for_layout; ?>
55+
56+
<h1 style="color: red;"> Here is the Layout Footer </h1>
57+
58+
</body>
59+
60+
</html>

application/config/custome/neat.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
3+
$neat_lm['default_layout'] = 'default';
4+
$neat_lm['elements_folder'] = 'elements';
5+
6+
$neat_lm['HTML_WEBROOT'] = base_url().'webroot/';
7+

application/controllers/home.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
3+
class Home extends CI_Controller
4+
{
5+
6+
public function index() {
7+
8+
$data_sample = array();
9+
$data_sample['sample1']='data1';
10+
$data_sample['sample2']='data2';
11+
12+
13+
$this->neat->setLayout('default');
14+
$this->neat->render('home/index', $data_sample);
15+
16+
17+
}
18+
19+
}

application/libraries/Neat.php

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
3+
class Neat
4+
{
5+
6+
private $config;
7+
private $layout;
8+
private $data = array();
9+
private $ci_instance;
10+
private $elements_folder;
11+
private $html_webroot;
12+
public $css_output = array();
13+
public $js_output = array();
14+
public $metatags = array();
15+
16+
public function __construct() {
17+
18+
include_once(APPPATH.'config/custome/neat.php');
19+
20+
$this->config = $neat_lm;
21+
22+
$this->layout = 'layouts/'.$this->config['default_layout'];
23+
$this->elements_folder = $this->config['elements_folder'];
24+
25+
$this->html_webroot = $this->config['HTML_WEBROOT'];
26+
27+
$this->ci_instance =& get_instance();
28+
29+
}
30+
31+
function setLayout($name) {
32+
33+
$this->layout = 'layouts/'.$name;
34+
35+
}
36+
37+
function render($view, $data = null, $return = false) {
38+
39+
if($data != null && is_array($data)) {
40+
41+
$this->data = array_merge($this->data, $data);
42+
43+
}
44+
45+
$content_layout = array();
46+
47+
$content_layout['content_for_layout'] = $this->ci_instance->load->view($view, $this->data, true);
48+
49+
if ($return) {
50+
51+
$output = $this->ci_instance->load->view($this->layout, $content_layout, true);
52+
return $output;
53+
54+
} else {
55+
56+
$this->ci_instance->load->view($this->layout, $content_layout, false);
57+
58+
}
59+
60+
}
61+
62+
function get_elements($name) {
63+
64+
$output = $this->ci_instance->load->view($this->elements_folder.'/'.$name, $this->data, false) ;
65+
return $output;
66+
67+
}
68+
69+
// Must be called before render method so data applies to view
70+
public function bind_data($key, $value) {
71+
72+
$this->data[$key] = $value;
73+
return $this;
74+
75+
}
76+
77+
public function css($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) {
78+
79+
$css_output = '';
80+
81+
if (strpos($href, '//') !== false) {
82+
83+
$this->css_output[] = link_tag($href , $rel, $type, $title, $media, $index_page = FALSE);
84+
85+
}else{
86+
87+
$this->css_output[] = link_tag($this->html_webroot.$href , $rel, $type, $title, $media, $index_page = FALSE);
88+
89+
}
90+
91+
92+
}
93+
94+
public function js($src = '', $language = 'javascript', $type = 'text/javascript') {
95+
96+
if (strpos($src, '//') !== false) {
97+
98+
$this->js_output[] = '<script type="'.$type.'" src="'.$src.'"></script>';
99+
100+
}else{
101+
102+
$this->js_output[] = '<script type="'.$type.'" src="'.$this->html_webroot.$src.'"></script>';
103+
104+
}
105+
106+
}
107+
108+
public function meta_tag_link($name = "", $content = "", $type = 'name') {
109+
110+
$this->metatags[]=meta($name,$content,$type);
111+
112+
}
113+
114+
115+
}

application/views/elements/footer.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is the footer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This Text From Inside The elements
2+
<br>This data from elements:<?php echo $sample1; ?></br>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
if (!empty($this->neat->css_output)) {
3+
foreach ($this->neat->css_output as $css) {
4+
echo $css;
5+
}
6+
}
7+
8+
if (!empty($this->neat->js_output)) {
9+
foreach ($this->neat->js_output as $js) {
10+
echo $js;
11+
}
12+
}
13+
14+
if (!empty($this->neat->metatags)) {
15+
foreach ($this->neat->metatags as $metatags) {
16+
echo $metatags;
17+
}
18+
}
19+
20+
?>

application/views/home/index.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php $this->neat->css('css/bs.min.css'); ?>
2+
<?php $this->neat->js('js/jq.min.js'); ?>
3+
4+
<?php $this->neat->meta_tag_link('description','Neat Template Manager'); ?>
5+
6+
<?php $this->neat->get_elements('home/hello',$sample1); ?>
7+
<br></br>
8+
<p>This variable From inside the view direct - <?php echo $sample1; ?></p>
9+

0 commit comments

Comments
 (0)