/**
  * 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);
 }
Esempio n. 2
0
    $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);
                $context->pop();
            }
            return implode($separator, $out);
Esempio n. 3
0
        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');
    // return Response::view('errors.missing', array(), 404);
});
App::error(function (MethodNotAllowedHttpException $exception) {
    exit('503');