Skip to content

Commit

Permalink
Several additions:
Browse files Browse the repository at this point in the history
  - Altered config handling. Deleted all dot-notation stuff and used
    the config like it should with Kohana 3.2
  - Added a pre-render method for stuff that needs to be done after
    setting the config array but before rendering of the view
  • Loading branch information
Luwe committed Aug 20, 2011
1 parent 9c8c38f commit 47f857e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
42 changes: 26 additions & 16 deletions classes/ljcore/view/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,39 @@
*/
abstract class Ljcore_View_Core extends Kostache_Layout {

/**
* Holds the config array
* @var array
*/
public $config;

/**
* Config file to get initial layout settings from
* @var string
*/
protected $_layout_config = 'website';
protected $_config_file = 'website';

/**
* Add initial settings from a config file to an existing array
*
* @param mixed array to prepend initial settings to
* @param mixed config file
* @param mixed config variable (dotnotation enabled type.subtype etc.)
* @return array
* Overloaded render method to include config setting and pre_rendering
*
* @return string
*/
protected function _add_initial_settings(array $var, $type = 'css')
public function render()
{
$type = ($type) ? '.'. (string) $type : '';

// Check if initial array exists, otherwise send back original $var
if ( ! ($initial = Kohana::$config->load($this->_layout_config.$type)))
return $var;
$this->config = Kohana::$config->load($this->_config_file)->as_array();
$this->pre_render();

return parent::render();
}

return array_merge($initial, $var);
/**
* Pre-render method
*
* @return void
*/
public function pre_render()
{
// Everything that needs to happen after config, but before rendering
}

}
18 changes: 8 additions & 10 deletions classes/ljcore/view/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class Ljcore_View_Default extends View_Core {
*/
public function title()
{
return (string) Kohana::$config->load($this->_layout_config.'.title');
return (string) $this->config['title'];
}

/**
Expand All @@ -46,8 +46,8 @@ public function title()
*/
public function favicon()
{
return URL::site(Kohana::$config->load('media.images')
.Kohana::$config->load($this->_layout_config.'.favicon'), NULL, FALSE);
return URL::site(Kohana::$config->load('media')->get('images')
.$this->config['favicon'], NULL, FALSE);
}

/**
Expand All @@ -58,11 +58,10 @@ public function favicon()
public function scripts()
{
// Add initial global scripts
$this->_scripts = $this->_add_initial_settings($this->_scripts, 'files.js');

$raw = $this->config['files']['js'] + $this->_scripts;
$scripts = array();

foreach ($this->_scripts as $file)
foreach ($raw as $file)
{
$file = $this->_format_media_uri($file, 'js');
$scripts[] = $file;
Expand All @@ -79,11 +78,10 @@ public function scripts()
public function stylesheets()
{
// Add initial global stylesheets
$this->_stylesheets = $this->_add_initial_settings($this->_stylesheets, 'files.css');

$raw = $this->config['files']['css'] + $this->_stylesheets;
$stylesheets = array();

foreach ($this->_stylesheets as $stylesheet)
foreach ($raw as $stylesheet)
{
$file = $this->_format_media_uri($stylesheet['file'], 'css');
$stylesheets[] = array('file' => $file, 'media' => $stylesheet['media']);
Expand All @@ -108,7 +106,7 @@ protected function _format_media_uri($file, $extension = 'css')
// Check if filename has protocol
if ( ! strchr($file, '://'))
{
$file = URL::site(Kohana::$config->load('media.'.$extension).$file, NULL, FALSE);
$file = URL::site(Kohana::$config->load('media')->get($extension).$file, NULL, FALSE);
}

return $file;
Expand Down

0 comments on commit 47f857e

Please sign in to comment.