mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
MINOR: merging changes from ss2doc back. APICHANGE: renamed DocumentationOpenSearch_Controller to DocumentationOpenSearchController. MINOR: renamed left and right column to more generic content/sidebar columns
This commit is contained in:
parent
035df99088
commit
56578742f4
@ -131,16 +131,18 @@ class DocumentationSearch {
|
||||
/**
|
||||
* Enable searching documentation
|
||||
*/
|
||||
public static function enable() {
|
||||
self::$enabled = true;
|
||||
public static function enable($enabled = true) {
|
||||
self::$enabled = $enabled;
|
||||
|
||||
// include the zend search functionality
|
||||
set_include_path(
|
||||
dirname(dirname(__FILE__)) . '/thirdparty/'. PATH_SEPARATOR .
|
||||
get_include_path()
|
||||
);
|
||||
if($enabled) {
|
||||
// include the zend search functionality
|
||||
set_include_path(
|
||||
dirname(dirname(__FILE__)) . '/thirdparty/'. PATH_SEPARATOR .
|
||||
get_include_path()
|
||||
);
|
||||
|
||||
require_once 'Zend/Search/Lucene.php';
|
||||
require_once 'Zend/Search/Lucene.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -378,35 +380,4 @@ class DocumentationSearch {
|
||||
|
||||
return $this->outputController->customise($data)->renderWith($templates);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Public facing controller for handling search.
|
||||
*
|
||||
* @package sapphiredocs
|
||||
*/
|
||||
|
||||
class DocumentationOpenSearch_Controller extends Controller {
|
||||
|
||||
function index() {
|
||||
return $this->httpError('404');
|
||||
}
|
||||
|
||||
function description() {
|
||||
$viewer = new DocumentationViewer();
|
||||
|
||||
if(!DocumentationViewer::canView()) return Security::permissionFailure($this);
|
||||
|
||||
$data = DocumentationSearch::get_meta_data();
|
||||
$link = Director::absoluteBaseUrl() .
|
||||
$data['SearchPageLink'] = Controller::join_links(
|
||||
$viewer->Link(),
|
||||
'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'
|
||||
);
|
||||
|
||||
$data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
|
||||
|
||||
return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
|
||||
}
|
||||
}
|
39
code/controllers/DocumentationOpenSearchController.php
Normal file
39
code/controllers/DocumentationOpenSearchController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Public facing controller for handling an opensearch interface based on
|
||||
* the standard search form.
|
||||
*
|
||||
* @package sapphiredocs
|
||||
*/
|
||||
|
||||
class DocumentationOpenSearchController extends ContentController {
|
||||
|
||||
static $allowed_actions = array(
|
||||
'description'
|
||||
);
|
||||
|
||||
function index() {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
|
||||
function description() {
|
||||
$viewer = new DocumentationViewer();
|
||||
|
||||
if(!$viewer->canView()) return Security::permissionFailure($this);
|
||||
if(!DocumentationSearch::enabled()) return $this->httpError('404');
|
||||
|
||||
$data = DocumentationSearch::get_meta_data();
|
||||
$link = Director::absoluteBaseUrl() .
|
||||
$data['SearchPageLink'] = Controller::join_links(
|
||||
$viewer->Link(),
|
||||
'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'
|
||||
);
|
||||
|
||||
$data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
|
||||
|
||||
return $this->customise(
|
||||
new ArrayData($data)
|
||||
)->renderWith(array('OpenSearchDescription'));
|
||||
}
|
||||
}
|
@ -296,13 +296,13 @@ class DocumentationViewer extends Controller {
|
||||
*/
|
||||
function getVersions($entity = false) {
|
||||
if(!$entity) $entity = $this->entity;
|
||||
|
||||
|
||||
$entity = DocumentationService::is_registered_entity($entity);
|
||||
if(!$entity) return false;
|
||||
|
||||
|
||||
$versions = $entity->getVersions();
|
||||
$output = new DataObjectSet();
|
||||
|
||||
|
||||
if($versions) {
|
||||
$lang = $this->getLang();
|
||||
$currentVersion = $this->getVersion();
|
||||
@ -681,12 +681,7 @@ class DocumentationViewer extends Controller {
|
||||
* @return Form
|
||||
*/
|
||||
function LanguageForm() {
|
||||
if($entity = $this->getEntity()) {
|
||||
$langs = DocumentationService::get_registered_languages($entity->getFolder());
|
||||
}
|
||||
else {
|
||||
$langs = DocumentationService::get_registered_languages();
|
||||
}
|
||||
$langs = $this->getLanguages();
|
||||
|
||||
$fields = new FieldSet(
|
||||
$dropdown = new DropdownField(
|
||||
|
@ -63,7 +63,12 @@ fieldset { border: none; }
|
||||
#footer { width: 960px; margin: 22px auto; }
|
||||
#footer p { font-size: 11px; line-height: 11px; color: #798D85;}
|
||||
#footer p a { color: #798D85;}
|
||||
|
||||
|
||||
/* Search */
|
||||
#search { float: right; }
|
||||
#search label { display: none; }
|
||||
/* Breadcrumbs */
|
||||
#breadcrumbs { float: left; }
|
||||
/* Content */
|
||||
#layout { }
|
||||
#content { }
|
||||
@ -89,14 +94,14 @@ fieldset { border: none; }
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#left-column { width: 640px; float: left; }
|
||||
#content-column { width: 640px; float: left; }
|
||||
|
||||
#right-column {
|
||||
#sidebar-column {
|
||||
width: 260px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#right-column .box {
|
||||
#sidebar-column .box {
|
||||
margin: 0 12px 12px 0;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
// Remove existing anchor redirection in the url
|
||||
var pageURL = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, '');
|
||||
|
||||
$('#left-column h1[id], #left-column h2[id], #left-column h3[id], #left-column h4[id]').each(function(i) {
|
||||
$('#content-column h1[id], #content-column h2[id], #content-column h3[id], #content-column h4[id]').each(function(i) {
|
||||
var current = $(this);
|
||||
toc += '<li class="' + current.attr("tagName").toLowerCase() + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>';
|
||||
});
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
var url = window.location.href;
|
||||
|
||||
$("#left-column h1[id], #left-column h2[id], #left-column h3[id], #left-column h4[id], #left-column h5[id], #left-column h6[id]").each(function() {
|
||||
$("#content-column h1[id], #content-column h2[id], #content-column h3[id], #content-column h4[id], #content-column h5[id], #content-column h6[id]").each(function() {
|
||||
var link = '<a class="heading-anchor-link" title="Link to this section" href="'+ url + '#' + $(this).attr('id') + '">¶</a>';
|
||||
$(this).append(' ' + link);
|
||||
});
|
||||
|
@ -3,12 +3,12 @@
|
||||
<% end_if %>
|
||||
|
||||
<div id="documentation-page">
|
||||
<div id="left-column">
|
||||
<div id="content-column">
|
||||
$Content
|
||||
</div>
|
||||
|
||||
<% if Content %>
|
||||
<div id="right-column">
|
||||
<div id="sidebar-column">
|
||||
<% include DocTableOfContents %>
|
||||
<% include DocInThisModule %>
|
||||
</div>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<% end_if %>
|
||||
|
||||
<div id="module-home">
|
||||
<div id="left-column">
|
||||
<div id="content-column">
|
||||
<% if Content %>
|
||||
$Content
|
||||
<% else %>
|
||||
@ -11,7 +11,7 @@
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
<div id="right-column">
|
||||
<div id="sidebar-column">
|
||||
<% include DocInThisModule %>
|
||||
</div>
|
||||
</div>
|
@ -1,5 +1,5 @@
|
||||
<div id="documentation-page">
|
||||
<div id="left-column">
|
||||
<div id="content-column">
|
||||
<p>Your search for <strong>"$Query.XML"</strong> found $TotalResults result<% if TotalResults != 1 %>s<% end_if %>.</p>
|
||||
|
||||
<% if Results %>
|
||||
@ -40,7 +40,7 @@
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
<div id="right-column">
|
||||
<div id="sidebar-column">
|
||||
|
||||
</div>
|
||||
</div>
|
@ -5,7 +5,7 @@
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class DocumentationSearchTest extends SapphireTest {
|
||||
class DocumentationSearchTest extends FunctionalTest {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
@ -17,7 +17,6 @@ class DocumentationSearchTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testGetAllPages() {
|
||||
|
||||
if(!DocumentationSearch::enabled()) return;
|
||||
|
||||
DocumentationService::set_automatic_registration(false);
|
||||
@ -27,4 +26,25 @@ class DocumentationSearchTest extends SapphireTest {
|
||||
|
||||
$this->assertEquals(7, $search->Count(), '5 pages. 5 pages in entire folder');
|
||||
}
|
||||
|
||||
function testOpenSearchControllerAccessible() {
|
||||
$c = new DocumentationOpenSearchController();
|
||||
|
||||
$response = $c->handleRequest(new SS_HTTPRequest('GET', ''));
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
// test accessing it when the search isn't active
|
||||
DocumentationSearch::enable(false);
|
||||
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description/'));
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
// test we get a response to the description. The meta data test will check
|
||||
// that the individual fields are valid but we should check urls are there
|
||||
DocumentationSearch::enable(true);
|
||||
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'description'));
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
$desc = new SimpleXMLElement($response->getBody());
|
||||
$this->assertEquals(2, count($desc->Url));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user