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 format: 1
handler: handler:
commit: b1c93bd27a232267a2ab9e05f9372982b0781236 commit: fab93f80df203a75dc2dcc4fba721115ce4a9007
branch: master branch: master
lock: false lock: false
repository_class: Piston::Git::Repository repository_class: Piston::Git::Repository

View File

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

View File

@ -220,7 +220,8 @@ class DocumentationSearch {
'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')), 'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')),
'Content' => DBField::create('HTMLText', $content), 'Content' => DBField::create('HTMLText', $content),
'Score' => $hit->score, 'Score' => $hit->score,
'Number' => $k + 1 'Number' => $k + 1,
'ID' => md5($doc->getFieldValue('Link'))
)); ));
$results->push($obj); $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() { public function renderResults() {
if(!$this->results) $this->performSearch(); if(!$this->results) $this->performSearch();
if(!$this->outputController) return user_error('Call renderResults() on a DocumentationViewer instance.', E_USER_ERROR); 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'); $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. // alter the fields for the opensearch xml.
$title = ($title = $this->getTitle()) ? ' - '. $title : ""; $title = ($title = $this->getTitle()) ? ' - '. $title : "";
@ -391,7 +396,7 @@ class DocumentationOpenSearch_Controller extends Controller {
'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1' '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')); return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
} }

View File

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

View File

View File

@ -18,19 +18,22 @@ you need to add the following to your applications _config.php file:
DocumentationSearch::enable(); 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/ ### 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, 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(''); DocumentationViewer::set_link_base('');
Director::addRules(1, array( Director::addRules(1, array(
'$Action' => 'DocumentationViewer', '$Action' => 'DocumentationViewer',
'' => 'DocumentationViewer' '' => 'DocumentationViewer'
)); ));

View File

@ -47,7 +47,7 @@
</div> </div>
<div id="footer"> <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> </div>
</body> </body>
</html> </html>

View File

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

View File

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

View File

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<channel> <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> <title>$Title</title>
<link>$Link</link> <link href="$Link">$Link</link>
<id>urn:uuid:$ID</id>
<opensearch:totalResults>$TotalResults</opensearch:totalResults> <content type="text">$Content.LimitCharacters(200)</content>
<opensearch:startIndex>$StartResult</opensearch:startIndex> </entry>
<opensearch:itemsPerPage>$PageLength</opensearch:itemsPerPage> <% end_control %>
</feed>
<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>

View File

@ -217,4 +217,24 @@ HTML;
$this->assertEquals("Foo Bar's Test page.", $page->getTitle()); $this->assertEquals("Foo Bar's Test page.", $page->getTitle());
$this->assertEquals("Foo Bar's Test page.", $page->Title); $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); $this->assertFalse($child1->Children);
$child2 = $pagesArr[2]; $child2 = $pagesArr[2];
$this->assertType('DataObjectSet', $child2->Children); $this->assertInstanceOf('DataObjectSet', $child2->Children);
$this->assertEquals( $this->assertEquals(
array('subfolder/subpage.md', 'subfolder/subsubfolder/'), 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+);)/', $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
'&amp;', $text);; '&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; return $text;
} }