*/ 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, $id, $originalId) { // $data->label = 'boo yah!'; }); /** * Create an instance of Primer * * @var Primer */ $primer = Primer::start(['basePath' => __DIR__ . '/..', 'templateClass' => HandlebarsTemplateEngine::class]); return $primer;
*/ 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]); return $primer;
public function testLoadingDataShouldTriggerEventsForParentPaths() { $testData = new \stdClass(); $testData->count = 0; $event1 = ViewData::composer('components/events/*', function ($data) use($testData) { // Is the data the right type? $this->assertEquals(ViewData::class, get_class($data)); // Increment the count $testData->count++; }); $event2 = ViewData::composer('components/*', function ($data) use($testData) { // Is the data the right type? $this->assertEquals(ViewData::class, get_class($data)); // Increment the count $testData->count++; }); $viewData = FileSystem::getDataForPattern('components/events/loading-data'); $this->assertEquals(2, $testData->count); // Unbind event so it can't mess with other tests $event1->stop(); $event2->stop(); }