Exemple #1
0
 public function buildIndex()
 {
     $xyl = new Xyl(new File\Read('hoa://Jekxyl/Source/Layouts/Default.xyl'), new File\Write('hoa://Jekxyl/Dist/index.html'), new Xyl\Interpreter\Html(), $this->_router);
     $posts = [];
     foreach ($this->_posts as $post) {
         $posts[] = ['title' => $post->getTitle(), 'url' => $post->getUrl(), 'timestamp' => $post->getTimestamp(), 'date' => $post->getDate()];
     }
     $data = $xyl->getData();
     $data->posts = $posts;
     $xyl->addOverlay('hoa://Jekxyl/Source/Index.xyl');
     $xyl->render();
     return;
 }
Exemple #2
0
 public function construct()
 {
     parent::construct();
     if (false === $this->router->isAsynchronous()) {
         $main = 'hoa://Application/View/Shared/Main.xyl';
     } else {
         $main = 'hoa://Application/View/Shared/Main.Async.xyl';
     }
     $xyl = new Xyl(new File\Read($main), new Http\Response(false), new Xyl\Interpreter\Html(), $this->router);
     $xyl->setTheme('');
     $this->view = $xyl;
     $this->data = $xyl->getData();
     $this->data->title = 'Natibat - ';
     $this->data->Num_Version = VERSION;
     // Index par défaut
     if (false === $this->router->isAsynchronous()) {
         $this->view->addOverlay('hoa://Application/View/Shared/Index.xyl');
     } else {
         $this->view->addOverlay('hoa://Application/View/Shared/Index.Async.xyl');
     }
     // On essaye de récuperer la session
     try {
         $this->session = new Session("user");
         // TODO mettre en cache
         $autorisation = new \Application\Model\Autors();
         $this->session['Autor'] = $autorisation->getForSession();
         if (!empty($this->session['user'])) {
             $this->data->username = $this->session['user']->User_Nom . ' ' . $this->session['user']->User_Prenom;
             $this->data->profile = 'hoa://Application/Public/Images/inoupdate_128.png';
             foreach ($autorisation->getForSession() as $key => $value) {
                 $this->data->{$key} = (bool) ($this->session['droit'] & $this->session['Autor'][$key]);
             }
         } else {
             $rule = $this->router->getTheRule();
             if ($rule[1] != 'Home' && $rule[1] != 'Login') {
                 $response = $this->view->getOutPutStream();
                 $response->sendHeader('Location', $this->router->unroute('Home'), 302);
             }
         }
     } catch (\Hoa\Session\Exception\Expired $e) {
         echo $e->getMessage();
     }
     return;
 }
Exemple #3
0
 protected function computeMetas()
 {
     $xyl = new Xyl(new File\Read($this->_file->getPathname()), new Http\Response(), new Xyl\Interpreter\Html(), $this->_router);
     $ownerDocument = $xyl->readDOM()->ownerDocument;
     $xpath = new DOMXpath($ownerDocument);
     $query = $xpath->query('/processing-instruction(\'xyl-meta\')');
     for ($i = 0, $m = $query->length; $i < $m; ++$i) {
         $item = $query->item($i);
         $meta = new Xml\Attribute($item->data);
         $name = $meta->readAttribute('name');
         $value = $meta->readAttribute('value');
         if (false === in_array($name, static::LIST_OF_METAS)) {
             continue;
         }
         $this->_metas[$name] = $value;
         $item->parentNode->removeChild($item);
     }
     $buffer = new Stringbuffer\Read();
     $buffer->initializeWith($xyl->readXML());
     $this->_streamName = $buffer->getStreamName();
     return;
 }
Exemple #4
0
 /**
  * Structural compute (if/elseif/else).
  *
  * @param   \Hoa\Stream\IStream\Out  $out    Out stream.
  * @return  void
  */
 public function structuralCompute(Stream\IStream\Out $out)
 {
     $verdict = false;
     if (true === $this->abstract->attributeExists('test')) {
         $verdict = Xyl::evaluateXPath($this->computeAttributeValue($this->abstract->readAttribute('test'), self::ATTRIBUTE_TYPE_NORMAL));
     }
     if (false === $verdict) {
         $next = $this->abstract->selectAdjacentSiblingElement('elseif') ?: $this->abstract->selectAdjacentSiblingElement('else');
         if (false === $next) {
             return;
         }
         $this->getConcreteElement($next)->structuralCompute($out);
         return;
     }
     $this->computeValue($out);
     return;
 }
