public static function instance() { if (!isset(self::$_instance)) { self::$_instance = new Handlebars(); Event::fire('handlebars.init', self::$_instance); } return self::$_instance; }
/** * Singleton function * * @return Twig A singleton instance of the Twig engine */ public static function instance() { if (!isset(self::$_instance)) { self::$_instance = new Twig(); Event::fire('twig.init', self::$_instance); } return self::$_instance; }
/** * Load a template and optionally pass in params * * @param string $name The name of the template to load (without .handlebars extension) * @param Array|ViewData $params An associative array of variables to export into the view * @return string HTML text * @author Joe Lambert **/ public static function render($name, $params = array()) { if (is_array($params)) { $params = new ViewData($params); } $templateClass = Primer::$TEMPLATE_CLASS; $template = new $templateClass(Primer::$VIEW_PATH, $name); Event::fire('view.' . $name, $params); return $template->render($params); }
public static function instance() { if (!isset(Cli::$instance)) { Cli::$instance = new Cli(); // Add the inbuilt commands Cli::$instance->add(new \Rareloop\Primer\Commands\PatternMake()); Cli::$instance->add(new \Rareloop\Primer\Commands\Serve()); Event::fire('cli.init', Cli::$instance); } return Cli::$instance; }
public function testEventCallbacksRecieveData() { $testData = new \stdClass(); $testData->count = 0; $eventArgs = 123; $event = Event::listen('testEvent', function ($arg) use($testData) { $testData->count++; $this->assertEquals(123, $arg); }); Event::fire('testEvent', $eventArgs); $this->assertEquals(1, $testData->count); }
public static function fire($id, &$data) { Event::fire('data.' . $id, $data, $id); // Fire off events that let us listen for parent paths as well as the main template // e.g. components/misc/* and components/* $parts = explode('/', $id); // We don't need to do the full path as we've already done it array_pop($parts); $eventString = ''; foreach ($parts as $part) { $eventString .= '/' . $part; $eventString = trim($eventString, '/'); Event::fire('data.' . $eventString . '/*', $data, $id); } }
protected function prepareViewForPatterns(RenderList $renderList, $showChrome = false) { $bodyClasses = array('not-template'); // If we're in minimal mode then add a new class to the body if (!$showChrome) { $bodyClasses[] = 'minimal'; } $viewData = new ViewData(['primer' => ['items' => $renderList->render($showChrome), 'bodyClass' => implode(' ', $bodyClasses)]]); Event::fire('render', $viewData); return View::render('template', $viewData); }