MINOR Updated piston dependency

git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@117891 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2011-04-10 20:11:27 +00:00
parent 4a849df06b
commit f33c56d6ea
15 changed files with 110 additions and 61 deletions

View File

@ -1,7 +1,7 @@
---
format: 1
handler:
commit: b1c93bd27a232267a2ab9e05f9372982b0781236
commit: fab93f80df203a75dc2dcc4fba721115ce4a9007
branch: master
lock: false
repository_class: Piston::Git::Repository

View File

@ -42,11 +42,13 @@ class DocumentationParser {
$md = self::rewrite_api_links($md, $page);
$md = self::rewrite_heading_anchors($md, $page);
$md = self::rewrite_code_blocks($md, $page);
require_once(BASE_PATH . '/sapphiredocs/thirdparty/markdown/markdown.php');
$html = Markdown($md);
return $html;
$parser = new MarkdownExtra_Parser();
$parser->no_markup = true;
return $parser->transform($md);
}
function rewrite_code_blocks($md) {

View File

@ -220,7 +220,8 @@ class DocumentationSearch {
'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')),
'Content' => DBField::create('HTMLText', $content),
'Score' => $hit->score,
'Number' => $k + 1
'Number' => $k + 1,
'ID' => md5($doc->getFieldValue('Link'))
));
$results->push($obj);
@ -340,6 +341,10 @@ class DocumentationSearch {
);
}
/**
* Renders the search results into a template. Either
* the search results template or the Atom feed
*/
public function renderResults() {
if(!$this->results) $this->performSearch();
if(!$this->outputController) return user_error('Call renderResults() on a DocumentationViewer instance.', E_USER_ERROR);
@ -350,7 +355,7 @@ class DocumentationSearch {
$templates = array('DocumentationViewer_results', 'DocumentationViewer');
if($request->requestVar('format') && $request->requestVar('format') == "rss") {
if($request->requestVar('format') && $request->requestVar('format') == "atom") {
// alter the fields for the opensearch xml.
$title = ($title = $this->getTitle()) ? ' - '. $title : "";
@ -391,7 +396,7 @@ class DocumentationOpenSearch_Controller extends Controller {
'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'
);
$data['SearchPageRss'] = $data['SearchPageLink'] . '&format=rss';
$data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
}

View File

@ -81,8 +81,8 @@ class DocumentationViewer extends Controller {
// css
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCore.css');
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCoreEclipse.css');
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shThemeEclipse.css');
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCoreRDark.css');
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shThemeRDark.css');
Requirements::customScript('jQuery(document).ready(function() {SyntaxHighlighter.all();});');
}
@ -169,7 +169,7 @@ class DocumentationViewer extends Controller {
// 'current' version mapping
$module = DocumentationService::is_registered_module($this->module, null, $this->getLang());
if($module) {
$current = $module->getCurrentVersion();
@ -186,14 +186,14 @@ class DocumentationViewer extends Controller {
$this->redirect($link, 301); // permanent redirect
return $this->response;
}
}
// Check if page exists, otherwise return 404
if(!$this->locationExists()) {
$body = $this->renderWith(get_class($this));
$this->response = new SS_HTTPResponse($body, 404);
return $this->response;
}
// Check if page exists, otherwise return 404
if(!$this->locationExists()) {
$body = $this->renderWith(get_class($this));
$this->response = new SS_HTTPResponse($body, 404);
return $this->response;
}
}
return parent::handleRequest($request);
@ -357,6 +357,7 @@ class DocumentationViewer extends Controller {
$output->push(new ArrayData(array(
'Title' => $module->getTitle(),
'Code' => $module,
'Link' => $this->Link(array_slice($this->Remaining, -1, -1), $module->moduleFolder),
'Content' => DBField::create("HTMLText", $content)
)));
}
@ -387,6 +388,7 @@ class DocumentationViewer extends Controller {
*/
function locationExists() {
$module = $this->getModule();
return (
$module
&& (
@ -528,6 +530,7 @@ class DocumentationViewer extends Controller {
// In case no folder exists, show a "not found" page.
$module = $this->getModule();
$url = $this->Remaining;
if($url && $module) {
$pages = DocumentationService::get_pages_from_folder($module, implode('/', $url), false);
// If no pages are found, the 404 is handled in the same template
@ -536,6 +539,14 @@ class DocumentationViewer extends Controller {
'Pages' => $pages
))->renderWith('DocFolderListing');
}
else {
// get all available modules and show a table of contents.
return $this->customise(array(
'Title' => _t('DocumentationViewer.MODULES', 'Modules'),
'Pages' => $this->getModules()
))->renderWith('DocFolderListing');
}
}
return false;
@ -583,7 +594,7 @@ class DocumentationViewer extends Controller {
$output = "";
foreach($pages as $page) {
$output = $page->Title .' | '. $output;
$output = $page->Title .' - '. $output;
}
return $output;
@ -597,12 +608,12 @@ class DocumentationViewer extends Controller {
*
* @return String
*/
public function Link($path = false) {
public function Link($path = false, $module = false) {
$base = Director::absoluteBaseURL();
$version = ($this->version) ? $this->version . '/' : false;
$lang = ($this->language) ? $this->language .'/' : false;
$module = ($this->module) ? $this->module .'/' : false;
$module = (!$module && $this->module) ? $this->module .'/' : $module;
$action = '';

View File

View File

@ -18,19 +18,22 @@ you need to add the following to your applications _config.php file:
DocumentationSearch::enable();
After adding that line you will also need to build the indexes of the search. You can run the following from your webbrowser or via sake
After adding that line you will also need to build the indexes of the search. You can do this either via your web browser by accessing
http://yoursite.com/dev/tasks/RebuildLuceneDocsIndex?flush=1
Or rebuild it via sake. You will want to set this up as a cron job if your documentation search needs to be updated on the fly
sake dev/tasks/RebuildLuceneDocsIndex flush=1
### Using a URL other than /dev/docs/
By default, the documentation is available in `dev/docs`. If you want it to live on the webroot instead of a subfolder,
add the following configuration to your `mysite/_config.php`:
add the following configuration to your.
DocumentationViewer::set_link_base('');
Director::addRules(1, array(
'$Action' => 'DocumentationViewer',
'' => 'DocumentationViewer'
));

View File

@ -47,7 +47,7 @@
</div>
<div id="footer">
<p>Documentation powered by <a href="http://www.silverstripe.org">SilverStripe</a>. Found a typo? <a href="http://github.com/chillu/silverstripe-doc-restructuring">Contribute to the Documentation Project</a>.</p>
<p>Documentation powered by <a href="http://www.silverstripe.org">SilverStripe</a>.</p>
</div>
</body>
</html>

View File

@ -1,10 +1,13 @@
<div id="home">
<% control Modules %>
<% if Content %>
<h2><% _t('DOCUMENTEDMODULES', 'Documented Modules') %></h2>
<% if Modules %>
<% control Modules %>
<div class="module">
$Content
<h3><a href="$Link">$Title</a></h3>
</div>
<% end_if %>
<% end_control %>
<% end_control %>
<% else %>
<p><% _t('NOMODULEDOCUMENTATION', 'No modules with documentation installed could be found.') %></p>
<% end_if %>
</div>

View File

@ -6,8 +6,7 @@
<% if Tags %><Tags>$Tags</Tags><% end_if %>
<% if Contact %><Contact>$Content</Contact><% end_if %>
<% if SearchPageLink %><Url type="text/html" template="$SearchPageLink" /><% end_if %>
<% if SearchPageRss %><Url type="application/rss+xml" template="$SearchPageRss" /><% end_if %>
<% if SearchPageJson %><Url type="application/x-suggestions+json" template="$SearchPageJson" /><% end_if %>
</OpenSearchDescription>
<% if SearchPageLink %><Url type="text/html" template="$SearchPageLink"></Url><% end_if %>
<% if SearchPageAtom %><Url type="application/atom+xml" template="$SearchPageAtom"></Url><% end_if %>
<% if SearchPageJson %><Url type="application/x-suggestions+json" template="$SearchPageJson"></Url><% end_if %>
</OpenSearchDescription>

View File

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<title>$Title</title>
<link>$Link</link>
<author>
<name>SilverStripe Ltd.</name>
</author>
<updated>$Now</updated>
<opensearch:totalResults>$TotalResults</opensearch:totalResults>
<opensearch:startIndex>$StartResult</opensearch:startIndex>
<opensearch:itemsPerPage>$PageLength</opensearch:itemsPerPage>
<opensearch:Query role="request" searchTerms="$Query" startIndex="$StartResult" count="$PageLength"></opensearch:Query>
<% control Results %>
<entry>
<title>$Title</title>
<link>$Link</link>
<opensearch:totalResults>$TotalResults</opensearch:totalResults>
<opensearch:startIndex>$StartResult</opensearch:startIndex>
<opensearch:itemsPerPage>$PageLength</opensearch:itemsPerPage>
<atom:link rel="search" type="application/opensearchdescription+xml" href="{$BaseHref}DocumentationSearch/opensearch"/>
<opensearch:Query role="request" searchTerms="$Query" startPage="1" />
<% control Results %>
<item>
<title>$Title</title>
<link>$Link</link>
<description>$Content.LimitCharacters(200)</description>
</item>
<% end_control %>
</channel>
</rss>
<link href="$Link">$Link</link>
<id>urn:uuid:$ID</id>
<content type="text">$Content.LimitCharacters(200)</content>
</entry>
<% end_control %>
</feed>

View File

@ -217,4 +217,24 @@ HTML;
$this->assertEquals("Foo Bar's Test page.", $page->getTitle());
$this->assertEquals("Foo Bar's Test page.", $page->Title);
}
function testParserConvertsSpecialCharacters() {
$page = new DocumentationPage();
$page->setRelativePath('CodeSnippets.md');
$page->setEntity(new DocumentationEntity('parser', '2.4', BASE_PATH . '/sapphiredocs/tests/docs-parser/'));
$parsed = DocumentationParser::parse($page, '/sapphiredocs/tests/docs-parser/');
// header elements parsed
$this->assertContains(
'&lt;% control Foo %&gt;',
$parsed
);
// paragraphs
$this->assertContains(
'&lt;% foo %&gt;',
$parsed
);
}
}

View File

@ -99,7 +99,7 @@ class DocumentationViewerTest extends FunctionalTest {
$this->assertFalse($child1->Children);
$child2 = $pagesArr[2];
$this->assertType('DataObjectSet', $child2->Children);
$this->assertInstanceOf('DataObjectSet', $child2->Children);
$this->assertEquals(
array('subfolder/subpage.md', 'subfolder/subsubfolder/'),

View File

@ -0,0 +1,6 @@
#### <% control Foo %>
code block
<% without formatting prefix %>
Paragraph with a segment of <% foo %>

View File

View File

@ -1419,8 +1419,9 @@ class Markdown_Parser {
$text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
'&amp;', $text);;
}
# Encode remaining <'s
$text = str_replace('<', '&lt;', $text);
# Encode remaining <'s and >'s
$text = str_replace(array('<','>'), array('&lt;','&gt;'), $text);
return $text;
}