Exemple #5
0
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $directories = [];
     $clean = false;
     $lang = 'En';
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'd':
                 foreach ($this->parser->parseSpecialValue($v) as $directory) {
                     $directory = realpath($directory);
                     if (false === is_dir($directory)) {
                         throw new Console\Exception('Directory %s does not exist.', 0, $directory);
                     }
                     $directories[] = $directory;
                 }
                 break;
             case 'c':
                 $clean = true;
                 break;
             case 'l':
                 $lang = ucfirst(strtolower($v));
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     $workspace = resolve('hoa://Library/Devtools/Resource/Documentation') . DS . 'HackBook.output';
     if (true === $clean) {
         if (true === is_dir($workspace)) {
             $directory = new File\Directory($workspace);
             $directory->delete();
             unset($directory);
         }
         return;
     }
     clearstatcache(true);
     $workspace .= DS . $lang;
     if (false === is_dir($workspace)) {
         File\Directory::create($workspace);
     }
     Console\Cursor::colorize('foreground(yellow)');
     echo 'Selected language: ', $lang, '.', "\n\n";
     Console\Cursor::colorize('normal');
     require_once 'hoa://Library/Devtools/Resource/Documentation/Router.php';
     // $router is defined.
     $finder = new File\Finder();
     foreach ($directories as $location) {
         $_location = $location . DS . 'Documentation' . DS . $lang;
         if (false === is_dir($_location)) {
             throw new Console\Exception('Directory %s does not contain documentation.', 1, $location);
         }
         $finder->in($_location);
     }
     foreach (resolve('hoa://Library', true, true) as $location) {
         $libraryFinder = new File\Finder();
         $libraryFinder->in($location)->directories()->maxDepth(1);
         foreach ($libraryFinder as $_location) {
             $_location = $_location->getPathName() . DS . 'Documentation' . DS . $lang;
             if (true === is_dir($_location)) {
                 $finder->in($_location);
             }
         }
     }
     $vendors = [];
     foreach ($finder as $entry) {
         $path = dirname(dirname($entry->getPath()));
         $vendor = ucfirst(strtolower(basename(dirname($path))));
         $library = ucfirst(strtolower(basename($path)));
         if (!isset($vendors[$vendor])) {
             $vendors[$vendor] = [];
         }
         $vendors[$vendor][$library] = ['library' => $library, 'vendor' => $vendor, 'fullname' => $vendor . '\\' . $library];
     }
     foreach ($vendors as $vendor => &$libraries) {
         $libraries = array_values($libraries);
     }
     $layout = new File\Read('hoa://Library/Devtools/Resource/Documentation/Layout.xyl');
     $xyl = new Xyl($layout, new File\Write($workspace . '/index.html'), new Xyl\Interpreter\Html(), $router);
     $xyl->setTheme('');
     $data = $xyl->getData();
     foreach ($vendors as $vendor => $libraries) {
         $data->vendors->vendor = ['name' => $vendor, 'library' => $libraries];
     }
     $xyl->addOverlay('hoa://Library/Devtools/Resource/Documentation/Index.xyl');
     $xyl->render();
     echo 'Generate', "\t";
     Console\Cursor::colorize('foreground(green)');
     echo 'index.html';
     Console\Cursor::colorize('normal');
     echo '.', "\n";
     $xyl = null;
     foreach ($vendors as $vendor => $libraries) {
         File\Directory::create($workspace . dirname($router->unroute('full', ['vendor' => $libraries[0]['vendor'], 'chapter' => $libraries[0]['library']])));
         foreach ($libraries as $library) {
             $in = 'hoa://Library/' . $library['library'] . '/Documentation/' . $lang . '/Index.xyl';
             $out = $workspace . $router->unroute('full', ['vendor' => $library['vendor'], 'chapter' => $library['library']]);
             if (true === file_exists($out) && filemtime($in) <= filemtime($out)) {
                 echo 'Skip', "\t\t";
                 Console\Cursor::colorize('foreground(green)');
                 echo $library['fullname'];
                 Console\Cursor::colorize('normal');
                 echo '.', "\n";
                 continue;
             }
             $out = new File\Write($out);
             $out->truncate(0);
             if (null === $xyl) {
                 $xyl = new Xyl($layout, $out, new Xyl\Interpreter\Html(), $router);
                 $xyl->setTheme('');
                 $xyl->addOverlay('hoa://Library/Devtools/Resource/Documentation/Chapter.xyl');
             } else {
                 $xyl->setOutputStream(new File\Write($out));
             }
             $xyl->addOverlay($in);
             $xyl->getData()->name[0] = $library['fullname'];
             $xyl->getData()->library[0] = $library['library'];
             try {
                 $xyl->render();
             } catch (\Exception $e) {
                 echo $e->getMessage(), "\n";
             }
             $xyl->removeOverlay($in);
             echo 'Generate', "\t";
             Console\Cursor::colorize('foreground(green)');
             echo $library['fullname'];
             Console\Cursor::colorize('normal');
             echo '.', "\n";
         }
     }
     echo "\n", 'Open file://', $workspace, '/index.html', '.', "\n";
     return;
 }
Exemple #6
0
 /**
  * Select data according to an expression into a bucket.
  * Move pointer into bucket or fill a new bucket and return the last
  * reachable branche.
  *
  * @param   string     $expression    Expression (please, see inline
  *                                    comments to study all cases).
  * @param   array      &$bucket       Bucket.
  * @return  string
  */
 protected function selectData($expression, array &$bucket)
 {
     switch (Xyl::getSelector($expression, $matches)) {
         case Xyl::SELECTOR_PATH:
             $split = preg_split('#(?<!\\\\)\\/#', $matches[1]);
             foreach ($split as &$s) {
                 $s = str_replace('\\/', '/', $s);
             }
             $branche = array_pop($split);
             $handle =& $bucket;
             foreach ($split as $part) {
                 $handle =& $bucket[0][$part];
             }
             $bucket = $handle;
             return $branche;
         case Xyl::SELECTOR_QUERY:
             var_dump('*** QUERY');
             var_dump($matches);
             break;
         case Xyl::SELECTOR_XPATH:
             var_dump('*** XPATH');
             var_dump($matches);
             break;
     }
     return null;
 }