mirror of
https://github.com/Oreolek/oreolek.ru.git
synced 2024-05-17 16:38:22 +03:00
Testdrive: logic-less templates
This commit is contained in:
parent
6aebac434d
commit
9b6166f850
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -22,3 +22,6 @@
|
|||
[submodule "ko3-markdown"]
|
||||
path = modules/markdown
|
||||
url = git://github.com/Oreolek/kohana-markdown.git
|
||||
[submodule "modules/kostache"]
|
||||
path = modules/kostache
|
||||
url = git://github.com/zombor/KOstache.git
|
||||
|
|
|
@ -106,13 +106,14 @@ Cookie::$salt = 'Dz75cE_TgeDXvo2';
|
|||
* Enable modules. Modules are referenced by a relative or absolute path.
|
||||
*/
|
||||
Kohana::modules(array(
|
||||
'auth' => MODPATH.'auth', // Basic authentication
|
||||
'database' => MODPATH.'database', // Database access
|
||||
'orm' => MODPATH.'orm', // Object Relationship Mapping
|
||||
'markdown' => MODPATH.'markdown', // Markdown module
|
||||
'less' => MODPATH.'less', // LEaner CSS
|
||||
'debug-toolbar' => MODPATH.'debug-toolbar', // Debug toolbar
|
||||
'image' => MODPATH.'image', // Image manipulation
|
||||
'auth' => MODPATH.'auth', // Basic authentication
|
||||
'database' => MODPATH.'database', // Database access
|
||||
'orm' => MODPATH.'orm', // Object Relationship Mapping
|
||||
'markdown' => MODPATH.'markdown', // Markdown module
|
||||
'less' => MODPATH.'less', // LEaner CSS
|
||||
'debug-toolbar' => MODPATH.'debug-toolbar', // Debug toolbar
|
||||
'image' => MODPATH.'image', // Image manipulation
|
||||
'kostache' => MODPATH.'kostache', // Logic-less Mustache views
|
||||
// 'cache' => MODPATH.'cache', // Caching with multiple backends
|
||||
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
|
||||
// 'unittest' => MODPATH.'unittest', // Unit testing
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Controller_Layout extends Controller_Template {
|
||||
class Controller_Layout extends Controller {
|
||||
protected $secure_actions = FALSE;
|
||||
public function before()
|
||||
{
|
||||
|
@ -21,9 +21,5 @@ class Controller_Layout extends Controller_Template {
|
|||
$this->redirect('user/signin');
|
||||
}
|
||||
}
|
||||
if ($this->auto_render)
|
||||
{
|
||||
$this->template->footer = Request::factory('footer/standard')->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,15 +118,14 @@ class Controller_Post extends Controller_Layout {
|
|||
|
||||
public function action_index()
|
||||
{
|
||||
$this->template = new View('index');
|
||||
$this->template->header = Request::factory('header/standard')->post('title','Содержание')->execute();
|
||||
$this->template->is_admin = Auth::instance()->logged_in('admin');
|
||||
$this->template->show_date = TRUE;
|
||||
$this->template->items = ORM::factory('Post')
|
||||
$view = new View_Index;
|
||||
$view->show_date = TRUE;
|
||||
$view->items = ORM::factory('Post')
|
||||
->where('is_draft', '=', '0')
|
||||
->order_by('posted_at', 'DESC')
|
||||
->find_all();
|
||||
$this->template->footer = Request::factory('footer/standard')->execute();
|
||||
->find_all();
|
||||
$renderer = Kostache::factory();
|
||||
$this->response->body($renderer->render($view));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
73
application/classes/View/Index.php
Normal file
73
application/classes/View/Index.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Контроллер вида оглавлений
|
||||
**/
|
||||
class View_Index {
|
||||
public $show_date = TRUE;
|
||||
public $items = NULL;
|
||||
|
||||
public function get_items()
|
||||
{
|
||||
$result = array();
|
||||
$colwidth = $this->view_link_colwidth();
|
||||
$is_admin = Auth::instance()->logged_in('admin');
|
||||
if (is_null($this->items))
|
||||
{
|
||||
return NULL;
|
||||
};
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
$output = array(
|
||||
'date' => '',
|
||||
'edit_link' => '',
|
||||
'view_link' => '',
|
||||
'delete_link' => '',
|
||||
);
|
||||
if ($this->show_date)
|
||||
{
|
||||
$output['date'] = $item->creation_date();
|
||||
}
|
||||
$output['view_link'] = '<a class = "link_view column'.$colwidth.'" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'view','id' => $item->id)).'">'.$item->name.'</a>';
|
||||
if ($is_admin)
|
||||
{
|
||||
$output['edit_link'] = '<a class = "link_edit" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'edit','id' => $item->id)).'">Редактировать</a>';
|
||||
$output['delete_link'] = '<a class = "link_delete" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'delete','id' => $item->id)).'">Удалить</a>';
|
||||
}
|
||||
array_push($result, $output);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function header()
|
||||
{
|
||||
return Request::factory('header/standard')->post('title','Содержание')->execute();
|
||||
}
|
||||
|
||||
public function footer()
|
||||
{
|
||||
return Request::factory('footer/standard')->execute();
|
||||
}
|
||||
|
||||
protected function view_link_colwidth()
|
||||
{
|
||||
$columns = 3;
|
||||
if (!$this->show_date)
|
||||
{
|
||||
$columns++;
|
||||
}
|
||||
if (!Auth::instance()->logged_in('admin'))
|
||||
{
|
||||
$columns = $columns + 2;
|
||||
}
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function link_new()
|
||||
{
|
||||
if (Auth::instance()->logged_in('admin'))
|
||||
{
|
||||
return '<a href="'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'create')).'" class="link_new">Добавить</a>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
17
application/templates/index.mustache
Normal file
17
application/templates/index.mustache
Normal file
|
@ -0,0 +1,17 @@
|
|||
{{{header}}}
|
||||
|
||||
{{{link_new}}}
|
||||
<div class="table_index">
|
||||
{{#get_items}}
|
||||
<div class="table_row">
|
||||
{{#date}}
|
||||
<div class="date">{{date}}</div>
|
||||
{{/date}}
|
||||
{{{view_link}}}
|
||||
{{{edit_link}}}
|
||||
{{{delete_link}}}
|
||||
</div>
|
||||
{{/get_items}}
|
||||
</div>
|
||||
|
||||
{{{footer}}}
|
|
@ -1,39 +0,0 @@
|
|||
<?php echo $header; ?>
|
||||
|
||||
<?php
|
||||
if ($is_admin)
|
||||
{
|
||||
echo '<a href="'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'create')).'" class="link_new">Добавить</a>';
|
||||
}
|
||||
?>
|
||||
<div class="table_index">
|
||||
<?php
|
||||
$columns = 3;
|
||||
if (!isset($show_date) OR $show_date != TRUE)
|
||||
{
|
||||
$columns++;
|
||||
}
|
||||
if (!$is_admin)
|
||||
{
|
||||
$columns = $columns + 2;
|
||||
}
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
echo '<div class="table_row">';
|
||||
if (isset($show_date) AND $show_date === TRUE)
|
||||
{
|
||||
echo '<div class="date">'. $item->creation_date() .'</div>';
|
||||
}
|
||||
echo '<a class = "link_view column'.$columns.'" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'view','id' => $item->id)).'">' . $item->name . '</a>';
|
||||
if ($is_admin)
|
||||
{
|
||||
echo '<a class = "link_edit" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'edit','id' => $item->id)).'">Редактировать</a>';
|
||||
echo '<a class = "link_delete" href = "'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'delete','id' => $item->id)).'">Удалить</a>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php echo $footer; ?>
|
1
modules/kostache
Submodule
1
modules/kostache
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit d7db6778dc9ee8b26487ef5336c31c05c9fd1b48
|
Loading…
Reference in a new issue