mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
MINOR: update references to sapphiredocs to docviewer. ENHANCEMENT: introduce DOCVIEWER_PATH and DOCVIEWER_DIR consts
This commit is contained in:
parent
4a40b51ab2
commit
34d46b7a5b
54
README.md
54
README.md
@ -3,7 +3,7 @@
|
|||||||
## Maintainer Contact
|
## Maintainer Contact
|
||||||
|
|
||||||
* Will Rossiter (Nickname: willr, wrossiter)
|
* Will Rossiter (Nickname: willr, wrossiter)
|
||||||
<will@silverstripe.com>
|
<will@fullscreen.io>
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@ -11,57 +11,13 @@
|
|||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
Reads markdown documentation files from the /docs/ folder in . To read documentation go to yoursite.com/dev/docs/.
|
Reads text files from a given list of folders from your installation and
|
||||||
|
provides a web interface for viewing.
|
||||||
|
|
||||||
|
To read documentation go to yoursite.com/dev/docs/
|
||||||
|
|
||||||
For more documentation on how to use the module please read /docs/Writing-Documentation.md
|
For more documentation on how to use the module please read /docs/Writing-Documentation.md
|
||||||
(or via this in /dev/docs/sapphiredocs/Writing-Documentation in your webbrowser)
|
(or via this in /dev/docs/sapphiredocs/Writing-Documentation in your webbrowser)
|
||||||
|
|
||||||
**Note** This module assumes you are using numeric values for your versions.
|
**Note** This module assumes you are using numeric values for your versions.
|
||||||
|
|
||||||
## Search ##
|
|
||||||
|
|
||||||
Search needs to be indexed manually with `dev/tasks/RebuildLuceneDocsIndex`.
|
|
||||||
|
|
||||||
## Syntax Highlighting ##
|
|
||||||
|
|
||||||
The custom Markdown parser can render custom prefixes for code blocks,
|
|
||||||
and render it via a [javascript syntax highlighter](http://alexgorbatchev.com/SyntaxHighlighter).
|
|
||||||
|
|
||||||
In:
|
|
||||||
|
|
||||||
:::php
|
|
||||||
my sourcecode
|
|
||||||
|
|
||||||
Out:
|
|
||||||
|
|
||||||
<pre class="brush: php">
|
|
||||||
my sourcecode
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
To include the syntax highlighter source, add the following to your `DocumentationViewer->init()`:
|
|
||||||
|
|
||||||
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
|
||||||
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shCore.js');
|
|
||||||
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js');
|
|
||||||
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushPHP.js');
|
|
||||||
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushXML.js');
|
|
||||||
// ... any additional syntaxes you want to support
|
|
||||||
Requirements::combine_files(
|
|
||||||
'syntaxhighlighter.js',
|
|
||||||
array(
|
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shCore.js',
|
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js',
|
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushPHP.js',
|
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushXML.js'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
Requirements::javascript('sapphiredocs/javascript/DocumentationViewer.js');
|
|
||||||
|
|
||||||
// css
|
|
||||||
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCore.css');
|
|
||||||
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCoreDefault.css');
|
|
||||||
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shThemeRDark.css');
|
|
||||||
|
|
||||||
You can overload the `DocumentationViewer` class and add a custom route through `Director::addRule()`
|
|
||||||
if you prefer not to modify the module file.
|
|
||||||
|
12
_config.php
12
_config.php
@ -1,12 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Documentation Configuration
|
* Documentation Configuration
|
||||||
*
|
*
|
||||||
* Please override any of these options in your own projects _config.php file.
|
* Please override any of these options in your own projects _config.php file.
|
||||||
* For more information and documentation see sapphiredocs/docs/en
|
* For more information and documentation see docviewer/docs/en
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if(!defined('DOCVIEWER_PATH')) {
|
||||||
|
define('DOCVIEWER_PATH', dirname(__FILE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!defined('DOCVIEWER_DIR')) {
|
||||||
|
define('DOCVIEWER_DIR', array_pop(explode(DIRECTORY_SEPARATOR, DOCVIEWER_PATH)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// default location for documentation. If you want this under a custom url
|
// default location for documentation. If you want this under a custom url
|
||||||
// define your own rule in your mysite/_config.php
|
// define your own rule in your mysite/_config.php
|
||||||
Director::addRules(100, array(
|
Director::addRules(100, array(
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* Parser wrapping the Markdown Extra parser (see http://michelf.com/projects/php-markdown/extra/).
|
* Parser wrapping the Markdown Extra parser (see http://michelf.com/projects/php-markdown/extra/).
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
class DocumentationParser {
|
class DocumentationParser {
|
||||||
|
|
||||||
@ -15,9 +15,10 @@ class DocumentationParser {
|
|||||||
static $heading_counts = array();
|
static $heading_counts = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a given path to the documentation for a file. Performs a case insensitive
|
* Parse a given path to the documentation for a file. Performs a case
|
||||||
* lookup on the file system. Automatically appends the file extension to one of the markdown
|
* insensitive lookup on the file system. Automatically appends the file
|
||||||
* extensions as well so /install/ in a web browser will match /install.md or /INSTALL.md
|
* extension to one of the markdown extensions as well so /install/ in a
|
||||||
|
* web browser will match /install.md or /INSTALL.md
|
||||||
*
|
*
|
||||||
* Filepath: /var/www/myproject/src/cms/en/folder/subfolder/page.md
|
* Filepath: /var/www/myproject/src/cms/en/folder/subfolder/page.md
|
||||||
* URL: http://myhost/mywebroot/dev/docs/2.4/cms/en/folder/subfolder/page
|
* URL: http://myhost/mywebroot/dev/docs/2.4/cms/en/folder/subfolder/page
|
||||||
@ -44,7 +45,7 @@ class DocumentationParser {
|
|||||||
$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(DOCVIEWER_PATH .'/thirdparty/markdown/markdown.php');
|
||||||
|
|
||||||
$parser = new MarkdownExtra_Parser();
|
$parser = new MarkdownExtra_Parser();
|
||||||
$parser->no_markup = true;
|
$parser->no_markup = true;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping store of given permalinks to the full documentation path or useful for customizing the
|
* A mapping store of given permalinks to the full documentation path or useful
|
||||||
* shortcut URLs used in the viewer.
|
* for customizing the shortcut URLs used in the viewer.
|
||||||
*
|
*
|
||||||
* Redirects the user from example.com/foo to example.com/en/module/foo
|
* Redirects the user from example.com/foo to example.com/en/module/foo
|
||||||
*
|
*
|
||||||
* @module sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationPermalinks {
|
class DocumentationPermalinks {
|
||||||
@ -19,13 +19,14 @@ class DocumentationPermalinks {
|
|||||||
/**
|
/**
|
||||||
* Add a mapping of nice short permalinks to a full long path
|
* Add a mapping of nice short permalinks to a full long path
|
||||||
*
|
*
|
||||||
* DocumentationPermalinks::add(array(
|
* <code>
|
||||||
* 'debugging' => 'current/en/sapphire/topics/debugging'
|
* DocumentationPermalinks::add(array(
|
||||||
* ));
|
* 'debugging' => 'current/en/sapphire/topics/debugging'
|
||||||
|
* ));
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
*
|
* Do not need to include the language or the version current as it
|
||||||
* You do not need to include the language or the version current as it will add it
|
* will add it based off the language or version in the session
|
||||||
* based off the language or version in the session
|
|
||||||
*/
|
*/
|
||||||
public static function add($map = array()) {
|
public static function add($map = array()) {
|
||||||
if(ArrayLib::is_associative($map)) {
|
if(ArrayLib::is_associative($map)) {
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Documentation Search powered by Lucene. You will need Zend_Lucene installed on your path
|
* Documentation Search powered by Lucene. You will need Zend_Lucene installed
|
||||||
* to rebuild the indexes run the {@link RebuildLuceneDocsIndex} task. You may wish to setup
|
* on your path.
|
||||||
* a cron job to remake the indexes on a regular basis.
|
|
||||||
*
|
*
|
||||||
* It has the ability to generate an OpenSearch RSS formatted feeds simply by using the URL
|
* To rebuild the indexes run the {@link RebuildLuceneDocsIndex} task. You may
|
||||||
|
* wish to setup a cron job to remake the indexes on a regular basis.
|
||||||
|
*
|
||||||
|
* This class has the ability to generate an OpenSearch RSS formatted feeds
|
||||||
|
* simply by using the URL:
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* yoursite.com/search/?q=Foo&format=rss. // Format can either be specified as rss or left off.
|
* yoursite.com/search/?q=Foo&format=rss. // Format can either be specified as rss or left off.
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* To get a specific amount of results you can also use the modifiers start and limit
|
* To get a specific amount of results you can also use the modifiers start and
|
||||||
|
* limit:
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* yoursite.com/search/?q=Foo&start=10&limit=10
|
* yoursite.com/search/?q=Foo&start=10&limit=10
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationSearch {
|
class DocumentationSearch {
|
||||||
@ -108,7 +112,7 @@ class DocumentationSearch {
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $index_location = 'sapphiredocs';
|
private static $index_location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an array of every single documentation page installed on the system.
|
* Generate an array of every single documentation page installed on the system.
|
||||||
@ -178,7 +182,13 @@ class DocumentationSearch {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_index_location() {
|
public function get_index_location() {
|
||||||
return TEMP_FOLDER . '/'. trim(self::$index_location, '/');
|
if(!self::$index_location)
|
||||||
|
self::$index_location = DOCVIEWER_DIR;
|
||||||
|
|
||||||
|
return Controller::join_links(
|
||||||
|
TEMP_FOLDER,
|
||||||
|
trim(self::$index_location, '/')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* DocumentationService
|
* DocumentationService
|
||||||
*
|
*
|
||||||
* Handles the management of the documentation services delivered by the entity.
|
* Handles the management of the documentation services delivered by the entity.
|
||||||
* Includes registering which components to document and handles the entities being
|
|
||||||
* documented
|
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* Includes registering which components to document and handles the entities being
|
||||||
|
* documented.
|
||||||
|
*
|
||||||
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationService {
|
class DocumentationService {
|
||||||
@ -28,7 +29,10 @@ class DocumentationService {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $ignored_files = array('.', '..', '.DS_Store', '.svn', '.git', 'assets', 'themes', '_images');
|
private static $ignored_files = array(
|
||||||
|
'.', '..', '.DS_Store',
|
||||||
|
'.svn', '.git', 'assets', 'themes', '_images'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case insenstive values to use as extensions on markdown pages. The
|
* Case insenstive values to use as extensions on markdown pages. The
|
||||||
@ -39,8 +43,12 @@ class DocumentationService {
|
|||||||
public static $valid_markdown_extensions = array('md', 'txt', 'markdown');
|
public static $valid_markdown_extensions = array('md', 'txt', 'markdown');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registered {@link DocumentationEntity} objects to include in the documentation.
|
* Registered {@link DocumentationEntity} objects to include in the
|
||||||
* Either pre-filled by the automatic filesystem parser or via {@link DocumentationService::register()}.
|
* documentation.
|
||||||
|
*
|
||||||
|
* Either pre-filled by the automatic filesystem parser or via
|
||||||
|
* {@link DocumentationService::register()}.
|
||||||
|
*
|
||||||
* Stores the {@link DocumentEntity} objects which contain the languages
|
* Stores the {@link DocumentEntity} objects which contain the languages
|
||||||
* and versions of each entity.
|
* and versions of each entity.
|
||||||
*
|
*
|
||||||
@ -132,8 +140,8 @@ class DocumentationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the entities which are listed for documentation. Optionally only get
|
* Return the entities which are listed for documentation. Optionally only
|
||||||
* entities which have a version or language given
|
* get entities which have a version or language given.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -157,7 +165,7 @@ class DocumentationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if a entity is registered with the documenter
|
* Check to see if a entity is registered with the documenter.
|
||||||
*
|
*
|
||||||
* @param String $entity entity name
|
* @param String $entity entity name
|
||||||
* @param String $version version
|
* @param String $version version
|
||||||
@ -250,7 +258,8 @@ class DocumentationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the docs from off a file system if automatic registration is turned on.
|
* Register the docs from off a file system if automatic registration is
|
||||||
|
* turned on.
|
||||||
*
|
*
|
||||||
* @see {@link DocumentationService::set_automatic_registration()}
|
* @see {@link DocumentationService::set_automatic_registration()}
|
||||||
*/
|
*/
|
||||||
@ -294,8 +303,8 @@ class DocumentationService {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a documentation page given a path and a file name. It ignores the extensions
|
* Find a documentation page given a path and a file name. It ignores the
|
||||||
* and simply compares the title.
|
* extensions and simply compares the title.
|
||||||
*
|
*
|
||||||
* Name may also be a path /install/foo/bar.
|
* Name may also be a path /install/foo/bar.
|
||||||
*
|
*
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Public facing controller for handling an opensearch interface based on
|
* Public facing controller for handling an opensearch interface based on
|
||||||
* the standard search form.
|
* the standard search form.
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationOpenSearchController extends ContentController {
|
class DocumentationOpenSearchController extends ContentController {
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
/**
|
/**
|
||||||
* Documentation Viewer.
|
* Documentation Viewer.
|
||||||
*
|
*
|
||||||
* Reads the bundled markdown files from documentation folders and displays the output (either
|
* Reads the bundled markdown files from documentation folders and displays the
|
||||||
* via markdown or plain text)
|
* output (either via markdown or plain text)
|
||||||
*
|
*
|
||||||
* For more documentation on how to use this class see the documentation in /sapphiredocs/docs folder
|
* For more documentation on how to use this class see the documentation in the
|
||||||
|
* docs folder
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationViewer extends Controller {
|
class DocumentationViewer extends Controller {
|
||||||
@ -35,6 +36,7 @@ class DocumentationViewer extends Controller {
|
|||||||
/**
|
/**
|
||||||
* The string name of the currently accessed {@link DocumentationEntity}
|
* The string name of the currently accessed {@link DocumentationEntity}
|
||||||
* object. To access the entire object use {@link getEntity()}
|
* object. To access the entire object use {@link getEntity()}
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $entity = '';
|
public $entity = '';
|
||||||
@ -59,41 +61,46 @@ class DocumentationViewer extends Controller {
|
|||||||
|
|
||||||
if(!$this->canView()) return Security::permissionFailure($this);
|
if(!$this->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
// javascript
|
|
||||||
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
||||||
|
|
||||||
Requirements::combine_files(
|
Requirements::combine_files(
|
||||||
'syntaxhighlighter.js',
|
'syntaxhighlighter.js',
|
||||||
array(
|
array(
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shCore.js',
|
DOCVIEWER_DIR .'/thirdparty/syntaxhighlighter/scripts/shCore.js',
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js',
|
DOCVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js',
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushPhp.js',
|
DOCVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushPhp.js',
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushXml.js',
|
DOCVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushXml.js',
|
||||||
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushCss.js',
|
DOCVIEWER_DIR . '/thirdparty/syntaxhighlighter/scripts/shBrushCss.js',
|
||||||
'sapphiredocs/javascript/shBrushSS.js'
|
DOCVIEWER_DIR . '/javascript/shBrushSS.js'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Requirements::javascript('sapphiredocs/javascript/DocumentationViewer.js');
|
Requirements::javascript(DOCVIEWER_DIR .'/javascript/DocumentationViewer.js');
|
||||||
|
Requirements::css(DOCVIEWER_DIR .'/css/shSilverStripeDocs.css');
|
||||||
|
|
||||||
// css
|
Requirements::css(DOCVIEWER_DIR .'/css/DocumentationViewer.css');
|
||||||
Requirements::css('sapphiredocs/css/shSilverStripeDocs.css');
|
|
||||||
|
|
||||||
Requirements::customScript('jQuery(document).ready(function() {SyntaxHighlighter.all();});');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can the user view this documentation. Hides all functionality for private wikis
|
* Can the user view this documentation. Hides all functionality for
|
||||||
|
* private wikis.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canView() {
|
public function canView() {
|
||||||
return (Director::isDev() || Director::is_cli() || !self::$check_permission || Permission::check(self::$check_permission));
|
return (Director::isDev() || Director::is_cli() ||
|
||||||
|
!self::$check_permission ||
|
||||||
|
Permission::check(self::$check_permission)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overloaded to avoid "action doesn't exist" errors - all URL parts in this
|
* Overloaded to avoid "action doesn't exist" errors - all URL parts in
|
||||||
* controller are virtual and handled through handleRequest(), not controller methods.
|
* this controller are virtual and handled through handleRequest(), not
|
||||||
|
* controller methods.
|
||||||
|
*
|
||||||
|
* @param SS_HTTPRequest
|
||||||
|
*
|
||||||
|
* @return SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function handleAction($request) {
|
public function handleAction($request) {
|
||||||
try {
|
try {
|
||||||
@ -123,7 +130,8 @@ class DocumentationViewer extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function handleRequest(SS_HTTPRequest $request) {
|
public function handleRequest(SS_HTTPRequest $request) {
|
||||||
// if we submitted a form, let that pass
|
// if we submitted a form, let that pass
|
||||||
if(!$request->isGET() || isset($_GET['action_results'])) return parent::handleRequest($request);
|
if(!$request->isGET() || isset($_GET['action_results']))
|
||||||
|
return parent::handleRequest($request);
|
||||||
|
|
||||||
$firstParam = ($request->param('Action')) ? $request->param('Action') : $request->shift();
|
$firstParam = ($request->param('Action')) ? $request->param('Action') : $request->shift();
|
||||||
$secondParam = $request->shift();
|
$secondParam = $request->shift();
|
||||||
|
@ -13,9 +13,11 @@
|
|||||||
* Versions are assumed to be in numeric format (e.g. '2.4'),
|
* Versions are assumed to be in numeric format (e.g. '2.4'),
|
||||||
*
|
*
|
||||||
* They're also parsed through version_compare() in {@link getStableVersion()}
|
* They're also parsed through version_compare() in {@link getStableVersion()}
|
||||||
* which assumes a certain format {@link http://php.net/manual/en/function.version-compare.php}
|
* which assumes a certain format:
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @see http://php.net/manual/en/function.version-compare.php
|
||||||
|
*
|
||||||
|
* @package docviewer
|
||||||
* @subpackage models
|
* @subpackage models
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* A specific page within a {@link DocumentationEntity}. Maps 1 to 1 to a file on the
|
* A specific page within a {@link DocumentationEntity}. Maps 1 to 1 to a file on the
|
||||||
* filesystem.
|
* filesystem.
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class DocumentationPage extends ViewableData {
|
class DocumentationPage extends ViewableData {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* For the hourly cron rebuild use RebuildLuceneDocusIndex_Hourly
|
* For the hourly cron rebuild use RebuildLuceneDocusIndex_Hourly
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage tasks
|
* @subpackage tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,14 +13,15 @@ class RebuildLuceneDocsIndex extends BuildTask {
|
|||||||
|
|
||||||
protected $title = "Rebuild Documentation Search Indexes";
|
protected $title = "Rebuild Documentation Search Indexes";
|
||||||
|
|
||||||
protected $description = "Rebuilds the indexes used for the search engine in sapphiredocs. Gathers all documentation files from your modules";
|
protected $description = "
|
||||||
|
Rebuilds the indexes used for the search engine in the docviewer.";
|
||||||
|
|
||||||
function run($request) {
|
function run($request) {
|
||||||
$this->rebuildIndexes();
|
$this->rebuildIndexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildIndexes($quiet = false) {
|
function rebuildIndexes($quiet = false) {
|
||||||
require_once(BASE_PATH . '/sapphiredocs/thirdparty/markdown/markdown.php');
|
require_once(DOCVIEWER_PATH .'/thirdparty/markdown/markdown.php');
|
||||||
require_once 'Zend/Search/Lucene.php';
|
require_once 'Zend/Search/Lucene.php';
|
||||||
|
|
||||||
ini_set("memory_limit", -1);
|
ini_set("memory_limit", -1);
|
||||||
@ -106,7 +107,7 @@ class RebuildLuceneDocsIndex extends BuildTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage tasks
|
* @subpackage tasks
|
||||||
*/
|
*/
|
||||||
class RebuildLuceneDocusIndex_Hourly extends HourlyTask {
|
class RebuildLuceneDocusIndex_Hourly extends HourlyTask {
|
||||||
|
43
docs/en/Syntax-Highlighting.md
Normal file
43
docs/en/Syntax-Highlighting.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Syntax Highlighting
|
||||||
|
|
||||||
|
The custom Markdown parser can render custom prefixes for code blocks, and
|
||||||
|
render it via a [javascript syntax highlighter](http://alexgorbatchev.com/SyntaxHighlighter).
|
||||||
|
|
||||||
|
In:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
my sourcecode
|
||||||
|
|
||||||
|
Out:
|
||||||
|
|
||||||
|
<pre class="brush: php">
|
||||||
|
my sourcecode
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
To include the syntax highlighter source, add the following to your `DocumentationViewer->init()`:
|
||||||
|
|
||||||
|
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
|
||||||
|
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shCore.js');
|
||||||
|
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js');
|
||||||
|
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushPHP.js');
|
||||||
|
Requirements::javascript('sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushXML.js');
|
||||||
|
// ... any additional syntaxes you want to support
|
||||||
|
Requirements::combine_files(
|
||||||
|
'syntaxhighlighter.js',
|
||||||
|
array(
|
||||||
|
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shCore.js',
|
||||||
|
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushJScript.js',
|
||||||
|
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushPHP.js',
|
||||||
|
'sapphiredocs/thirdparty/syntaxhighlighter/scripts/shBrushXML.js'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Requirements::javascript('sapphiredocs/javascript/DocumentationViewer.js');
|
||||||
|
|
||||||
|
// css
|
||||||
|
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCore.css');
|
||||||
|
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shCoreDefault.css');
|
||||||
|
Requirements::css('sapphiredocs/thirdparty/syntaxhighlighter/styles/shThemeRDark.css');
|
||||||
|
|
||||||
|
You can overload the `DocumentationViewer` class and add a custom route through `Director::addRule()`
|
||||||
|
if you prefer not to modify the module file.
|
@ -1,11 +1,7 @@
|
|||||||
# Writing Documentation
|
# Writing Documentation
|
||||||
|
|
||||||
Your documentation needs to go in the specific modules docs folder which it
|
The files have to end with the __.md__ or __.markdown__ extension. The
|
||||||
refers mostly too. For example if you want to document a feature of your
|
documentation viewer will automatically replace hyphens (-) with spaces.
|
||||||
custom module 'mymodule' you need to create markdown files in mymodule/docs/en/.
|
|
||||||
|
|
||||||
The files have to end with the __.md__ extension. The documentation viewer will
|
|
||||||
automatically replace hyphens (-) with spaces.
|
|
||||||
|
|
||||||
my-documentation-file.md
|
my-documentation-file.md
|
||||||
|
|
||||||
@ -60,7 +56,6 @@ default behaviour is to display an ordered list of links.
|
|||||||
The table of contents on each module page is generated based on where and what
|
The table of contents on each module page is generated based on where and what
|
||||||
headers you use.
|
headers you use.
|
||||||
|
|
||||||
|
|
||||||
## Images and Files
|
## Images and Files
|
||||||
|
|
||||||
If you want to attach images and other assets to a page you need to bundle those
|
If you want to attach images and other assets to a page you need to bundle those
|
||||||
|
@ -1,38 +1,79 @@
|
|||||||
# Sapphire Documentation Module
|
# Docviewer Module
|
||||||
|
|
||||||
This module has been developed to read and display content from markdown files in webbrowser. It is an easy
|
This module has been developed to read and display content from markdown and
|
||||||
way to bundle end user documentation within a SilverStripe installation.
|
plain text files in web browser. It provides an easy way to bundle end user
|
||||||
|
documentation within a SilverStripe installation or module.
|
||||||
See [Writing Documentation](dev/docs/en/sapphiredocs/writing-documentation) for more information on how to write markdown files which
|
|
||||||
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
|
## Setup
|
||||||
|
|
||||||
### Enabling Search
|
The module includes the ability to read documentation from any folder on your
|
||||||
|
file system. By standard, documentation should go in a __docs__ folder in the
|
||||||
|
root of your module or project documentation.
|
||||||
|
|
||||||
The module provides automatic search functionality via [Lucene Search](http://lucene.apache.org/java/docs/index.html). To enable search
|
### Standard
|
||||||
you need to add the following to your applications _config.php file:
|
|
||||||
|
If you follow the standard setup create a file in /<<module>>/__docs/_en/index.md__
|
||||||
|
file then include the following in your config file:
|
||||||
|
|
||||||
|
DocumentationService::set_automatic_registration(true);
|
||||||
|
|
||||||
|
Now visit yoursite.com/dev/docs you should see your module.
|
||||||
|
|
||||||
|
### Custom Folders
|
||||||
|
|
||||||
|
If you wish to register specific folders only, or folders in a non standard
|
||||||
|
location then you can register paths directly:
|
||||||
|
|
||||||
|
try {
|
||||||
|
DocumentationService::register(
|
||||||
|
$name = "sapphire",
|
||||||
|
$path = "/src/sapphire_master/docs/",
|
||||||
|
$version = 'trunk'
|
||||||
|
);
|
||||||
|
} catch(InvalidArgumentException $e) {
|
||||||
|
// Silence if path is not found (for CI environment)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
To configure the documentation system the configuration information is
|
||||||
|
available on the [Configurations](dev/docs/en/docviewer/configuration-options)
|
||||||
|
page.
|
||||||
|
|
||||||
|
## Writing documentation
|
||||||
|
|
||||||
|
See [Writing Documentation](dev/docs/en/sapphiredocs/writing-documentation)
|
||||||
|
for more information on how to write markdown files which are available here.
|
||||||
|
|
||||||
|
|
||||||
|
## Enabling Search
|
||||||
|
|
||||||
|
The module provides automatic search functionality via [Lucene Search](http://lucene.apache.org/java/docs/index.html).
|
||||||
|
|
||||||
|
To enable search 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 do this either via your web browser by accessing
|
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
|
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
|
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
|
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
|
||||||
add the following configuration to your.
|
live on the webroot instead of a subfolder or on another url address, add the
|
||||||
|
following configuration to your _config.php file:
|
||||||
|
|
||||||
DocumentationViewer::set_link_base('');
|
DocumentationViewer::set_link_base('');
|
||||||
|
|
||||||
Director::addRules(1, array(
|
Director::addRules(1, array(
|
||||||
'$Action' => 'DocumentationViewer',
|
'$Action' => 'DocumentationViewer',
|
||||||
'' => 'DocumentationViewer'
|
'' => 'DocumentationViewer'
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(function($) {
|
;(function($) {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
/** -----------------------------------------------
|
/** -----------------------------------------------
|
||||||
@ -52,8 +52,8 @@
|
|||||||
$("#Form_LanguageForm select").change(function() {
|
$("#Form_LanguageForm select").change(function() {
|
||||||
$("#Form_LanguageForm").submit();
|
$("#Form_LanguageForm").submit();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Syntaxhighlighter defaults
|
SyntaxHighlighter.defaults.toolbar = false;
|
||||||
SyntaxHighlighter.defaults.toolbar = false;
|
SyntaxHighlighter.all();
|
||||||
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
<% base_tag %>
|
<% base_tag %>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>SilverStripe Documentation</title>
|
<title>SilverStripe Documentation</title>
|
||||||
|
|
||||||
<% require themedCSS(DocumentationViewer) %>
|
|
||||||
<% require javascript(sapphire/thirdparty/jquery/jquery.js) %>
|
|
||||||
<% require javascript(sapphiredocs/javascript/DocumentationViewer.js) %>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
Permission:
|
|
||||||
admin:
|
|
||||||
Code: ADMIN
|
|
||||||
Group:
|
|
||||||
admins:
|
|
||||||
Code: admins
|
|
||||||
Permissions: =>Permission.admin
|
|
||||||
Member:
|
|
||||||
admin:
|
|
||||||
Email: admin@test.com
|
|
||||||
Groups: =>Group.admins
|
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class DocumentationEntityTest extends SapphireTest {
|
class DocumentationEntityTest extends SapphireTest {
|
||||||
|
|
||||||
function testDocumentationEntityAccessing() {
|
function testDocumentationEntityAccessing() {
|
||||||
$entity = new DocumentationEntity('docs', '1.0', '../sapphiredocs/tests/docs/', 'My Test');
|
$entity = new DocumentationEntity('docs', '1.0', DOCVIEWER_PATH .'/tests/docs/', 'My Test');
|
||||||
|
|
||||||
$this->assertEquals($entity->getTitle(), 'My Test');
|
$this->assertEquals($entity->getTitle(), 'My Test');
|
||||||
$this->assertEquals($entity->getVersions(), array('1.0'));
|
$this->assertEquals($entity->getVersions(), array('1.0'));
|
||||||
@ -20,13 +21,13 @@ class DocumentationEntityTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testgetStableVersion() {
|
function testgetStableVersion() {
|
||||||
$entity = new DocumentationEntity('docs', '1.0', '../sapphiredocs/tests/docs/', 'My Test');
|
$entity = new DocumentationEntity('docs', '1.0', DOCVIEWER_PATH. '/tests/docs/', 'My Test');
|
||||||
$entity->addVersion('1.1', '../sapphiredocs/tests/docs-v2.4/');
|
$entity->addVersion('1.1', DOCVIEWER_PATH. '/tests/docs-v2.4/');
|
||||||
$entity->addVersion('0.0', '../sapphiredocs/tests/docs-v3.0/');
|
$entity->addVersion('0.0', DOCVIEWER_PATH. '/tests/docs-v3.0/');
|
||||||
$this->assertEquals('1.1', $entity->getStableVersion(), 'Automatic version sorting');
|
$this->assertEquals('1.1', $entity->getStableVersion(), 'Automatic version sorting');
|
||||||
|
|
||||||
$entity = new DocumentationEntity('docs', '1.0', '../sapphiredocs/tests/docs/', 'My Test');
|
$entity = new DocumentationEntity('docs', '1.0', DOCVIEWER_PATH. '/tests/docs/', 'My Test');
|
||||||
$entity->addVersion('1.1.', '../sapphiredocs/tests/docs-v2.4/');
|
$entity->addVersion('1.1.', DOCVIEWER_PATH .'/tests/docs-v2.4/');
|
||||||
$entity->setStableVersion('1.0');
|
$entity->setStableVersion('1.0');
|
||||||
$this->assertEquals('1.0', $entity->getStableVersion(), 'Manual setting');
|
$this->assertEquals('1.0', $entity->getStableVersion(), 'Manual setting');
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationPageTest extends SapphireTest {
|
class DocumentationPageTest extends SapphireTest {
|
||||||
|
|
||||||
function testGetLink() {
|
function testGetLink() {
|
||||||
$entity = new DocumentationEntity('testmodule', null, BASE_PATH . '/sapphiredocs/tests/docs/');
|
$entity = new DocumentationEntity('testmodule', null, DOCVIEWER_PATH .'/tests/docs/');
|
||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
@ -32,8 +32,8 @@ class DocumentationPageTest extends SapphireTest {
|
|||||||
$this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link());
|
$this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link());
|
||||||
|
|
||||||
// test with version.
|
// test with version.
|
||||||
$entity = DocumentationService::register("versionlinks", BASE_PATH . "/sapphiredocs/tests/docs-v2.4/", '1');
|
$entity = DocumentationService::register("versionlinks", DOCVIEWER_PATH ."/tests/docs-v2.4/", '1');
|
||||||
$entity->addVersion('2', BASE_PATH . "/sapphiredocs/tests/docs-v3.0/");
|
$entity->addVersion('2', DOCVIEWER_PATH ."/tests/docs-v3.0/");
|
||||||
$entity->setStableVersion('2');
|
$entity->setStableVersion('2');
|
||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
@ -47,19 +47,19 @@ class DocumentationPageTest extends SapphireTest {
|
|||||||
function testGetRelativePath() {
|
function testGetRelativePath() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', null, DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$this->assertEquals('test.md', $page->getRelativePath());
|
$this->assertEquals('test.md', $page->getRelativePath());
|
||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('subfolder/subpage.md');
|
$page->setRelativePath('subfolder/subpage.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', null, DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$this->assertEquals('subfolder/subpage.md', $page->getRelativePath());
|
$this->assertEquals('subfolder/subpage.md', $page->getRelativePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetPath() {
|
function testGetPath() {
|
||||||
$absPath = BASE_PATH . '/sapphiredocs/tests/docs/';
|
$absPath = DOCVIEWER_PATH .'/tests/docs/';
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', null, $absPath));
|
$page->setEntity(new DocumentationEntity('mymodule', null, $absPath));
|
||||||
@ -74,7 +74,7 @@ class DocumentationPageTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testGetBreadcrumbTitle() {
|
function testGetBreadcrumbTitle() {
|
||||||
$entity = new DocumentationEntity('testmodule', null, BASE_PATH . '/sapphiredocs/tests/docs/');
|
$entity = new DocumentationEntity('testmodule', null, DOCVIEWER_PATH . '/tests/docs/');
|
||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
@ -84,7 +84,7 @@ class DocumentationPageTest extends SapphireTest {
|
|||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('subfolder/subpage.md');
|
$page->setRelativePath('subfolder/subpage.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', null, BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', null, DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$this->assertEquals('Mymodule - Subfolder - Subpage', $page->getBreadcrumbTitle());
|
$this->assertEquals('Mymodule - Subfolder - Subpage', $page->getBreadcrumbTitle());
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
*/
|
*/
|
||||||
class DocumentationParserTest extends SapphireTest {
|
class DocumentationParserTest extends SapphireTest {
|
||||||
|
|
||||||
function testRewriteCodeBlocks() {
|
function testRewriteCodeBlocks() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
$page->setLang('en');
|
$page->setLang('en');
|
||||||
$page->setVersion('2.4');
|
$page->setVersion('2.4');
|
||||||
$result = DocumentationParser::rewrite_code_blocks($page->getMarkdown());
|
$result = DocumentationParser::rewrite_code_blocks($page->getMarkdown());
|
||||||
@ -38,24 +38,24 @@ HTML;
|
|||||||
// Page on toplevel
|
// Page on toplevel
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('subfolder/subpage.md');
|
$page->setRelativePath('subfolder/subpage.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
$page->setLang('en');
|
$page->setLang('en');
|
||||||
$page->setVersion('2.4');
|
$page->setVersion('2.4');
|
||||||
|
|
||||||
$result = DocumentationParser::rewrite_image_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
$result = DocumentationParser::rewrite_image_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
'[relative image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/subfolder/_images/image.png)',
|
'[relative image link](' . Director::absoluteBaseURL() .'/'. DOCVIEWER_DIR . '/tests/docs/en/subfolder/_images/image.png)',
|
||||||
$result
|
$result
|
||||||
);
|
);
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
'[parent image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/_images/image.png)',
|
'[parent image link](' . Director::absoluteBaseURL() . '/'. DOCVIEWER_DIR. '/tests/docs/en/_images/image.png)',
|
||||||
$result
|
$result
|
||||||
);
|
);
|
||||||
// TODO Fix absolute image references
|
|
||||||
// $this->assertContains(
|
// $this->assertContains(
|
||||||
// '[absolute image link](' . Director::absoluteBaseURL() . '/sapphiredocs/tests/docs/en/_images/image.png)',
|
// '[absolute image link](' . Director::absoluteBaseURL() . '/'. DOCVIEWER_DIR. '/tests/docs/en/_images/image.png)',
|
||||||
// $result
|
// $result
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ HTML;
|
|||||||
// Page on toplevel
|
// Page on toplevel
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH .'/tests/docs/'));
|
||||||
$page->setLang('en');
|
$page->setLang('en');
|
||||||
$page->setVersion('2.4');
|
$page->setVersion('2.4');
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ HTML;
|
|||||||
function testHeadlineAnchors() {
|
function testHeadlineAnchors() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
$page->setLang('en');
|
$page->setLang('en');
|
||||||
$page->setVersion('2.4');
|
$page->setVersion('2.4');
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ HTML;
|
|||||||
// Page on toplevel
|
// Page on toplevel
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ HTML;
|
|||||||
// Page in subfolder
|
// Page in subfolder
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('subfolder/subpage.md');
|
$page->setRelativePath('subfolder/subpage.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ HTML;
|
|||||||
// Page in nested subfolder
|
// Page in nested subfolder
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('subfolder/subsubfolder/subsubpage.md');
|
$page->setRelativePath('subfolder/subsubfolder/subsubpage.md');
|
||||||
$page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/'));
|
$page->setEntity(new DocumentationEntity('mymodule', '2.4', DOCVIEWER_PATH . '/tests/docs/'));
|
||||||
|
|
||||||
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
$result = DocumentationParser::rewrite_relative_links($page->getMarkdown(), $page, 'mycontroller/cms/2.4/en/');
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ HTML;
|
|||||||
function testRetrieveMetaData() {
|
function testRetrieveMetaData() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('MetaDataTest.md');
|
$page->setRelativePath('MetaDataTest.md');
|
||||||
$page->setEntity(new DocumentationEntity('parser', '2.4', BASE_PATH . '/sapphiredocs/tests/docs-parser/'));
|
$page->setEntity(new DocumentationEntity('parser', '2.4', DOCVIEWER_PATH . '/tests/docs-parser/'));
|
||||||
|
|
||||||
DocumentationParser::retrieve_meta_data($page);
|
DocumentationParser::retrieve_meta_data($page);
|
||||||
|
|
||||||
@ -221,9 +221,9 @@ HTML;
|
|||||||
function testParserConvertsSpecialCharacters() {
|
function testParserConvertsSpecialCharacters() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('CodeSnippets.md');
|
$page->setRelativePath('CodeSnippets.md');
|
||||||
$page->setEntity(new DocumentationEntity('parser', '2.4', BASE_PATH . '/sapphiredocs/tests/docs-parser/'));
|
$page->setEntity(new DocumentationEntity('parser', '2.4', DOCVIEWER_PATH . '/tests/docs-parser/'));
|
||||||
|
|
||||||
$parsed = DocumentationParser::parse($page, '/sapphiredocs/tests/docs-parser/');
|
$parsed = DocumentationParser::parse($page, '/'.DOCVIEWER_DIR .'/tests/docs-parser/');
|
||||||
|
|
||||||
// header elements parsed
|
// header elements parsed
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
@ -239,21 +239,21 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testRewritingRelativeLinksToFiles() {
|
function testRewritingRelativeLinksToFiles() {
|
||||||
$folder = '/sapphiredocs/tests/docs-parser/';
|
$folder = DOCVIEWER_PATH . '/tests/docs-parser/';
|
||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('file-download.md');
|
$page->setRelativePath('file-download.md');
|
||||||
$page->setEntity(new DocumentationEntity('parser', '2.4', BASE_PATH . $folder));
|
$page->setEntity(new DocumentationEntity('parser', '2.4', $folder));
|
||||||
|
|
||||||
$parsed = DocumentationParser::parse($page, $folder);
|
$parsed = DocumentationParser::parse($page, $folder);
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
Controller::join_links($folder, '/en/_images/external_link.png'),
|
DOCVIEWER_DIR .'/tests/docs-parser/en/_images/external_link.png',
|
||||||
$parsed
|
$parsed
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
Controller::join_links($folder, '/en/_images/test.tar.gz'),
|
DOCVIEWER_DIR .'/tests/docs-parser/en/_images/test.tar.gz',
|
||||||
$parsed
|
$parsed
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,14 +13,14 @@ class DocumentationSearchTest extends FunctionalTest {
|
|||||||
if(!DocumentationSearch::enabled()) return;
|
if(!DocumentationSearch::enabled()) return;
|
||||||
|
|
||||||
DocumentationService::set_automatic_registration(false);
|
DocumentationService::set_automatic_registration(false);
|
||||||
DocumentationService::register('docs-search', BASE_PATH . '/sapphiredocs/tests/docs-search/');
|
DocumentationService::register('docs-search', DOCVIEWER_PATH . '/tests/docs-search/');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetAllPages() {
|
function testGetAllPages() {
|
||||||
if(!DocumentationSearch::enabled()) return;
|
if(!DocumentationSearch::enabled()) return;
|
||||||
|
|
||||||
DocumentationService::set_automatic_registration(false);
|
DocumentationService::set_automatic_registration(false);
|
||||||
DocumentationService::register('docs-search', BASE_PATH . '/sapphiredocs/tests/docs-search/');
|
DocumentationService::register('docs-search', DOCVIEWER_PATH . '/tests/docs-search/');
|
||||||
|
|
||||||
$search = DocumentationSearch::get_all_documentation_pages();
|
$search = DocumentationSearch::get_all_documentation_pages();
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationServiceTest extends SapphireTest {
|
class DocumentationServiceTest extends SapphireTest {
|
||||||
|
|
||||||
function testGetPagesFromFolder() {
|
function testGetPagesFromFolder() {
|
||||||
$entity = DocumentationService::register('testdocs', BASE_PATH . '/sapphiredocs/tests/docs/');
|
$entity = DocumentationService::register('testdocs', DOCVIEWER_PATH . '/tests/docs/');
|
||||||
$pages = DocumentationService::get_pages_from_folder($entity);
|
$pages = DocumentationService::get_pages_from_folder($entity);
|
||||||
|
|
||||||
$this->assertContains('index.md', $pages->column('Filename'), 'The tests/docs/en folder should contain a index file');
|
$this->assertContains('index.md', $pages->column('Filename'), 'The tests/docs/en folder should contain a index file');
|
||||||
@ -28,7 +28,7 @@ class DocumentationServiceTest extends SapphireTest {
|
|||||||
|
|
||||||
|
|
||||||
function testGetPagesFromFolderRecursive() {
|
function testGetPagesFromFolderRecursive() {
|
||||||
$entity = DocumentationService::register('testdocsrecursive', BASE_PATH . '/sapphiredocs/tests/docs-recursive/');
|
$entity = DocumentationService::register('testdocsrecursive', DOCVIEWER_PATH . '/tests/docs-recursive/');
|
||||||
|
|
||||||
$pages = DocumentationService::get_pages_from_folder($entity, null, true);
|
$pages = DocumentationService::get_pages_from_folder($entity, null, true);
|
||||||
|
|
||||||
@ -43,19 +43,19 @@ class DocumentationServiceTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testFindPath() {
|
function testFindPath() {
|
||||||
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/");
|
DocumentationService::register("DocumentationViewerTests", DOCVIEWER_PATH . "/tests/docs/");
|
||||||
|
|
||||||
// file
|
// file
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('test'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('test'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/test.md", $path);
|
$this->assertEquals(DOCVIEWER_PATH . "/tests/docs/en/test.md", $path);
|
||||||
|
|
||||||
// the home page. The path finder should go to the index.md file in the default language
|
// the home page. The path finder should go to the index.md file in the default language
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array(''));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array(''));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/index.md", $path);
|
$this->assertEquals(DOCVIEWER_PATH . "/tests/docs/en/index.md", $path);
|
||||||
|
|
||||||
// second level
|
// second level
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path);
|
$this->assertEquals(DOCVIEWER_PATH . "/tests/docs/en/subfolder/subpage.md", $path);
|
||||||
|
|
||||||
// subsubfolder has no index file. It should fail instead the viewer should pick up on this
|
// subsubfolder has no index file. It should fail instead the viewer should pick up on this
|
||||||
// and display the listing of the folder
|
// and display the listing of the folder
|
||||||
@ -64,11 +64,11 @@ class DocumentationServiceTest extends SapphireTest {
|
|||||||
|
|
||||||
// third level
|
// third level
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
$this->assertEquals(DOCVIEWER_PATH . "/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
||||||
|
|
||||||
// with trailing slash
|
// with trailing slash
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
$this->assertEquals(DOCVIEWER_PATH . "/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,13 +4,12 @@
|
|||||||
* Some of these tests are simply checking that pages load. They should not assume
|
* Some of these tests are simply checking that pages load. They should not assume
|
||||||
* somethings working.
|
* somethings working.
|
||||||
*
|
*
|
||||||
* @package sapphiredocs
|
* @package docviewer
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DocumentationViewerTest extends FunctionalTest {
|
class DocumentationViewerTest extends FunctionalTest {
|
||||||
|
|
||||||
static $fixture_file = 'sapphiredocs/tests/DocumentTests.yml';
|
|
||||||
|
|
||||||
protected $autoFollowRedirection = false;
|
protected $autoFollowRedirection = false;
|
||||||
|
|
||||||
function setUpOnce() {
|
function setUpOnce() {
|
||||||
@ -26,12 +25,12 @@ class DocumentationViewerTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues
|
// We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues
|
||||||
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/", '2.3');
|
DocumentationService::register("DocumentationViewerTests", DOCVIEWER_PATH . "/tests/docs/", '2.3');
|
||||||
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-v2.4/", '2.4', 'Doc Test', true);
|
DocumentationService::register("DocumentationViewerTests", DOCVIEWER_PATH . "/tests/docs-v2.4/", '2.4', 'Doc Test', true);
|
||||||
DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-v3.0/", '3.0', 'Doc Test');
|
DocumentationService::register("DocumentationViewerTests", DOCVIEWER_PATH . "/tests/docs-v3.0/", '3.0', 'Doc Test');
|
||||||
|
|
||||||
DocumentationService::register("DocumentationViewerAltModule1", BASE_PATH . "/sapphiredocs/tests/docs-parser/", '1.0');
|
DocumentationService::register("DocumentationViewerAltModule1", DOCVIEWER_PATH . "/tests/docs-parser/", '1.0');
|
||||||
DocumentationService::register("DocumentationViewerAltModule2", BASE_PATH . "/sapphiredocs/tests/docs-search/", '1.0');
|
DocumentationService::register("DocumentationViewerAltModule2", DOCVIEWER_PATH . "/tests/docs-search/", '1.0');
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDownOnce() {
|
function tearDownOnce() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user