Exemple #1
0
 public function testCustomPatternData()
 {
     $primer = Primer::start(array('basePath' => __DIR__ . '/primer-test', 'templateClass' => HandlebarsTemplateEngine::class));
     $pattern = new Pattern('components/patterns/custom-data', ['name' => 'Test name']);
     $output = $pattern->render(false);
     $this->assertEquals("Test name", $output);
 }
Exemple #2
0
 public function __construct($id)
 {
     $this->id = Primer::cleanId($id);
     $this->path = Primer::$PATTERN_PATH . '/' . $this->id;
     // Check the path is valid
     if (!is_dir($this->path)) {
         throw new NotFoundException('Group not found: ' . $this->id);
     }
     // Get the title
     $idComponents = explode('/', $this->id);
     $this->title = ucwords(preg_replace('/\\-/', ' ', strtolower(end($idComponents))));
     $this->copy = $this->loadCopy();
     // Load the patterns
     $this->patterns = new RenderList(Pattern::loadPatternsInPath($this->path));
 }
Exemple #3
0
 /**
  * Get a specific page template
  *
  * @param  String $id The template id
  * @return String
  */
 public function getTemplate($id)
 {
     // Default system wide template wrapping config
     $wrapTemplate = Primer::$WRAP_TEMPLATES;
     $id = Primer::cleanId($id);
     // Create the template
     $template = new Pattern('templates/' . $id);
     $templateData = new ViewData(["primer" => ['bodyClass' => 'is-template', 'template' => $id]]);
     $data = $template->getData();
     // Template level wrapping config
     if (isset($data->primer->wrapTemplate)) {
         $wrapTemplate = $data->primer->wrapTemplate;
     }
     if ($wrapTemplate) {
         $view = 'template';
         // Check the data to see if there is a custom view
         if (isset($data->primer) && isset($data->primer->view)) {
             $view = $data->primer->view;
         }
         $templateData->primer->items = $template->render(false);
         Event::fire('render', $templateData);
         return View::render($view, $templateData);
     } else {
         // Merge the data we would have passed into the view into the template
         $template->setData($templateData);
         // Get a reference to the template data so that we can pass it to anyone who's listening
         $viewData = $template->getData();
         Event::fire('render', $viewData);
         return $template->render(false);
     }
 }