diff --git a/code/DocumentationManifest.php b/code/DocumentationManifest.php index dde9452..8003b9a 100644 --- a/code/DocumentationManifest.php +++ b/code/DocumentationManifest.php @@ -60,9 +60,9 @@ class DocumentationManifest { private $entity; /** - * @var array + * @var ArrayList */ - private $registeredEntities = array(); + private $registeredEntities; /** * Constructs a new template manifest. The manifest is not actually built @@ -74,6 +74,7 @@ class DocumentationManifest { public function __construct($forceRegen = false) { $this->cacheKey = 'manifest'; $this->forceRegen = $forceRegen; + $this->registeredEntities = new ArrayList(); $this->cache = SS_Cache::factory('DocumentationManifest', 'Core', array( 'automatic_serialization' => true, @@ -142,7 +143,7 @@ class DocumentationManifest { $entity->setIsDefaultEntity($details['DefaultEntity']); } - $this->registeredEntities[] = $entity; + $this->registeredEntities->push($entity); } } } @@ -158,7 +159,7 @@ class DocumentationManifest { } /** - * @return array + * @return ArrayList */ public function getEntities() { return $this->registeredEntities; @@ -300,7 +301,8 @@ class DocumentationManifest { 'title' => $folder->getTitle(), 'basename' => $basename, 'filepath' => $path, - 'type' => 'DocumentationFolder' + 'type' => 'DocumentationFolder', + 'summary' => '' ); } @@ -472,7 +474,7 @@ class DocumentationManifest { // if the page is the index page then hide it from the menu if(strpos(strtolower($pagePath), '/index.md/')) { - continue; + $pagePath = substr($pagePath, 0, strpos($pagePath, "index.md/")); } // only pull it up if it's one more level depth @@ -489,6 +491,7 @@ class DocumentationManifest { 'Link' => Controller::join_links($base, $url, '/'), 'Title' => $page['title'], 'LinkingMode' => $mode, + 'Summary' => $page['summary'], 'Children' => $children ))); } @@ -502,7 +505,7 @@ class DocumentationManifest { * * @return ArrayList */ - public function getAllVersions(DocumentationEntity $entity) { + public function getAllVersionsOfEntity(DocumentationEntity $entity) { $all = new ArrayList(); foreach($this->getEntities() as $check) { @@ -564,4 +567,23 @@ class DocumentationManifest { return $output; } + + /** + * Returns a sorted array of all the unique versions registered + */ + public function getAllVersions() { + $versions = array(); + + foreach($this->getEntities() as $entity) { + $versions[$entity->getVersion()] = $entity->getVersion(); + } + + $uniqueVersions = array_unique( + ArrayLib::flatten(array_values($versions)) + ); + + asort($uniqueVersions); + + return array_combine($uniqueVersions, $uniqueVersions); + } } diff --git a/code/DocumentationParser.php b/code/DocumentationParser.php index 7dd6ae7..bb497bd 100755 --- a/code/DocumentationParser.php +++ b/code/DocumentationParser.php @@ -383,7 +383,7 @@ class DocumentationParser { // relative path (relative to module base folder), without the filename. // For "sapphire/en/current/topics/templates", this would be "templates" - $relativePath = dirname($page->getRelativeLink()); + $relativePath = dirname($page->getRelativePath()); if($relativePath == '.') { $relativePath = ''; diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index 2c1367d..98877fc 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -359,8 +359,33 @@ class DocumentationViewer extends Controller { */ public function getContent() { $page = $this->getPage(); + $html = $page->getHTML(); + $html = $this->replaceChildrenCalls($html); - return DBField::create_field("HTMLText", $page->getHTML()); + return DBField::create_field("HTMLText", $html); + } + + public function replaceChildrenCalls($html) { + $codes = new ShortcodeParser(); + $codes->register('CHILDREN', array($this, 'includeChildren')); + + return $codes->parse($html); + } + + public function includeChildren($args) { + if(isset($args['Folder'])) { + $children = $this->getManifest()->getChildrenFor( + Controller::join_links(dirname($this->record->getPath()), $args['Folder']) + ); + } else { + $children = $this->getManifest()->getChildrenFor( + dirname($this->record->getPath()) + ); + } + + return $this->customise(new ArrayData(array( + 'Children' => $children + )))->renderWith('Includes/DocumentationPages'); } /** diff --git a/code/extensions/DocumentationViewerVersionWarning.php b/code/extensions/DocumentationViewerVersionWarning.php index f6f85a3..7a7351b 100644 --- a/code/extensions/DocumentationViewerVersionWarning.php +++ b/code/extensions/DocumentationViewerVersionWarning.php @@ -22,7 +22,7 @@ class DocumentationViewerVersionWarning extends Extension { return false; } - $versions = $this->owner->getManifest()->getAllVersions($entity); + $versions = $this->owner->getManifest()->getAllVersionsOfEntity($entity); if($entity->getIsStable()) { return false; diff --git a/code/forms/DocumentationAdvancedSearchForm.php b/code/forms/DocumentationAdvancedSearchForm.php index 89e608f..c814aad 100644 --- a/code/forms/DocumentationAdvancedSearchForm.php +++ b/code/forms/DocumentationAdvancedSearchForm.php @@ -6,30 +6,14 @@ class DocumentationAdvancedSearchForm extends Form { public function __construct($controller) { + $versions = $controller->getManifest()->getAllVersions(); $entities = $controller->getManifest()->getEntities(); - $versions = array(); - - foreach($entities as $entity) { - foreach($entity->getVersions() as $version) { - $versions[$version->getVersion()] = $version->getVersion(); - } - } - - // get a list of all the unique versions - $uniqueVersions = array_unique( - ArrayLib::flatten(array_values($versions)) - ); - - asort($uniqueVersions); - - $uniqueVersions = array_combine($uniqueVersions,$uniqueVersions); $q = ($q = $controller->getSearchQuery()) ? $q->NoHTML() : ""; - + // klude to take an array of objects down to a simple map - $entities = new ArrayList($entities); $entities = $entities->map('Folder', 'Title'); - + // if we haven't gone any search limit then we're searching everything $searchedEntities = $controller->getSearchedEntities(); @@ -40,16 +24,16 @@ class DocumentationAdvancedSearchForm extends Form { $searchedVersions = $controller->getSearchedVersions(); if(count($searchedVersions) < 1) { - $searchedVersions = $uniqueVersions; + $searchedVersions = $versions; } $fields = new FieldList( - new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), + new TextField('q', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities), new CheckboxSetField( 'Versions', _t('DocumentationViewer.VERSIONS', 'Versions'), - $uniqueVersions, $searchedVersions + $versions, $searchedVersions ) ); @@ -69,6 +53,6 @@ class DocumentationAdvancedSearchForm extends Form { $this->disableSecurityToken(); $this->setFormMethod('GET'); - $this->setFormAction($controller->Link('search')); + $this->setFormAction($controller->Link('results')); } } \ No newline at end of file diff --git a/code/forms/DocumentationSearchForm.php b/code/forms/DocumentationSearchForm.php index 9e0969a..40b1bd3 100644 --- a/code/forms/DocumentationSearchForm.php +++ b/code/forms/DocumentationSearchForm.php @@ -16,13 +16,8 @@ class DocumentationSearchForm extends Form { $this->disableSecurityToken(); $this->setFormMethod('GET'); + $this->setFormAction($controller->Link('results')); - if($controller->getPage()) { - $this->setFormAction($controller->getPage()->getEntity()->Link()); - } else { - $this->setFormAction($controller->Link()); - } - $this->addExtraClass('search'); } } \ No newline at end of file diff --git a/code/models/DocumentationPage.php b/code/models/DocumentationPage.php index 28562e2..be3af43 100755 --- a/code/models/DocumentationPage.php +++ b/code/models/DocumentationPage.php @@ -15,12 +15,7 @@ class DocumentationPage extends ViewableData { /** * @var string */ - protected $title; - - /** - * @var string - */ - protected $summary; + protected $title, $summary, $introduction; /** * @var DocumentationEntity @@ -39,6 +34,8 @@ class DocumentationPage extends ViewableData { */ protected $filename; + protected $read = false; + /** * @param DocumentationEntity $entity * @param string $filename @@ -63,7 +60,7 @@ class DocumentationPage extends ViewableData { * @return string */ public function getBreadcrumbTitle($divider = ' - ') { - $pathParts = explode('/', trim($this->getRelativeLink(), '/')); + $pathParts = explode('/', trim($this->getRelativePath(), '/')); // from the page from this array_pop($pathParts); @@ -74,8 +71,16 @@ class DocumentationPage extends ViewableData { $titleParts = array_map(array( 'DocumentationHelper', 'clean_page_name' ), $pathParts); - - array_unshift($titleParts, $this->getTitle()); + + $titleParts = array_filter($titleParts, function($val) { + if($val) { + return $val; + } + }); + + if($this->getTitle()) { + array_unshift($titleParts, $this->getTitle()); + } return implode($divider, $titleParts); } @@ -131,6 +136,8 @@ class DocumentationPage extends ViewableData { return $md; } + + $this->read = true; } catch(InvalidArgumentException $e) { @@ -144,6 +151,14 @@ class DocumentationPage extends ViewableData { $this->$key = $value; } + + public function getIntroduction() { + if(!$this->read) { + $this->getMarkdown(); + } + + return $this->introduction; + } /** * Parse a file and return the parsed HTML version. @@ -160,12 +175,15 @@ class DocumentationPage extends ViewableData { } /** + * This should return the link from the entity root to the page. The link + * value has the cleaned version of the folder names. See + * {@link getRelativePath()} for the actual file path. + * * @return string */ public function getRelativeLink() { - $path = str_replace($this->entity->getPath(), '', $this->getPath()); + $path = $this->getRelativePath(); $url = explode('/', $path); - $url = implode('/', array_map(function($a) { return DocumentationHelper::clean_page_url($a); }, $url)); @@ -175,6 +193,17 @@ class DocumentationPage extends ViewableData { return $url; } + /** + * This should return the link from the entity root to the page. For the url + * polished version, see {@link getRelativeLink()}. + * + * @return string + */ + public function getRelativePath() { + return str_replace($this->entity->getPath(), '', $this->getPath()); + + } + /** * @return string */ @@ -217,14 +246,12 @@ class DocumentationPage extends ViewableData { // find the key/value pairs $intPattern = '/(?[A-Za-z][A-Za-z0-9_-]+)[\t]*:[\t]*(?[^:\n\r\/]+)/x'; $matches = preg_match_all($intPattern, $block[1], $meta); - + foreach($meta['key'] as $index => $key) { if(isset($meta['value'][$index])) { - // check if a property exists for this key if (property_exists(get_class(), $key)) { $this->$key = $meta['value'][$index]; - $metaDataFound = true; } } diff --git a/code/tasks/RebuildLuceneDocsIndex.php b/code/tasks/RebuildLuceneDocsIndex.php index 47050a2..34809e4 100755 --- a/code/tasks/RebuildLuceneDocsIndex.php +++ b/code/tasks/RebuildLuceneDocsIndex.php @@ -67,8 +67,6 @@ class RebuildLuceneDocsIndex extends BuildTask { // iconv complains about all the markdown formatting // turn off notices while we parse - $error = error_reporting(); - error_reporting('E_ALL ^ E_NOTICE'); if(!Director::is_cli()) { echo "'; - // Table of content location - var title = $('#content h1:first'); - if (title.length > 0) { - title.after(toc); - } else { - var breadcrums = $('#content .doc-breadcrumbs'); - - if (breadcrums.length > 0) { - breadcrums.after(toc); - } else { - $('#table-contents-holder').prepend(toc); - } - } + $('#table-contents-holder').prepend(toc); // Toggle the TOC $('#table-of-contents').attr('href', 'javascript:void()').toggle( diff --git a/templates/DocumentationPages.ss b/templates/DocumentationPages.ss new file mode 100644 index 0000000..c40ab38 --- /dev/null +++ b/templates/DocumentationPages.ss @@ -0,0 +1,12 @@ +<% if Children %> +
+
    + <% loop Children %> +
  • +

    $Title

    + <% if Summary %>

    $Summary

    <% end_if %> +
  • + <% end_loop %> +
+
+<% end_if %> \ No newline at end of file diff --git a/templates/Includes/DocumentationPages.ss b/templates/Includes/DocumentationPages.ss new file mode 100644 index 0000000..c40ab38 --- /dev/null +++ b/templates/Includes/DocumentationPages.ss @@ -0,0 +1,12 @@ +<% if Children %> +
+
    + <% loop Children %> +
  • +

    $Title

    + <% if Summary %>

    $Summary

    <% end_if %> +
  • + <% end_loop %> +
+
+<% end_if %> \ No newline at end of file diff --git a/templates/Includes/DocumentationSidebar.ss b/templates/Includes/DocumentationSidebar.ss index 5d69909..28be097 100644 --- a/templates/Includes/DocumentationSidebar.ss +++ b/templates/Includes/DocumentationSidebar.ss @@ -3,10 +3,12 @@ $DocumentationSearchForm