/** * {@inheritdoc} */ protected function fire() { $commandName = $this->argument('command_name'); $commandDescription = $this->option('description'); $hasArguments = $this->option('arguments'); $hasOptions = $this->option('options'); $namespace = $this->option('namespace'); // where to create the file, default to current directory $path = $this->argument('path') ?: '.'; // make sure it has a trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; // split command into individual words $words = preg_split('/[:-_]/', $commandName); // camel case $words = array_map(function ($word) { return mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1); }, $words); $className = implode('', $words); $handlebars = new Handlebars(array('loader' => new FilesystemLoader(__DIR__ . '/../templates/'))); $destination = $path . $className . 'Command.php'; $handle = fopen($destination, 'w'); $output = $handlebars->render('Command.php', array('className' => $className, 'commandName' => $commandName, 'commandDescription' => $commandDescription, 'hasArguments' => $hasArguments, 'hasOptions' => $hasOptions, 'namespace' => $namespace)); fwrite($handle, $output); fclose($handle); $this->info($destination . ' created.'); }
public function renderHbs($templateName, array $params = [], $inlineCss = false) { $html = $this->handlebars->render($templateName, $params); if ($inlineCss) { $html = $this->cssToInlineStyles->convert($html); } return $html; }
/** * {@inheritdoc} */ public function present(Presentation $presentation) { $layout = $this->theme->getLayout(); foreach ($presentation->slides as $slide) { $this->renderSlide($slide); } $out = $this->hbs->render($layout, ['title' => $presentation->title, 'subtitle' => $presentation->subtitle, 'date' => $presentation->date->toString(), 'presenters' => $presentation->authors, 'license' => $presentation->license, 'theme_settings' => $presentation->themeSettings, 'slides' => $presentation->slides->getAll()]); return $out; }
public function template(&$_class) { $engine = new Handlebars(array('loader' => new \Handlebars\Loader\FilesystemLoader(__DIR__ . '/tpl/'))); $result = array(); $sourceCode = $engine->render('objch', $_class); $_poxo = new Source(); $_poxo->setFileName($_class->getName() . ".h"); $_poxo->setSourceCode($sourceCode); array_push($result, $_poxo); $sourceCode = $engine->render('objcm', $_class); $_poxo = new Source(); $_poxo->setFileName($_class->getName() . ".m"); $_poxo->setSourceCode($sourceCode); array_push($result, $_poxo); return $result; }
public function template(&$_class) { $engine = new Handlebars(array('loader' => new \Handlebars\Loader\FilesystemLoader(__DIR__ . '/tpl/'))); $_poxo = new Source(); $result = $engine->render('java', $_class); $_poxo->setFileName($_class->getName() . ".java"); $_poxo->setSourceCode($result); return array($_poxo); }
/** * returns rendered content * * @param string $content input content * @param array $data additional data to be passed into render context * @param array $options an array with additional options * helpers => Helpers object * escape => a callable function to escape values * escapeArgs => array to pass as extra parameter to escape function * loader => Loader object * partials_loader => Loader object * cache => Cache object * @return string content as given * @filter */ public function get($content, $data = array(), array $options = array()) { $defaults = array('allowed' => true); $options += $defaults; $params = compact('content', 'data', 'options'); return $this->_filter(__METHOD__, $params, function ($self, $params) { $renderer = new Renderer($params['options']); return $renderer->render($params['content'], $params['data']); }); }
/** * @param $value * @param $i * * @return mixed */ protected function replaceNumbersInString($value, $i) { if (!is_string($value)) { return $value; } $thisTemplateData = array_merge($this->templateData, ['n' => $i]); array_walk($thisTemplateData, function (&$value) use($i) { $value = is_callable($value) ? $value($i) : $value; }); return $this->handlebars->render($value, $thisTemplateData); }
public function get($path, array $data = array()) { $path = basename($path); $app = app(); //$config = $app['config']->get('handlebars-l4::config'); $m = new Handlebars(array('loader' => new \Handlebars\Loader\FilesystemLoader(app_path() . '/views/', array('extension' => '.hbs.php')), 'partials_loader' => new \Handlebars\Loader\FilesystemLoader(app_path() . '/views/', array('extension' => '.hbs.php', 'prefix' => '_')))); $data = array_map(function ($item) { return is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : $item; }, $data); return $m->render($path, $data); }
/** * Render a file from a Handlebars template * @param string $template name of template * @param string $destination where to save the file * @return void */ protected function template($template, $destination) { $output = $this->handlebars->render($template, $this->vars); if (file_exists($destination) && !$this->confirm($destination . ' already exists. Do you want to overwrite? ', false)) { $this->error(basename($destination) . ' not created.'); return; } $handle = fopen($destination, 'w'); fwrite($handle, $output); fclose($handle); $this->comment(basename($destination) . ' created.'); }
public function get($path, array $data = array()) { $view = $this->files->get($path); $app = app(); $options = array(); $handlebars_config = $app['config']->get('handlebars-l4::config'); if (isset($handlebars_config['partials_loader'])) { $options['partials_loader'] = $handlebars_config['partials_loader']; } if (isset($handlebars_config['helpers']) && is_array($handlebars_config['helpers'])) { $options['helpers'] = new Helpers($handlebars_config['helpers']); } $engine = new Handlebars($options); $data = array_map(function ($item) { return is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : $item; }, $data); return $engine->render($view, $data); }
/** * {@inheritdoc} */ protected function fire() { // where to create the file, default to current directory $path = $this->argument('path') ?: '.'; // make sure it has a trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $handlebars = new Handlebars(array('loader' => new FilesystemLoader(__DIR__ . '/../templates/'))); $destination = $path . '.htaccess'; if (file_exists($destination)) { $path = realpath($path) . DIRECTORY_SEPARATOR; $confirmed = $this->confirm("An .htaccess file already exists in {$path}. Do you want to overwrite? [yN] ", false); if (!$confirmed) { $this->info('Did not create .htaccess file.'); return; } } $handle = fopen($destination, 'w'); $output = $handlebars->render('htaccess', array('systemFolder' => $this->getApplication()->getSystemFolder())); fwrite($handle, $output); fclose($handle); $this->info($destination . ' created.'); }
// Save the file $data = removeNonIntSections($_POST); $data = removeEmptyPasswords($data); $fonb->write_users($data); prepareContext(); header("Location: users.php"); exit; } ### VIEW the edit user form // Creat the listusers object $Json = array(); $Json['Extensions'] = MustacheReformatExtensions(getExtensions()); $Json['NoExtensionErrorMessage'] = getNoExtensionErrorMessage(); $Json['RingGroups'] = getRingGroups(); $Json['Queues'] = getQueues(); $Json['DeletedExtensions'] = getDeletedExtensions(); $Json['License'] = $fonb->getTotalUsersAllowed(); // Get the Handlebars Template $UsersTemplateFilePath = realpath("../templates/admin/users.html"); if ($UsersTemplateFilePath === false) { // Error exit("Template users.html was not found"); } $UsersTemplate = file_get_contents($UsersTemplateFilePath); // Last step, output the html file require 'Handlebars/Autoloader.php'; Handlebars\Autoloader::register(); use Handlebars\Handlebars; $engine = new Handlebars(); echo $engine->render($UsersTemplate, $Json); //var_dump ( $Json );
$data = removeUnnecessaryKeys($_POST, $fonbconfig); $data = array_merge($fonbconfig, $data); unset($data['WebSocket']); $fonb->write_phoneb($data); header("Location: config.php"); exit; } ### UPDATE button if (isset($_POST['action']) && $_POST['action'] == "SAVE") { // Save the file $data = removeUnnecessaryKeys($_POST, $fonbconfig); $data = array_merge($fonbconfig, $data); $fonb->write_phoneb($data); header("Location: config.php"); exit; } ### VIEW the edit user form // Get the Handlebars Template $ConfigTemplateFilePath = realpath("../templates/admin/config.html"); if ($ConfigTemplateFilePath === false) { // Error exit("Template config.html was not found"); } $ConfigTemplate = file_get_contents($ConfigTemplateFilePath); // Last step, output the html file require 'Handlebars/Autoloader.php'; Handlebars\Autoloader::register(); use Handlebars\Handlebars; $engine = new Handlebars(); echo $engine->render($ConfigTemplate, $fonbconfig);
public function render() { $engine = new Handlebars(array('loader' => new \Handlebars\Loader\FilesystemLoader(__DIR__ . '/templates/'))); return $engine->render($this->template, $this->context); }
public function getContents() { return $this->handlebars->render($this->template, $this->data); }
public function getBlogDropQuery($tablePrefix, $blogId) { $template = $this->templates('drop-blog-tables'); $data = ['prefix' => $tablePrefix, 'blog_id' => $blogId]; return $this->handlebars->render($template, $data); }
/** * Renders the given handlebars template * * @param string $template Template location * @param array $data Data being passed to the renderer * * @return string */ public function render($template, array $data = array()) { return $this->handlebarsRenderingEngine->render($template, $data); }
$extendata = $_POST['data']; update_SpeedDial($extendata); header("Location: speeddials.php"); exit; } ### DELETE link if (isset($_GET['action']) && $_GET['action'] == "DELETE") { $id = $_GET['id']; delete_SpeedDial($id); header("Location: speeddials.php"); exit; } ### VIEW the edit user form // Creat the listusers object $Json = array(); $Json['SpeedDials'] = getSpeedDials(); //print_r($Json); // Get the Handlebars Template $SpeedDialsTemplateFilePath = realpath("../templates/admin/speeddials.html"); if ($SpeedDialsTemplateFilePath === false) { // Error exit("Template users.html was not found"); } $SpeedDialsTemplate = file_get_contents($SpeedDialsTemplateFilePath); // Last step, output the html file require 'Handlebars/Autoloader.php'; Handlebars\Autoloader::register(); use Handlebars\Handlebars; $engine = new Handlebars(); echo $engine->render($SpeedDialsTemplate, $Json);
// Filesystem's options $partialsLoader = new FilesystemLoader($themePath, ['extension' => 'html']); // init Handlebars $engine = new Handlebars(['loader' => $partialsLoader, 'partials_loader' => $partialsLoader]); // Handelbars Helpers instance $helpers = new \JustBlackBird\HandlebarsHelpers\Helpers(); // init Handlebars $engine = new Handlebars(['loader' => $partialsLoader, 'partials_loader' => $partialsLoader, 'helpers' => $helpers]); $nativeHelpers = Config::get('frontage::helpers'); // Load Subbly's native Helpers foreach ($nativeHelpers as $key => $class) { $engine->addHelper($key, new $class()); } # Will render the model to the templates/main.tpl template // TODO: add cache return $engine->render($tpl, $data); }); } /* * Exception handling */ App::missing(function ($exception) { exit('404'); // return Response::view('errors.missing', array(), 404); }); App::error(function (MethodNotAllowedHttpException $exception) { exit('503'); }); // TODO: custom error page App::error(function (FrontageInvalidHelperException $exception) { exit($exception->getMessage());
header("Location: users.php"); exit; } ### VIEW the edit user form $id = $_GET["id"]; if (empty($id)) { header("Location: speeddials.php"); exit; } $Json = array(); $Json['SpeedDial'] = getSpeedDial($id); if ($_GET['encode'] == 'json') { echo json_encode($Json); exit; } // Get the Handlebars Template $EditSpeedDialTemplateFilePath = realpath("../templates/admin/editspeeddial.html"); if ($EditSpeedDialTemplateFilePath === false) { // Error exit("Template edituser.html was not found"); } $EditSpeedDialTemplate = file_get_contents($EditSpeedDialTemplateFilePath); // Last step, output the html file require 'Handlebars/Autoloader.php'; Handlebars\Autoloader::register(); use Handlebars\Handlebars; $engine = new Handlebars(); echo $engine->render($EditSpeedDialTemplate, $Json); ?>
/** * @return string */ public function render() { return $this->engine->render($this->template, $this->data); }
### VIEW the edit user form // Creat the listusers object $Json = array(); $Json['EditExtension'] = $users[$exten]; $Json['EditExtension']['Platform'] = GetPlatform(); $Json['Departments'] = $fonb->getDepartments(); //$Json['RingGroups'] = getRingGroups(); $Json['RingGroups'] = RingGroupsOf($exten); //$Json['Queues'] = getQueues(); $Json['Queues'] = QueuesOf($exten); $Json['DeletedExtensions'] = getDeletedExtensions(); $Json['Extensions'] = MustacheReformatExtensions(getExtensions()); $Json['License'] = $fonb->getTotalUsersAllowed(); if ($_GET['encode'] == 'json') { echo json_encode($Json); exit; } // Get the Handlebars Template $EditUserTemplateFilePath = realpath("../templates/admin/edituser.html"); if ($EditUserTemplateFilePath === false) { // Error exit("Template edituser.html was not found"); } $EditUserTemplate = file_get_contents($EditUserTemplateFilePath); // Last step, output the html file require 'Handlebars/Autoloader.php'; Handlebars\Autoloader::register(); use Handlebars\Handlebars; $engine = new Handlebars(); echo $engine->render($EditUserTemplate, $Json);
protected function render($template, $destination, $args) { $engine = new Handlebars(); $template = file_get_contents($template . '.template'); $result = $engine->render($template, $args); file_put_contents(APPLICATION_PATH . $destination, $result, FILE_TEXT); }