Skip to content

Commit

Permalink
remove addTemplate(), getTemplates() View methods
Browse files Browse the repository at this point in the history
  • Loading branch information
1f7 committed Mar 4, 2017
1 parent bbffb80 commit 858dbf8
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 48 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified composer.json
100644 → 100755
Empty file.
Empty file modified phpcs.xml
100644 → 100755
Empty file.
Empty file modified src/PdfRenderer.php
100644 → 100755
Empty file.
30 changes: 18 additions & 12 deletions src/PhpRenderer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,17 @@ public function getTemplate($file)
}

/**
* @param string $template
* @param bool $nested
* @return mixed
* @return array|string
* @throws \Exception
* @throws \Throwable
*/
public function display($nested = true)
public function render($template = '', $nested = true)
{
$data = [
// 'nested' => $nested
];
$data = array_merge($this->getDefaultPageInfo(), $this->all(), (array) $data);

$data = $this->getPageData();
$data = Container::get('hooks')->fire('view.alter_data', $data);

$templates = $this->getTemplates();
$tpl = trim(array_pop($templates));// get last in array
list($namespace, $shortname) = $this->parseName($tpl);
list($namespace, $shortname) = $this->parseName($template);
//dump($namespace);
try {
ob_start();
Expand All @@ -102,7 +96,19 @@ public function display($nested = true)
throw $e;
}

Response::getBody()->write($output);
return $output;
}

/**
* @param string $template
* @param bool $nested
* @return mixed
*/
public function display($template = '', $nested = true)
{
Response::getBody()->write(
$this->render($nested)
);
return Container::get('response');
}

Expand Down
Empty file modified src/Renderer.php
100644 → 100755
Empty file.
Empty file modified src/TwigExtension.php
100644 → 100755
Empty file.
28 changes: 16 additions & 12 deletions src/TwigRenderer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()
$this->loader = new \Twig_Loader_Filesystem();
$this->twig = new \Twig_Environment($this->loader, [
'cache' => ForumEnv::get('FORUM_CACHE_DIR') . 'twig',
'debug' => true,
'debug' => ForumEnv::get('FEATHER_DEBUG'),
]);
// load extensions
if (ForumEnv::get('FEATHER_DEBUG')) {
Expand All @@ -50,24 +50,28 @@ public function addTemplatesDirectory($dir = '', $alias = 'forum')
}

/**
* @param string $template
* @param bool $nested
* @return mixed
* @return string
*/
public function display($nested = true)
public function render($template = '', $nested = true)
{
$data = [
'nested' => $nested
];
$data = array_merge($this->getDefaultPageInfo(), $this->all(), (array) $data);
$data = $this->getPageData();
$data['nested'] = $nested;
$data = Container::get('hooks')->fire('view.alter_data', $data);

// TODO set template to display method?
$templates = $this->getTemplates();
$tpl = trim(array_pop($templates));// get last in array

return $this->twig->render($template . '.html.twig', $data);
}

/**
* @param string $template
* @param bool $nested
* @return mixed
*/
public function display($template = '', $nested = true)
{
Response::getBody()->write(
$this->twig->render($tpl. '.html.twig', $data)
$this->render($template, $nested)
);
return Container::get('response');
}
Expand Down
50 changes: 26 additions & 24 deletions src/View.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,30 @@ public function addAsset($type, $asset, $params = [])
// return $this->assets;
// }

public function addTemplate($tpl, $priority = 10)
{
$tpl = (array) $tpl;
foreach ($tpl as $key => $tpl_file) {
$this->templates[(int) $priority][] = (string) $tpl_file;
}
return $this;
}
// public function addTemplate($tpl, $priority = 10)
// {
// $tpl = (array) $tpl;
// foreach ($tpl as $key => $tpl_file) {
// $this->templates[(int) $priority][] = (string) $tpl_file;
// }
// return $this;
// }

public function getTemplates()
{
$output = [];
if (count($this->templates) > 1) {
ksort($this->templates);
}
foreach ($this->templates as $priority) {
if (!empty($priority)) {
foreach ($priority as $tpl) {
$output[] = $tpl;
}
}
}
return $output;
}
// public function getTemplates()
// {
// $output = [];
// if (count($this->templates) > 1) {
// ksort($this->templates);
// }
// foreach ($this->templates as $priority) {
// if (!empty($priority)) {
// foreach ($priority as $tpl) {
// $output[] = $tpl;
// }
// }
// }
// return $output;
// }

public function addMessage($msg, $type = 'info')
{
Expand All @@ -166,7 +166,7 @@ public function addMessage($msg, $type = 'info')
}
}

public function getDefaultPageInfo()
public function getPageData()
{
// Check if config file exists to avoid error when installing forum
if (!Container::get('cache')->isCached('quickjump') && is_file(ForumEnv::get('FORUM_CONFIG_FILE'))) {
Expand Down Expand Up @@ -237,6 +237,8 @@ public function getDefaultPageInfo()
$data['exec_info'] = \RunBB\Model\Debug::getInfo();
}
}
$data = array_merge($data, $this->all());

$data['pageTitle'] = Utils::generatePageTitle($data['title'], $data['page_number']);
$data['navlinks'] = $this->buildNavLinks($data['active_page']);

Expand Down

0 comments on commit 858dbf8

Please sign in to comment.