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/ diff --git a/application/libraries/CSS.php b/application/libraries/CSS.php new file mode 100644 index 0000000..9c82963 --- /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..6b793ce --- /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..2c737c0 --- /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 cc4bf3c..18a12a2 100644 --- a/application/libraries/Template.php +++ b/application/libraries/Template.php @@ -9,99 +9,26 @@ class Template { private $_ci; - protected $brand_name = 'CodeIgniter Skeleton'; - protected $title_separator = ' - '; + protected $ga_id = FALSE; // UA-XXXXX-X - protected $layout = 'default'; - - 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; + $this->layout = new Layout(); + $this->css = new CSS(); + $this->js = new JS(); + $this->title = new Title(); + $this->description = new Description(); + $this->metadata = new MetaData(); } /** @@ -123,54 +50,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->title->get(); // Description - $description = $this->description; + $description = $this->description->get(); // Metadata - $metadata = array(); - foreach ($this->metadata as $name => $content) - { - if (strpos($name, 'og:') === 0) - { - $metadata[] = ''; - } - else - { - $metadata[] = ''; - } - } - $metadata = implode('', $metadata); + $metadata = $this->metadata->get(); // Javascript - $js = array(); - foreach ($this->js as $js_file) - { - $js[] = ''; - } - $js = implode('', $js); + $js = $this->css->get(); // CSS - $css = array(); - foreach ($this->css as $css_file) - { - $css[] = ''; - } - $css = implode('', $css); + $css = $this->js->get(); + // Layout + $layout = $this->layout->get(); + $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, 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 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