/** * Renders the group * * @param boolean $showChrome Whether or not the item should render descriptive chrome * @return String HTML text */ public function render($showChrome = true) { if ($showChrome) { return View::render('group', array('title' => $this->title, 'id' => $this->id, 'copy' => $this->copy, 'patterns' => $this->patterns->render())); } else { return $this->patterns->render($showChrome); } }
/** * Renders the pattern * * @param boolean $showChrome Whether or not the item should render descriptive chrome * @return String HTML text */ public function render($showChrome = true) { $html = $this->template->render($this->data); // Tidy the HTML $parser = new Parser(); $html = $parser->indent($html); if ($showChrome) { return View::render('pattern', ['title' => $this->title, 'id' => $this->id, 'html' => $html, 'template' => $this->templateRaw, 'copy' => $this->copy, 'data' => json_encode($this->data, JSON_PRETTY_PRINT)]); } else { return $html; } }
/** * Get the menu listing all the page templates in the site * * @return String */ public function getMenu() { $viewData = new ViewData(array('templates' => $this->getTemplates())); return View::render('menu', $viewData); }
* Listen for whole page render events */ Event::listen('render', function ($data) { $data->primer->environment = 'development'; }); /** * Listen for when new Handlebars objects are created so that we can register any required helpers */ Event::listen('handlebars.init', function ($handlebars) { }); /** * Listen for when a View (not pattern template) is about to be rendered * view.[viewName] - below example would call when views/pattern.handlebars is loaded */ View::composer('pattern', function ($data, $eventId) { // $data->id = 'testing'; }); /** * A function that calls anytime a data for a pattern is loaded * Useful for dynamically generating pattern data, e.g. sprites * $data is the raw output of the data.json */ ViewData::composer('elements/forms/input', function ($data) { // $data->label = 'boo yah!'; }); /** * Create an instance of Primer * * @var Primer */ $primer = Primer::start(['basePath' => __DIR__ . '/..', 'templateClass' => HandlebarsTemplateEngine::class]);
public function testRenderingAViewShouldTriggerEvent() { $testData = new \stdClass(); $testData->count = 0; $event = View::composer('pattern', function ($data) use($testData) { // Is the data the right type? $this->assertEquals(ViewData::class, get_class($data)); // Increment the count $testData->count++; }); // Render a pattern with chrome so that it uses the pattern.hbs file $output = $this->primer->getPatterns(array('components/events/view-render'), true); $this->assertEquals(1, $testData->count); // Unbind event so it can't mess with other tests $event->stop(); }