From 12a7db25e38e1e4519fc29b0fe55a043a09578d6 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Fri, 21 Feb 2014 13:53:42 +0700 Subject: [PATCH] DAR-18: HTML message layouts --- application/classes/Controller/Letter.php | 12 ++++++ application/classes/Model/Letter.php | 4 +- application/classes/View/Letter/Index.php | 2 +- application/classes/View/Letter/View.php | 46 ++++++++++++++++++++++ application/templates/email.mustache | 20 ++++++++++ application/templates/letter/view.mustache | 1 + modules/less | 2 +- 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 application/classes/View/Letter/View.php create mode 100644 application/templates/email.mustache create mode 100644 application/templates/letter/view.mustache diff --git a/application/classes/Controller/Letter.php b/application/classes/Controller/Letter.php index 8f1a915..80a6ecb 100644 --- a/application/classes/Controller/Letter.php +++ b/application/classes/Controller/Letter.php @@ -63,4 +63,16 @@ class Controller_Letter extends Controller_Layout { $this->redirect('/'); } } + + public function action_view() + { + $id = $this->request->param('id'); + $model = ORM::factory('Letter', $id); + if (!$model->loaded()) + { + $this->redirect('error/404'); + } + $this->template = new View_Letter_View; + $this->template->content = $model->text; + } } diff --git a/application/classes/Model/Letter.php b/application/classes/Model/Letter.php index 6ea971d..269025b 100644 --- a/application/classes/Model/Letter.php +++ b/application/classes/Model/Letter.php @@ -68,7 +68,9 @@ class Model_Letter extends ORM { { Log::instance()->add(Log::NOTICE, __('Sending letter with subject "%subject" to address %address', array('%subject' => $subject, '%address' => $address))); $sender = Kohana::$config->load('email')->get('sender'); - $email = Email::factory($subject, $text)->from($sender[0], $sender[1]); + $template = new View_Letter_View; + $renderer = Kostache_Layout::factory($template->_layout); + $email = Email::factory($subject, $renderer->render($template, $template->_view))->from($sender[0], $sender[1]); if (is_array($address)) { $email->bcc($address); diff --git a/application/classes/View/Letter/Index.php b/application/classes/View/Letter/Index.php index ff1cd0c..14f60ef 100644 --- a/application/classes/View/Letter/Index.php +++ b/application/classes/View/Letter/Index.php @@ -21,7 +21,7 @@ class View_Letter_Index extends View_Index { $output = array( 'description' => $item->text, - 'view_link' => $item->subject,//HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)), $item->subject, array('class' => 'link_view')), + 'view_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'view','id' => $item->id)), $item->subject, array('class' => 'link_view')), 'edit_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit')), 'delete_link' => HTML::anchor(Route::url('default', array('controller' => 'Letter', 'action' => 'delete','id' => $item->id)), __('Delete'), array('class' => 'link_delete')), ); diff --git a/application/classes/View/Letter/View.php b/application/classes/View/Letter/View.php new file mode 100644 index 0000000..8bd1fc5 --- /dev/null +++ b/application/classes/View/Letter/View.php @@ -0,0 +1,46 @@ +render($this->content); + } + + public function scripts() + { + $scripts = $this->scripts; + $temp = ""; + foreach($scripts as $script): + if (strstr($script, '://') === FALSE) //no protocol given, script is local + { + if ($script === 'jquery') // CDN shortcut + { + $temp .= HTML::script('https://yandex.st/jquery/2.0.3/jquery.min.js')."\n"; + } + else + { + $temp .= HTML::script('application/assets/javascript/'.$script)."\n"; + } + } + else + { + $temp .= HTML::script($script)."\n"; + } + endforeach; + return $temp; + } +} diff --git a/application/templates/email.mustache b/application/templates/email.mustache new file mode 100644 index 0000000..817bd39 --- /dev/null +++ b/application/templates/email.mustache @@ -0,0 +1,20 @@ + + + + {{title}} + + + + + +
+
+

{{title}}

+{{>content}} +
+
+{{{scripts}}} + + diff --git a/application/templates/letter/view.mustache b/application/templates/letter/view.mustache new file mode 100644 index 0000000..b92f652 --- /dev/null +++ b/application/templates/letter/view.mustache @@ -0,0 +1 @@ +{{content}} diff --git a/modules/less b/modules/less index aaffc1b..19e6149 160000 --- a/modules/less +++ b/modules/less @@ -1 +1 @@ -Subproject commit aaffc1b4eaf878e975f8ce9933cf4b34e72b42e3 +Subproject commit 19e61497e200316d66be75ae8ae0b2074761769b