public function props() { if ($this->format() == 'v1') { return unyaml(data_directory() . '/' . $this->pth); } elseif ($this->format() == 'md') { $parser = new Mni\FrontYAML\Parser(); $document = $parser->parse(file_get_contents(data_directory() . '/' . $this->pth)); $yaml = $document->getYAML(); $html = $document->getContent(); return $yaml; } }
function props() { return unyaml('data/' . $this->pth); }
<? foreach($data as $v):?> <li><a href='<?php echo $v->getHref(); ?> '><?php echo $v->getName(); ?> </a></li> <? endforeach ?> </ul> </div> <div class='category-links'> Интересные материалы: <ul> <? foreach(unyaml('data/links.yaml') as $v): ?> <li> <? if(is_array($v)): ?> <a href='<?php echo car($v); ?> '><?php echo car($v); ?> </a> <?php echo cdr($v); ?> <? else: ?> <a href='<?php echo $v; ?>
public function meta($key = null) { if (is_null($this->_meta)) { $pth = data($this->_path . '/meta.yaml'); if (file_exists($pth)) { $this->_meta = unyaml($pth); } } if (is_null($key)) { return $this->_meta; } if (isset($this->_meta[$key])) { return $this->_meta[$key]; } }
return trim(`cd data; find * -type f -name '[0-9]*' | wc -l`); }); /** * Из каталога возвращает пути до всех примеров в правильном порядке */ def('ordered_exampls', function ($pth) { if (!is_category_exists($pth)) { throw new Exception("Category {$pth} not exists"); } $PREFIX = data_directory() . '/' . $pth . '/'; $data = array_filter(glob($PREFIX . '*'), function ($pth) { return is_example_path(strip_data_direcotry($pth)) && is_file($pth); }); natsort($data); $data = array_values($data); $meta_pth = $PREFIX . 'meta.yaml'; if (file_exists($meta_pth)) { $meta = unyaml($meta_pth); if (isset($meta['order'])) { $t = array_flip($data); $order = array_reverse($meta['order']); foreach ($order as $v) { unset($data[$t[$PREFIX . $v]]); } foreach ($order as $v) { array_unshift($data, $PREFIX . $v); } } } return array_values($data); });