mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
Apply PSR-2 coding conventions
This commit is contained in:
parent
a10cdd35f7
commit
fe8b9a37b5
@ -90,7 +90,9 @@ class DocumentationManifest
|
||||
$this->registeredEntities = new ArrayList();
|
||||
|
||||
$this->cache = SS_Cache::factory(
|
||||
'DocumentationManifest', 'Core', array(
|
||||
'DocumentationManifest',
|
||||
'Core',
|
||||
array(
|
||||
'automatic_serialization' => true,
|
||||
'lifetime' => null
|
||||
)
|
||||
@ -159,7 +161,8 @@ class DocumentationManifest
|
||||
* @var DocumentationEntity $entity
|
||||
*/
|
||||
$entity = Injector::inst()->create(
|
||||
'DocumentationEntity', $key
|
||||
'DocumentationEntity',
|
||||
$key
|
||||
);
|
||||
|
||||
$entity->setPath(DocumentationHelper::normalizePath(Controller::join_links($path, $lang, '/')));
|
||||
@ -242,7 +245,9 @@ class DocumentationManifest
|
||||
}
|
||||
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'register_entities', $entities
|
||||
'DocumentationManifest',
|
||||
'register_entities',
|
||||
$entities
|
||||
);
|
||||
|
||||
$this->automaticallyPopulated = true;
|
||||
@ -371,7 +376,8 @@ class DocumentationManifest
|
||||
|
||||
foreach ($grouped as $entity) {
|
||||
uasort(
|
||||
$entity, function ($a, $b) {
|
||||
$entity,
|
||||
function ($a, $b) {
|
||||
// ensure parent directories are first
|
||||
$a['filepath'] = str_replace('index.md', '', $a['filepath']);
|
||||
$b['filepath'] = str_replace('index.md', '', $b['filepath']);
|
||||
@ -417,7 +423,8 @@ class DocumentationManifest
|
||||
Config::inst()->get('DocumentationViewer', 'link_base'),
|
||||
'',
|
||||
$link
|
||||
), '/'
|
||||
),
|
||||
'/'
|
||||
);
|
||||
}
|
||||
|
||||
@ -461,7 +468,10 @@ class DocumentationManifest
|
||||
public function handleFolder($basename, $path, $depth)
|
||||
{
|
||||
$folder = Injector::inst()->create(
|
||||
'DocumentationFolder', $this->entity, $basename, $path
|
||||
'DocumentationFolder',
|
||||
$this->entity,
|
||||
$basename,
|
||||
$path
|
||||
);
|
||||
|
||||
// Add main folder link
|
||||
@ -491,7 +501,9 @@ class DocumentationManifest
|
||||
{
|
||||
$page = Injector::inst()->create(
|
||||
'DocumentationPage',
|
||||
$this->entity, $basename, $path
|
||||
$this->entity,
|
||||
$basename,
|
||||
$path
|
||||
);
|
||||
|
||||
// populate any meta data
|
||||
|
@ -125,7 +125,6 @@ class DocumentationParser
|
||||
$inner = true;
|
||||
}
|
||||
} elseif (preg_match('/^[\ ]{0,3}?[\t](.*)/', $line, $matches)) {
|
||||
|
||||
// inner line of block, or first line of standard markdown code block
|
||||
// regex removes first tab (any following tabs are part of the code).
|
||||
if (!$started) {
|
||||
@ -248,7 +247,9 @@ class DocumentationParser
|
||||
if (substr($url, 0, 1) == '/') {
|
||||
$relativeUrl = DocumentationHelper::normalizePath(
|
||||
str_replace(
|
||||
BASE_PATH, '', Controller::join_links(
|
||||
BASE_PATH,
|
||||
'',
|
||||
Controller::join_links(
|
||||
$page->getEntity()->getPath(),
|
||||
$url
|
||||
)
|
||||
@ -326,11 +327,11 @@ class DocumentationParser
|
||||
$html_format = '<a href="http://api.silverstripe.org/search/lookup/?q=%s&version=%s&module=%s">%s</a>';
|
||||
|
||||
// parse api links without backticks into html
|
||||
foreach($regexs as $type => $regex) {
|
||||
foreach ($regexs as $type => $regex) {
|
||||
preg_match_all($regex, $markdown, $links);
|
||||
if($links) {
|
||||
foreach($links[0] as $i => $match) {
|
||||
if($type === 'no_title') {
|
||||
if ($links) {
|
||||
foreach ($links[0] as $i => $match) {
|
||||
if ($type === 'no_title') {
|
||||
$title = $links[1][$i];
|
||||
$link = $links[1][$i];
|
||||
// change backticked links to avoid being parsed in the same way as non-backticked links
|
||||
@ -349,8 +350,8 @@ class DocumentationParser
|
||||
|
||||
// recover backticked links with no titles
|
||||
preg_match_all('#XYZ(.*)?XYZ#', $markdown, $links);
|
||||
if($links) {
|
||||
foreach($links[0] as $i => $match) {
|
||||
if ($links) {
|
||||
foreach ($links[0] as $i => $match) {
|
||||
$link = $links[1][$i];
|
||||
$markdown = str_replace($match, '`[api:'.$link.']`', $markdown);
|
||||
}
|
||||
@ -358,8 +359,8 @@ class DocumentationParser
|
||||
|
||||
// recover backticked links with titles
|
||||
preg_match_all('#XX(.*)?YY(.*)?ZZ#', $markdown, $links);
|
||||
if($links) {
|
||||
foreach($links[0] as $i => $match) {
|
||||
if ($links) {
|
||||
foreach ($links[0] as $i => $match) {
|
||||
$title = $links[1][$i];
|
||||
$link = $links[2][$i];
|
||||
$markdown = str_replace($match, '`['.$title.'](api:'.$link.')`', $markdown);
|
||||
@ -367,7 +368,6 @@ class DocumentationParser
|
||||
}
|
||||
|
||||
return $markdown;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -488,7 +488,7 @@ class DocumentationParser
|
||||
$fileBaseLink,
|
||||
$url
|
||||
);
|
||||
} else if (preg_match('/^#/', $url)) {
|
||||
} elseif (preg_match('/^#/', $url)) {
|
||||
// for relative links begining with a hash use the current page link
|
||||
$relativeUrl = Controller::join_links($baselink, $page->getRelativeLink(), $url);
|
||||
} else {
|
||||
@ -521,5 +521,4 @@ class DocumentationParser
|
||||
|
||||
return $md;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -428,7 +428,8 @@ class DocumentationSearch
|
||||
$title = ($title = $this->getTitle()) ? ' - '. $title : "";
|
||||
|
||||
$link = Controller::join_links(
|
||||
$this->outputController->Link(), 'DocumentationOpenSearchController/description/'
|
||||
$this->outputController->Link(),
|
||||
'DocumentationOpenSearchController/description/'
|
||||
);
|
||||
|
||||
$data->setField('Title', $data->Title . $title);
|
||||
|
@ -204,7 +204,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
// Strip off the base url
|
||||
//
|
||||
$base = ltrim(
|
||||
Config::inst()->get('DocumentationViewer', 'link_base'), '/'
|
||||
Config::inst()->get('DocumentationViewer', 'link_base'),
|
||||
'/'
|
||||
);
|
||||
|
||||
if ($base && strpos($url, $base) !== false) {
|
||||
@ -393,7 +394,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
|
||||
// add children
|
||||
$children = $this->getManifest()->getChildrenFor(
|
||||
$entity->getPath(), ($record) ? $record->getPath() : $entity->getPath()
|
||||
$entity->getPath(),
|
||||
($record) ? $record->getPath() : $entity->getPath()
|
||||
);
|
||||
} else {
|
||||
if ($current && $current->getKey() == $entity->getKey()) {
|
||||
@ -438,7 +440,7 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
public function replaceChildrenCalls($html)
|
||||
{
|
||||
$codes = new ShortcodeParser();
|
||||
$codes->register('CHILDREN', array($this, 'includeChildren'));
|
||||
$codes->register('CHILDREN', array($this, 'includeChildren'));
|
||||
|
||||
return $codes->parse($html);
|
||||
}
|
||||
@ -694,7 +696,6 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
$entity = $page->getEntity();
|
||||
|
||||
if ($entity && isset(self::$edit_links[strtolower($entity->title)])) {
|
||||
|
||||
// build the edit link, using the version defined
|
||||
$url = self::$edit_links[strtolower($entity->title)];
|
||||
$version = $entity->getVersion();
|
||||
@ -738,7 +739,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
{
|
||||
return ($this->record)
|
||||
? $this->getManifest()->getNextPage(
|
||||
$this->record->getPath(), $this->getEntity()->getPath()
|
||||
$this->record->getPath(),
|
||||
$this->getEntity()->getPath()
|
||||
)
|
||||
: null;
|
||||
}
|
||||
@ -753,7 +755,8 @@ class DocumentationViewer extends Controller implements PermissionProvider
|
||||
{
|
||||
return ($this->record)
|
||||
? $this->getManifest()->getPreviousPage(
|
||||
$this->record->getPath(), $this->getEntity()->getPath()
|
||||
$this->record->getPath(),
|
||||
$this->getEntity()->getPath()
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ class DocumentationAdvancedSearchForm extends Form
|
||||
CheckboxSetField::create(
|
||||
'Versions',
|
||||
_t('DocumentationViewer.VERSIONS', 'Versions'),
|
||||
$versions, $searchedVersions
|
||||
$versions,
|
||||
$searchedVersions
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -87,7 +87,8 @@ class DocumentationPage extends ViewableData
|
||||
);
|
||||
|
||||
$titleParts = array_filter(
|
||||
$titleParts, function ($val) {
|
||||
$titleParts,
|
||||
function ($val) {
|
||||
if ($val) {
|
||||
return $val;
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ class CheckDocsSourcesTask extends BuildTask
|
||||
|
||||
public function start()
|
||||
{
|
||||
if(!Director::is_cli()) {
|
||||
if (!Director::is_cli()) {
|
||||
echo "<ul>";
|
||||
}
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
if(Director::is_cli()) {
|
||||
if (Director::is_cli()) {
|
||||
echo "\nTotal errors: {$this->errors}\n";
|
||||
} else {
|
||||
echo "</ul>";
|
||||
@ -30,7 +30,7 @@ class CheckDocsSourcesTask extends BuildTask
|
||||
public function showError($error)
|
||||
{
|
||||
$this->errors++;
|
||||
if(Director::is_cli()) {
|
||||
if (Director::is_cli()) {
|
||||
echo "\n$error";
|
||||
} else {
|
||||
echo "<li>" . Convert::raw2xml($error) . "</li>";
|
||||
|
@ -87,25 +87,29 @@ class RebuildLuceneDocsIndex extends BuildTask
|
||||
|
||||
$doc->addField(
|
||||
Zend_Search_Lucene_Field::Keyword(
|
||||
'Version', $page->getEntity()->getVersion()
|
||||
'Version',
|
||||
$page->getEntity()->getVersion()
|
||||
)
|
||||
);
|
||||
|
||||
$doc->addField(
|
||||
Zend_Search_Lucene_Field::Keyword(
|
||||
'Language', $page->getEntity()->getLanguage()
|
||||
'Language',
|
||||
$page->getEntity()->getLanguage()
|
||||
)
|
||||
);
|
||||
|
||||
$doc->addField(
|
||||
Zend_Search_Lucene_Field::Keyword(
|
||||
'Entity', $page->getEntity()
|
||||
'Entity',
|
||||
$page->getEntity()
|
||||
)
|
||||
);
|
||||
|
||||
$doc->addField(
|
||||
Zend_Search_Lucene_Field::Keyword(
|
||||
'Link', $page->Link()
|
||||
'Link',
|
||||
$page->Link()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -16,18 +16,24 @@ class DocumentationManifestTests extends SapphireTest
|
||||
|
||||
// explicitly use dev/docs. Custom paths should be tested separately
|
||||
Config::inst()->update(
|
||||
'DocumentationViewer', 'link_base', 'dev/docs'
|
||||
'DocumentationViewer',
|
||||
'link_base',
|
||||
'dev/docs'
|
||||
);
|
||||
|
||||
// disable automatic module registration so modules don't interfere.
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'automatic_registration', false
|
||||
'DocumentationManifest',
|
||||
'automatic_registration',
|
||||
false
|
||||
);
|
||||
|
||||
Config::inst()->remove('DocumentationManifest', 'register_entities');
|
||||
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'register_entities', array(
|
||||
'DocumentationManifest',
|
||||
'register_entities',
|
||||
array(
|
||||
array(
|
||||
'Path' => DOCSVIEWER_PATH . "/tests/docs/",
|
||||
'Title' => 'Doc Test',
|
||||
@ -189,7 +195,8 @@ class DocumentationManifestTests extends SapphireTest
|
||||
);
|
||||
|
||||
$this->assertDOSContains(
|
||||
$expected, $this->manifest->getChildrenFor(
|
||||
$expected,
|
||||
$this->manifest->getChildrenFor(
|
||||
DOCSVIEWER_PATH . '/tests/docs/en/'
|
||||
)
|
||||
);
|
||||
|
@ -42,7 +42,8 @@ class DocumentationPageTest extends SapphireTest
|
||||
|
||||
// single layer
|
||||
$this->assertEquals(
|
||||
'dev/docs/en/doctest/2.4/test/', $page->Link(),
|
||||
'dev/docs/en/doctest/2.4/test/',
|
||||
$page->Link(),
|
||||
'The page link should have no extension and have a language'
|
||||
);
|
||||
|
||||
|
@ -23,7 +23,9 @@ class DocumentationParserTest extends SapphireTest
|
||||
|
||||
// explicitly use dev/docs. Custom paths should be tested separately
|
||||
Config::inst()->update(
|
||||
'DocumentationViewer', 'link_base', 'dev/docs/'
|
||||
'DocumentationViewer',
|
||||
'link_base',
|
||||
'dev/docs/'
|
||||
);
|
||||
|
||||
$this->entity = new DocumentationEntity('DocumentationParserTest');
|
||||
@ -294,7 +296,9 @@ HTML;
|
||||
);
|
||||
|
||||
$expected = Controller::join_links(
|
||||
Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/subfolder/_images/image.png'
|
||||
Director::absoluteBaseURL(),
|
||||
DOCSVIEWER_DIR,
|
||||
'/tests/docs/en/subfolder/_images/image.png'
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
@ -304,15 +308,20 @@ HTML;
|
||||
|
||||
$this->assertContains(
|
||||
sprintf(
|
||||
'[parent image link](%s)', Controller::join_links(
|
||||
Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png'
|
||||
'[parent image link](%s)',
|
||||
Controller::join_links(
|
||||
Director::absoluteBaseURL(),
|
||||
DOCSVIEWER_DIR,
|
||||
'/tests/docs/en/_images/image.png'
|
||||
)
|
||||
),
|
||||
$result
|
||||
);
|
||||
|
||||
$expected = Controller::join_links(
|
||||
Director::absoluteBaseURL(), DOCSVIEWER_DIR, '/tests/docs/en/_images/image.png'
|
||||
Director::absoluteBaseURL(),
|
||||
DOCSVIEWER_DIR,
|
||||
'/tests/docs/en/_images/image.png'
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
@ -350,11 +359,10 @@ HTML;
|
||||
array('[Title](api:DataObject::populateDefaults())',sprintf($html_format, 'DataObject::populateDefaults()', 'Title'))
|
||||
);
|
||||
|
||||
foreach($test_cases as $test_case) {
|
||||
foreach ($test_cases as $test_case) {
|
||||
$expected_html = $test_case[1];
|
||||
$this->assertContains($expected_html, $parsed_page);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testHeadlineAnchors()
|
||||
|
@ -15,18 +15,24 @@ class DocumentationSearchTest extends FunctionalTest
|
||||
|
||||
// explicitly use dev/docs. Custom paths should be tested separately
|
||||
Config::inst()->update(
|
||||
'DocumentationViewer', 'link_base', 'dev/docs'
|
||||
'DocumentationViewer',
|
||||
'link_base',
|
||||
'dev/docs'
|
||||
);
|
||||
|
||||
// disable automatic module registration so modules don't interfere.
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'automatic_registration', false
|
||||
'DocumentationManifest',
|
||||
'automatic_registration',
|
||||
false
|
||||
);
|
||||
|
||||
Config::inst()->remove('DocumentationManifest', 'register_entities');
|
||||
Config::inst()->update('DocumentationSearch', 'enabled', true);
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'register_entities', array(
|
||||
'DocumentationManifest',
|
||||
'register_entities',
|
||||
array(
|
||||
array(
|
||||
'Path' => DOCSVIEWER_PATH . "/tests/docs-search/",
|
||||
'Title' => 'Docs Search Test', )
|
||||
|
@ -22,18 +22,24 @@ class DocumentationViewerTest extends FunctionalTest
|
||||
|
||||
// explicitly use dev/docs. Custom paths should be tested separately
|
||||
Config::inst()->update(
|
||||
'DocumentationViewer', 'link_base', 'dev/docs/'
|
||||
'DocumentationViewer',
|
||||
'link_base',
|
||||
'dev/docs/'
|
||||
);
|
||||
|
||||
// disable automatic module registration so modules don't interfere.
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'automatic_registration', false
|
||||
'DocumentationManifest',
|
||||
'automatic_registration',
|
||||
false
|
||||
);
|
||||
|
||||
Config::inst()->remove('DocumentationManifest', 'register_entities');
|
||||
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'register_entities', array(
|
||||
'DocumentationManifest',
|
||||
'register_entities',
|
||||
array(
|
||||
array(
|
||||
'Path' => DOCSVIEWER_PATH . "/tests/docs/",
|
||||
'Title' => 'Doc Test',
|
||||
|
@ -18,18 +18,24 @@ class DocumentationViewerVersionWarningTest extends SapphireTest
|
||||
|
||||
// explicitly use dev/docs. Custom paths should be tested separately
|
||||
Config::inst()->update(
|
||||
'DocumentationViewer', 'link_base', 'dev/docs'
|
||||
'DocumentationViewer',
|
||||
'link_base',
|
||||
'dev/docs'
|
||||
);
|
||||
|
||||
// disable automatic module registration so modules don't interfere.
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'automatic_registration', false
|
||||
'DocumentationManifest',
|
||||
'automatic_registration',
|
||||
false
|
||||
);
|
||||
|
||||
Config::inst()->remove('DocumentationManifest', 'register_entities');
|
||||
|
||||
Config::inst()->update(
|
||||
'DocumentationManifest', 'register_entities', array(
|
||||
'DocumentationManifest',
|
||||
'register_entities',
|
||||
array(
|
||||
array(
|
||||
'Path' => DOCSVIEWER_PATH . "/tests/docs/",
|
||||
'Title' => 'Doc Test',
|
||||
|
Loading…
x
Reference in New Issue
Block a user