Example #1
0
 public static function composer($ids, $callable)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $events = [];
     foreach ($ids as $id) {
         $events[] = Event::listen("data.{$id}", $callable);
     }
     return new EventInstanceGroup($events);
 }
Example #2
0
 public static function composer($name, $callable)
 {
     return Event::listen("view.{$name}", $callable);
 }
Example #3
0
/**
 * Listen for when the CLI is created
 */
Event::listen('cli.init', function ($cli) {
    // Register custom commands here
});
/**
 * 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!';
});
Example #4
0
 public function testRenderEventContainsPrimerData()
 {
     $testData = new \stdClass();
     $testData->count = 0;
     $event = Event::listen('render', function ($data) use($testData) {
         // Is the data the right type?
         $this->assertEquals(ViewData::class, get_class($data));
         $array = $data->toArray();
         $this->assertArrayHasKey('primer', $array);
         $this->assertArrayHasKey('bodyClass', $array['primer']);
         $this->assertArrayHasKey('template', $array['primer']);
         $this->assertArrayHasKey('items', $array['primer']);
         // Increment the count
         $testData->count++;
     });
     $output = $this->primer->getTemplate('render-event');
     $this->assertEquals(1, $testData->count);
     $event->stop();
 }