mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX Allow using module on root URL space
This commit is contained in:
parent
b8cdec0531
commit
591b87e939
@ -27,8 +27,6 @@ class DocumentationViewer extends Controller {
|
||||
'LanguageForm',
|
||||
'doLanguageForm',
|
||||
'handleRequest',
|
||||
'fr', // better way of handling this?
|
||||
'en'
|
||||
);
|
||||
|
||||
static $casting = array(
|
||||
@ -38,6 +36,11 @@ class DocumentationViewer extends Controller {
|
||||
'LanguageTitle' => 'Text'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var String Same as the routing pattern set through Director::addRules().
|
||||
*/
|
||||
protected static $link_base = 'dev/docs/';
|
||||
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
@ -45,6 +48,24 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
if(!$canAccess) return Security::permissionFailure($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded to avoid "action doesnt exist" errors - all URL parts in this
|
||||
* controller are virtual and handled through handleRequest(), not controller methods.
|
||||
*/
|
||||
public function handleAction($request) {
|
||||
try{
|
||||
$response = parent::handleAction($request);
|
||||
} catch(SS_HTTPResponse_Exception $e) {
|
||||
if(strpos($e->getMessage(), 'does not exist') !== FALSE) {
|
||||
return $this;
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the url parsing for the documentation. In order to make this
|
||||
@ -59,8 +80,8 @@ class DocumentationViewer extends Controller {
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request) {
|
||||
|
||||
$this->Version = $request->shift();
|
||||
// Workaround for root routing, e.g. Director::addRules(10, array('$Action' => 'DocumentationViewer'))
|
||||
$this->Version = ($request->param('Action')) ? $request->param('Action') : $request->shift();
|
||||
$this->Lang = $request->shift();
|
||||
$this->ModuleName = $request->shift();
|
||||
$this->Remaining = $request->shift(10);
|
||||
@ -223,10 +244,11 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
if($modules) {
|
||||
foreach($modules as $module) {
|
||||
$filepath = $module->getPath() . '/index.md';
|
||||
if(file_exists($filepath)) {
|
||||
$absFilepath = $module->getPath() . '/index.md';
|
||||
$relativeFilePath = str_replace($module->getPath(), '', $absFilepath);
|
||||
if(file_exists($absFilepath)) {
|
||||
$page = new DocumentationPage(
|
||||
$filepath,
|
||||
$relativeFilePath,
|
||||
$module,
|
||||
$this->Lang,
|
||||
$this->Version
|
||||
@ -388,9 +410,6 @@ class DocumentationViewer extends Controller {
|
||||
public function Link($path = false) {
|
||||
$base = Director::absoluteBaseURL();
|
||||
|
||||
// @todo
|
||||
$loc = 'dev/docs/';
|
||||
|
||||
$version = ($this->Version) ? $this->Version . '/' : false;
|
||||
$lang = ($this->Lang) ? $this->Lang .'/' : false;
|
||||
$module = ($this->ModuleName) ? $this->ModuleName .'/' : false;
|
||||
@ -406,7 +425,7 @@ class DocumentationViewer extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
return $base . $loc . $version . $lang . $module . $action;
|
||||
return $base . self::$link_base . $version . $lang . $module . $action;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -451,4 +470,18 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
return $this->redirect($this->Link());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String
|
||||
*/
|
||||
static function set_link_base($base) {
|
||||
self::$link_base = $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
static function get_link_base() {
|
||||
return self::$link_base;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
### Sapphire Documentation Module
|
||||
# Sapphire Documentation Module
|
||||
|
||||
This module has been developed to read and display content from markdown files in webbrowser. It is an easy
|
||||
way to bundle end user documentation within a SilverStripe installation.
|
||||
@ -9,3 +9,13 @@ are available here.
|
||||
To include your docs file here create a __docs/en/index.md__ file. You can also include custom paths and versions. To configure the documentation system the configuration information is available on the [Configurations](dev/docs/en/sapphiredocs/configuration-options)
|
||||
page.
|
||||
|
||||
## Setup
|
||||
|
||||
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`:
|
||||
|
||||
DocumentationViewer::set_link_base('');
|
||||
Director::addRules(1, array(
|
||||
'$Action' => 'DocumentationViewer',
|
||||
'' => 'DocumentationViewer'
|
||||
));
|
Loading…
x
Reference in New Issue
Block a user