/** * {@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; }
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); }
/** * {@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; }
/** * Sets HandlebarsEngine up */ protected function setupEngine() { $this->engine = new HandlebarsEngine(); $loader = new HandlebarsLoader($this->viewManager); $partialLoader = new HandlebarsLoader($this->viewManager); $partialLoader->setPrefix('_'); $this->engine->setLoader($loader); $this->engine->setPartialsLoader($partialLoader); }
/** * 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']); }); }
/** * {@inheritdoc} */ public function getHandlebars() { if (is_null($this->templateEngine)) { $templates_loader = new \Handlebars\Loader\FilesystemLoader(MIBEW_FS_ROOT . '/' . $this->getFilesPath() . '/templates_src/server_side/'); $this->templateEngine = new \Handlebars\Handlebars(array('loader' => $templates_loader, 'partials_loader' => $templates_loader, 'helpers' => new Helpers())); // Use custom function to escape strings $this->templateEngine->setEscape('safe_htmlspecialchars'); $this->templateEngine->setEscapeArgs(array()); } return $this->templateEngine; }
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); }
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 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); }
/** * @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); }
/** * 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.'); }
/** * {@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.'); }
/** * Process variable * * @param Context $context current context * @param array $current section node data * @param boolean $escaped escape result or not * * @return string the result */ private function _getVariable(Context $context, $current, $escaped) { $name = $current[Tokenizer::NAME]; $value = $context->get($name); if (is_array($value)) { return 'Array'; } if ($escaped && !$value instanceof SafeString) { $args = $this->handlebars->getEscapeArgs(); array_unshift($args, (string) $value); $value = call_user_func_array($this->handlebars->getEscape(), array_values($args)); } return (string) $value; }
// Save the file $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);
/** * test variable access */ public function testVariableAccess() { $loader = new \Handlebars\Loader\StringLoader(); $engine = \Handlebars\Handlebars::factory(); $engine->setLoader($loader); $var = new \StdClass(); $var->x = 'var-x'; $var->y = array('z' => 'var-y-z'); $this->assertEquals('test', $engine->render('{{var}}', array('var' => 'test'))); $this->assertEquals('var-x', $engine->render('{{var.x}}', array('var' => $var))); $this->assertEquals('var-y-z', $engine->render('{{var.y.z}}', array('var' => $var))); // Access parent context in with helper $this->assertEquals('var-x', $engine->render('{{#with var.y}}{{../var.x}}{{/with}}', array('var' => $var))); $obj = new DateTime(); $time = $obj->getTimestamp(); $this->assertEquals($time, $engine->render('{{time.getTimestamp}}', array('time' => $obj))); }
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); }
if (isset($_POST['action']) && $_POST['action'] == "SAVE") { $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);
public function getBlogDropQuery($tablePrefix, $blogId) { $template = $this->templates('drop-blog-tables'); $data = ['prefix' => $tablePrefix, 'blog_id' => $blogId]; return $this->handlebars->render($template, $data); }
/** * @return string */ public function render() { return $this->engine->render($this->template, $this->data); }
/** * Adds the given helper to the rendering servie * * @param string $helperName Name of the helper * @param Helper $helper Helper * * @return void */ public function addHelper($helperName, Helper $helper) { $this->handlebarsRenderingEngine->addHelper($helperName, $helper); }
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); ?>
$data = ['inputs' => $params, 'themes' => $themePublic, 'settings' => $settings, 'user' => $currentUser]; // if developpement env // add some dataset $debugMode = Config::get('app.debug'); if ($debugMode) { $data = array_merge($data, Config::get('frontage::dataTestSet')); } // TPL Engine // 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');
} ### 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);
$config->setParam('title', new Params\TitleParam()); $config->setParam('subtitle', new Params\SubTitleParam()); $config->setParam('date', new Params\DateParam()); $config->setParam('authors', new Params\AuthorsParam()); $config->setParam('slides', new Params\SlidesParam()); $config->setParam('license', new Params\LicenseParam()); $config->setParam('theme', new Params\ThemeParam()); return $config; }), 'Bigwhoop\\Trumpet\\Presentation\\Theming\\Theme' => DI\object('Bigwhoop\\Trumpet\\Presentation\\Theming\\HandlebarsTheme')->constructor(DI\link('ThemeDirectory')), 'Bigwhoop\\Trumpet\\Presentation\\Presenter' => DI\factory(function (DIC $c) { /** @var HandlebarsPresenter $presenter */ $presenter = $c->get('Bigwhoop\\Trumpet\\Presentation\\HandlebarsPresenter'); $presenter->addSlideRenderer($c->get('Bigwhoop\\Trumpet\\Presentation\\SlideRendering\\CommandsRenderer')); $presenter->addSlideRenderer($c->get('Bigwhoop\\Trumpet\\Presentation\\SlideRendering\\MarkdownExtraSlideRenderer')); return $presenter; }), 'Bigwhoop\\SentenceBreaker\\SentenceBreaker' => DI\object()->method('addAbbreviations', DI\link('Bigwhoop\\SentenceBreaker\\Abbreviations\\ValueProvider')), 'Bigwhoop\\SentenceBreaker\\Abbreviations\\ValueProvider' => DI\object('Bigwhoop\\SentenceBreaker\\Abbreviations\\FlatFileProvider')->constructor(__DIR__ . '/../../vendor/bigwhoop/sentence-breaker/data', ['all']), 'Handlebars\\Handlebars' => DI\factory(function () { $hbs = new Handlebars(); $hbs->setLoader(new HbsStringLoader()); $hbs->addHelper('urlencode', function (HbsTemplate $template, HbsContext $context, $args, $source) { return rawurlencode($context->get($args)); }); $hbs->addHelper('count', function (HbsTemplate $template, HbsContext $context, $args, $source) { return count($context->get($args)); }); $hbs->addHelper('join', function (HbsTemplate $template, HbsContext $context, $args, $source) { $matches = []; if (preg_match("#'([^']+)' (.+)#", $args, $matches)) { list(, $separator, $input) = $matches; $out = []; foreach ((array) $context->get($input) as $value) { $context->push($value); $out[] = $template->render($context);
/** * Handlebars engine constructor * $options array can contain : * 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 * * @param array $options array of options to set * * @throws \InvalidArgumentException */ public function __construct(array $options = array()) { $options['partials_loader'] = new Loader(); parent::__construct($options); }
// 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 );
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); }