From a58e51bd24ee652228b6bf3820401203a0b793b6 Mon Sep 17 00:00:00 2001 From: souparno Date: Mon, 28 Sep 2015 21:06:14 +0530 Subject: [PATCH 1/4] including the nbproject --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3896c0e..c318f21 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ application/cache/* application/logs/* !application/logs/index.html -!application/logs/.htaccess \ No newline at end of file +!application/logs/.htaccess +/nbproject +/nbproject/private/ From 42d0dbfce461e04577ef179d5c54f5d37192c534 Mon Sep 17 00:00:00 2001 From: souparno Date: Mon, 28 Sep 2015 21:07:05 +0530 Subject: [PATCH 2/4] a cleaner load_view function --- application/libraries/Template.php | 103 +++++++++++++++++++---------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/application/libraries/Template.php b/application/libraries/Template.php index cc4bf3c..a1b25a2 100644 --- a/application/libraries/Template.php +++ b/application/libraries/Template.php @@ -13,7 +13,7 @@ class Template { protected $title_separator = ' - '; protected $ga_id = FALSE; // UA-XXXXX-X - protected $layout = 'default'; + protected $layout; protected $title = FALSE; protected $description = FALSE; @@ -103,6 +103,63 @@ public function add_css($css) { $this->css[$css] = $css; } + + public function get_title() + { + if (empty($this->title)) { + $this->title = $this->brand_name;; + } else { + $this->title = $this->title . $this->title_separator . $this->brand_name; + } + return $this->title; + } + + public function get_description() + { + if (empty($this->description)) { + $this->description = ''; + } + return $this->description; + } + + public function get_metadata() + { + $metadata = array(); + foreach ($this->metadata as $name => $content) { + if (strpos($name, 'og:') === 0) { + $metadata[] = ''; + } else { + $metadata[] = ''; + } + } + return implode('', $metadata); + } + + public function get_js() + { + $js = array(); + foreach ($this->js as $js_file) { + $js[] = ''; + } + return implode('', $js); + } + + public function get_css() + { + $css = array(); + foreach ($this->css as $css_file) { + $css[] = ''; + } + return implode('', $css); + } + + public function get_layout() + { + if(empty($this->layout)) { + $this->layout = 'default'; + } + return $this->layout; + } /** * Load view @@ -123,54 +180,28 @@ public function load_view($view, $data = array(), $return = FALSE) } // Title - if (empty($this->title)) - { - $title = $this->brand_name; - } - else - { - $title = $this->title . $this->title_separator . $this->brand_name; - } + $title = $this->get_title(); // Description - $description = $this->description; + $description = $this->get_description(); // Metadata - $metadata = array(); - foreach ($this->metadata as $name => $content) - { - if (strpos($name, 'og:') === 0) - { - $metadata[] = ''; - } - else - { - $metadata[] = ''; - } - } - $metadata = implode('', $metadata); + $metadata = $this->get_metadata(); // Javascript - $js = array(); - foreach ($this->js as $js_file) - { - $js[] = ''; - } - $js = implode('', $js); + $js = $this->get_js(); // CSS - $css = array(); - foreach ($this->css as $css_file) - { - $css[] = ''; - } - $css = implode('', $css); + $css = $this->get_css(); + // Layout + $layout = $this->get_layout(); + $header = $this->_ci->load->view('header', array(), TRUE); $footer = $this->_ci->load->view('footer', array(), TRUE); $main_content = $this->_ci->load->view($view, $data, TRUE); - $body = $this->_ci->load->view('layout/' . $this->layout, array( + $body = $this->_ci->load->view('layout/' . $layout, array( 'header' => $header, 'footer' => $footer, 'main_content' => $main_content, From 361f3ba1e41fc3f85a454534742ff53d8f5a63c5 Mon Sep 17 00:00:00 2001 From: souparno Date: Mon, 28 Sep 2015 21:53:42 +0530 Subject: [PATCH 3/4] converting the template attributes to individual class instances --- application/libraries/CSS.php | 27 +++ application/libraries/Description.php | 27 +++ application/libraries/JS.php | 27 +++ application/libraries/Layout.php | 26 +++ application/libraries/MetaData.php | 36 ++++ application/libraries/Template.php | 168 ++---------------- application/libraries/Title.php | 32 ++++ .../modules/addons/controllers/addons.php | 6 +- .../addons/data/ion_auth/controllers/auth.php | 4 +- .../jquery_file_upload/controllers/photo.php | 2 +- .../controllers/form_validation_example.php | 2 +- .../modules/skeleton/controllers/skeleton.php | 6 +- application/modules/todo/controllers/todo.php | 4 +- 13 files changed, 206 insertions(+), 161 deletions(-) create mode 100644 application/libraries/CSS.php create mode 100644 application/libraries/Description.php create mode 100644 application/libraries/JS.php create mode 100644 application/libraries/Layout.php create mode 100644 application/libraries/MetaData.php create mode 100644 application/libraries/Title.php diff --git a/application/libraries/CSS.php b/application/libraries/CSS.php new file mode 100644 index 0000000..ab16201 --- /dev/null +++ b/application/libraries/CSS.php @@ -0,0 +1,27 @@ +_css[$css] = $css; + } + + public function get() { + $css = array(); + foreach ($this->_css as $css_file) { + $css[] = ''; + } + return implode('', $css); + } +} diff --git a/application/libraries/Description.php b/application/libraries/Description.php new file mode 100644 index 0000000..41755e4 --- /dev/null +++ b/application/libraries/Description.php @@ -0,0 +1,27 @@ +_description = $description; + } + + public function get() { + if (empty($this->_description)) { + $this->_description = ''; + } + return $this->_description; + } + +} diff --git a/application/libraries/JS.php b/application/libraries/JS.php new file mode 100644 index 0000000..2d06df9 --- /dev/null +++ b/application/libraries/JS.php @@ -0,0 +1,27 @@ +_js[$js] = $js; + } + + public function get() { + $js = array(); + foreach ($this->_js as $js_file) { + $js[] = ''; + } + return implode('', $js); + } +} diff --git a/application/libraries/Layout.php b/application/libraries/Layout.php new file mode 100644 index 0000000..9efccda --- /dev/null +++ b/application/libraries/Layout.php @@ -0,0 +1,26 @@ +_layout = $_layout; + } + + public function get() { + if (empty($this->_layout)) { + $this->_layout = 'default'; + } + return $this->_layout; + } +} diff --git a/application/libraries/MetaData.php b/application/libraries/MetaData.php new file mode 100644 index 0000000..560bd8c --- /dev/null +++ b/application/libraries/MetaData.php @@ -0,0 +1,36 @@ +_metadata[$name] = $content; + } + + public function get() { + $metadata = array(); + foreach ($this->_metadata as $name => $content) { + if (strpos($name, 'og:') === 0) { + $metadata[] = ''; + } else { + $metadata[] = ''; + } + } + return implode('', $metadata); + } + +} diff --git a/application/libraries/Template.php b/application/libraries/Template.php index a1b25a2..18a12a2 100644 --- a/application/libraries/Template.php +++ b/application/libraries/Template.php @@ -9,156 +9,26 @@ class Template { private $_ci; - protected $brand_name = 'CodeIgniter Skeleton'; - protected $title_separator = ' - '; + protected $ga_id = FALSE; // UA-XXXXX-X - protected $layout; - - protected $title = FALSE; - protected $description = FALSE; - - protected $metadata = array(); - - protected $js = array(); - protected $css = array(); + public $layout; + public $title; + public $description; + public $metadata; + public $js; + public $css; function __construct() { $this->_ci =& get_instance(); - } - - /** - * Set page layout view (1 column, 2 column...) - * - * @access public - * @param string $layout - * @return void - */ - public function set_layout($layout) - { - $this->layout = $layout; - } - - /** - * Set page title - * - * @access public - * @param string $title - * @return void - */ - public function set_title($title) - { - $this->title = $title; - } - - /** - * Set page description - * - * @access public - * @param string $description - * @return void - */ - public function set_description($description) - { - $this->description = $description; - } - - /** - * Add metadata - * - * @access public - * @param string $name - * @param string $content - * @return void - */ - public function add_metadata($name, $content) - { - $name = htmlspecialchars(strip_tags($name)); - $content = htmlspecialchars(strip_tags($content)); - - $this->metadata[$name] = $content; - } - /** - * Add js file path - * - * @access public - * @param string $js - * @return void - */ - public function add_js($js) - { - $this->js[$js] = $js; - } - - /** - * Add css file path - * - * @access public - * @param string $css - * @return void - */ - public function add_css($css) - { - $this->css[$css] = $css; - } - - public function get_title() - { - if (empty($this->title)) { - $this->title = $this->brand_name;; - } else { - $this->title = $this->title . $this->title_separator . $this->brand_name; - } - return $this->title; - } - - public function get_description() - { - if (empty($this->description)) { - $this->description = ''; - } - return $this->description; - } - - public function get_metadata() - { - $metadata = array(); - foreach ($this->metadata as $name => $content) { - if (strpos($name, 'og:') === 0) { - $metadata[] = ''; - } else { - $metadata[] = ''; - } - } - return implode('', $metadata); - } - - public function get_js() - { - $js = array(); - foreach ($this->js as $js_file) { - $js[] = ''; - } - return implode('', $js); - } - - public function get_css() - { - $css = array(); - foreach ($this->css as $css_file) { - $css[] = ''; - } - return implode('', $css); - } - - public function get_layout() - { - if(empty($this->layout)) { - $this->layout = 'default'; - } - return $this->layout; + $this->layout = new Layout(); + $this->css = new CSS(); + $this->js = new JS(); + $this->title = new Title(); + $this->description = new Description(); + $this->metadata = new MetaData(); } /** @@ -180,22 +50,22 @@ public function load_view($view, $data = array(), $return = FALSE) } // Title - $title = $this->get_title(); + $title = $this->title->get(); // Description - $description = $this->get_description(); + $description = $this->description->get(); // Metadata - $metadata = $this->get_metadata(); + $metadata = $this->metadata->get(); // Javascript - $js = $this->get_js(); + $js = $this->css->get(); // CSS - $css = $this->get_css(); + $css = $this->js->get(); // Layout - $layout = $this->get_layout(); + $layout = $this->layout->get(); $header = $this->_ci->load->view('header', array(), TRUE); $footer = $this->_ci->load->view('footer', array(), TRUE); diff --git a/application/libraries/Title.php b/application/libraries/Title.php new file mode 100644 index 0000000..c878824 --- /dev/null +++ b/application/libraries/Title.php @@ -0,0 +1,32 @@ +_title = $title; + } + + public function get() { + if (empty($this->_title)) { + $this->_title = $this->_brand_name; + ; + } else { + $this->_title = $this->_title . $this->_title_separator . $this->_brand_name; + } + return $this->_title; + } + +} diff --git a/application/modules/addons/controllers/addons.php b/application/modules/addons/controllers/addons.php index efc17af..5acce29 100644 --- a/application/modules/addons/controllers/addons.php +++ b/application/modules/addons/controllers/addons.php @@ -6,9 +6,9 @@ public function index() { $this->load->library('template'); - $this->template->set_title('Add-ons'); - $this->template->add_js('modules/skeleton.js'); - $this->template->add_css('modules/skeleton.css'); + $this->template->title->set('Add-ons'); + $this->template->js->add('modules/skeleton.js'); + $this->template->css->add('modules/skeleton.css'); $addons = $this->load->config('addons/addons', TRUE); $data = array( diff --git a/application/modules/addons/data/ion_auth/controllers/auth.php b/application/modules/addons/data/ion_auth/controllers/auth.php index ddfd39f..65b2c82 100644 --- a/application/modules/addons/data/ion_auth/controllers/auth.php +++ b/application/modules/addons/data/ion_auth/controllers/auth.php @@ -767,12 +767,12 @@ function _render_page($view, $data=null, $render=false) if ( ! in_array($view, array('auth/index'))) { - $this->template->set_layout('pagelet'); + $this->template->layout->set('pagelet'); } if ( ! empty($data['title'])) { - $this->template->set_title($data['title']); + $this->template->title->set($data['title']); } $this->template->load_view($view, $data); diff --git a/application/modules/addons/data/jquery_file_upload/controllers/photo.php b/application/modules/addons/data/jquery_file_upload/controllers/photo.php index 747907e..e1696d3 100644 --- a/application/modules/addons/data/jquery_file_upload/controllers/photo.php +++ b/application/modules/addons/data/jquery_file_upload/controllers/photo.php @@ -6,7 +6,7 @@ public function upload() { $this->load->library('template'); - $this->template->set_title('Photo upload'); + $this->template->title->set('Photo upload'); $this->template->load_view('upload', array( 'pagelet_upload_control' => Modules::run('photo/_pagelet_upload_control') diff --git a/application/modules/addons/data/validate_js/controllers/form_validation_example.php b/application/modules/addons/data/validate_js/controllers/form_validation_example.php index e254094..a4762d0 100644 --- a/application/modules/addons/data/validate_js/controllers/form_validation_example.php +++ b/application/modules/addons/data/validate_js/controllers/form_validation_example.php @@ -6,7 +6,7 @@ public function index() { $this->load->library('template'); - $this->template->set_title('Form validation example'); + $this->template->title->set('Form validation example'); $this->template->load_view('form_validation_example/example_form', array( 'pagelet_example_form' => Modules::run('form_validation_example/_pagelet_example_form') diff --git a/application/modules/skeleton/controllers/skeleton.php b/application/modules/skeleton/controllers/skeleton.php index ca1cb3e..978decc 100644 --- a/application/modules/skeleton/controllers/skeleton.php +++ b/application/modules/skeleton/controllers/skeleton.php @@ -21,9 +21,9 @@ public function index() { $this->load->library('template'); - $this->template->set_title('Welcome'); - $this->template->add_js('modules/skeleton.js'); - $this->template->add_css('modules/skeleton.css'); + $this->template->title->set('Welcome'); + $this->template->js->add('modules/skeleton.js'); + $this->template->css->add('modules/skeleton.css'); $this->load->helper('file'); $skeleton_data = array(); diff --git a/application/modules/todo/controllers/todo.php b/application/modules/todo/controllers/todo.php index fb20ac2..35784c9 100644 --- a/application/modules/todo/controllers/todo.php +++ b/application/modules/todo/controllers/todo.php @@ -10,8 +10,8 @@ public function index() $this->load->library('template'); // Use custom layout (application/views/layout/pagelet.php) - $this->template->set_layout('pagelet'); - $this->template->set_title('Todo example'); + $this->template->layout->set('pagelet'); + $this->template->title->set('Todo example'); $this->template->load_view('todo/index', array( // Load todo pagelet with some fake items From a73951dd5d20ed3564c17d682c46fcac2787dea8 Mon Sep 17 00:00:00 2001 From: souparno Date: Tue, 20 Oct 2015 13:34:30 +0530 Subject: [PATCH 4/4] new classes created --- application/libraries/CSS.php | 2 +- application/libraries/JS.php | 2 +- application/libraries/Layout.php | 2 +- tests/bootstrap.php | 6 +++--- tests/mocks/autoloader.php | 10 +++++++--- tests/phpunit.xml | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/application/libraries/CSS.php b/application/libraries/CSS.php index ab16201..9c82963 100644 --- a/application/libraries/CSS.php +++ b/application/libraries/CSS.php @@ -4,7 +4,7 @@ class CSS { - private $_css = array(); + protected $_css = array(); /** * Add css file path diff --git a/application/libraries/JS.php b/application/libraries/JS.php index 2d06df9..6b793ce 100644 --- a/application/libraries/JS.php +++ b/application/libraries/JS.php @@ -4,7 +4,7 @@ class JS { - private $_js = array(); + protected $_js = array(); /** * Add js file path diff --git a/application/libraries/Layout.php b/application/libraries/Layout.php index 9efccda..2c737c0 100644 --- a/application/libraries/Layout.php +++ b/application/libraries/Layout.php @@ -4,7 +4,7 @@ class Layout { - private $_layout; + protected $_layout; /** * Set page layout view (1 column, 2 column...) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3bfedf5..79410f4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -38,9 +38,9 @@ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Prep our test environment -include_once $dir.'/mocks/core/common.php'; -include_once SYSTEM_PATH.'core/Common.php'; +//include_once $dir.'/mocks/core/common.php'; +//include_once SYSTEM_PATH.'core/Common.php'; include_once $dir.'/mocks/autoloader.php'; spl_autoload_register('autoload'); -unset($dir); \ No newline at end of file +unset($dir); diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 725954a..257fe9e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -11,7 +11,11 @@ // and so on... function autoload($class) { - $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; + + var_dump("==".$class."==\n"); + + + /*$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; $ci_core = array( 'Benchmark', 'Config', 'Controller', @@ -92,5 +96,5 @@ function autoload($class) return FALSE; } - include_once($file); -} \ No newline at end of file + include_once($file);*/ +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index b7b79b5..ebfdea5 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,8 +7,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false" -> + stopOnSkipped="false"> + ./cis