Commit c1fdb6d0 authored by Alexandre Israël's avatar Alexandre Israël

init doc

parent bcd54b33
Xtended Content for File
========================
......@@ -13,7 +13,7 @@ class LoadMarkdown
{
public function getContent($content){
$parsedown = New Parsedown();
$parsedown = New \Parsedown();
return $parsedown->text($content);
}
......
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: aisrael
* Date: 20/08/2018
* Time: 16:37
*/
namespace Drupal\xtcfile\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\xtc\XtendedContent\API\Config;
class XtcDocsController extends ControllerBase
{
/**
* @param $module
*
* @return array
*/
public function get($module){
$values = Config::getDocs($module);
return [
'#theme' => 'xtc_mkdocs',
'#response' => $values,
];
}
/**
* @return string
*/
public function getTitle() {
return 'Documentation for ' . $this->getModuleName();
}
/**
* @return string
*/
protected function getModuleName(){
$machinename = \Drupal::request()->get('module');
return \Drupal::moduleHandler()->getName($machinename);
}
}
<?php
/**
* Created by PhpStorm.
* User: aisrael
* Date: 20/08/2018
* Time: 16:37
*/
namespace Drupal\xtcfile\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\xtc\XtendedContent\API\Config;
class XtcDocsPageController extends ControllerBase
{
/**
* @param $module
* @param $id
*
* @return array
*/
public function get($module, $id){
$path = explode('-',$id);
if(count($path) == 1){
$values['parent'] = Url::fromRoute('xtcfile.docs.docs', ['module'
=> $module])->toString();
}
else {
$up = $path;
unset($up[count($path)-1]);
$values['parent'] = implode('-', $up);
}
$item = $this->getItem($this->getIndex($module), $path);
$values['title'] = key($item);
$values['path'] = $id;
$current = current($item);
if(is_array($current)){
$values['content'] = '';
$values['subpages'] = $current;
}
else{
$values['content'] = Config::getDocsPage($module, $current);
}
return [
'#theme' => 'xtc_mkdocs_page',
'#response' => $values,
];
}
/**
* @param $module
*
* @return array
*/
protected function getIndex($module){
return Config::getDocs($module)['pages'];
}
/**
* @param $index
* @param $path
* @param int $level
*
* @return mixed
*/
protected function getItem($index, $path, $level = 0){
$id = intval($path[$level]);
$item = $index[$id];
$next = $level+1;
if($next+1 < count($path)){
$item = $this->getItem(current($item), $path, $next);
}
return $item;
}
/**
* @return string
*/
public function getTitle() {
$request = \Drupal::request();
$name = \Drupal::moduleHandler()->getName($request->get('module'));
return $this->getPageTitle($request->get('module'), $request->get('id'))
. $this->t(' - Documentation for :name', [':name' => $name]);
}
/**
* @param $module
* @param $id
*
* @return int|null|string
*/
protected function getPageTitle($module, $id){
$path = explode('-', $id);
$item = $this->getItem($this->getIndex($module), $path);
return key($item);
}
}
<?php
/**
* Created by PhpStorm.
* User: aisrael
* Date: 20/08/2018
* Time: 16:37
*/
namespace Drupal\xtcfile\Controller;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
class XtcDocumentationController extends ControllerBase
{
protected $module;
public function get() {
// We are checking permissions, so add the user.permissions cache context.
$cacheability = new CacheableMetadata();
$modules = \Drupal::moduleHandler()->getModuleList();
$output = [
'#theme' => 'xtc_documentation',
'#links' => [],
];
foreach($modules as $name => $module){
$this->module = $name;
$helpLink = Link::createFromRoute($this->t('Help'), 'help.page',
['name' => $name])->toString();
$output['#links'][$name] =[
'#theme' => 'xtc_docs_links',
'#name' => \Drupal::moduleHandler()->getName($name),
'#help' => $helpLink,
'#docs' => $this->link2Docs(),
'#readme' => $this->link2Readme(),
'#empty' => $this->t('There is currently documentation available.'),
];
$cacheability->addCacheableDependency($module);
}
$cacheability->applyTo($output);
return $output;
}
public function getHelp(){
return '<h2>README file</h2><p>View ' . $this->link2Readme() . '.</p>' .
'<h2>Documentation</h2><p>Read ' . $this->link2Docs() . '.</p>'
;
}
/**
* @param $module
*
* @return string
*/
public function link2Readme($text = 'README'){
$pathMd = file_exists(\Drupal::moduleHandler()
->getModule($this->module)->getPath() .'/README.md');
$pathTxt = file_exists(\Drupal::moduleHandler()
->getModule($this->module)->getPath() .'/README.txt');
$exist = ($pathTxt || $pathMd);
if($exist) {
return Link::createFromRoute($this->t($text), 'xtcfile.docs.readme', [
'module' => $this->module])->toString();
}
}
/**
* @param $module
*
* @return string
*/
public function link2Docs($text = 'Documentation'){
$path = \Drupal::moduleHandler()->getModule($this->module)->getPath() .'/help/mkdocs.yml';
if(file_exists($path)){
return Link::createFromRoute($this->t($text), 'xtcfile.docs.docs',
['module' => $this->module])->toString();
}
}
}
......@@ -9,7 +9,6 @@
namespace Drupal\xtcfile\Controller;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Controller\ControllerBase;
use Drupal\xtc\XtendedContent\API\Config;
......@@ -22,7 +21,11 @@ class XtcFileController extends ControllerBase
* @return array
*/
public function file($alias) {
$values['body'] = Json::encode(Config::getProfile($alias)->get());
$values['body'] = '';
$handler = Config::getProfile($alias);
if(!empty($handler)){
$values['body'] = $handler->get();
}
return [
'#theme' => 'xtc_file',
'#response' => $values,
......
<?php
/**
* Created by PhpStorm.
* User: aisrael
* Date: 20/08/2018
* Time: 16:37
*/
namespace Drupal\xtcfile\Controller;
use Drupal\xtc\XtendedContent\API\Config;
class XtcReadmeController extends XtcFileController
{
/**
* @param $alias
*
* @return array
*/
public function file($module) {
foreach(['README.md', 'README.txt'] as $path){
$profile = [
'type' => 'readme',
'abs_path' => false,
'module' => $module,
'path' => $path,
];
$content = Config::getFromProfile($profile) ?? '';
if(!empty($content)){
break;
}
}
if(empty($content)){
$content = "<h2>README file is empty or needs to be created.</h2>
<p>Please contact the maintainer of the module.</p>
";
}
$values['body'] = $content;
return [
'#theme' => 'xtc_file',
'#response' => $values,
];
}
public function getTitle() {
return $this->getModuleName() . ' - README file';
}
protected function getType() {
return 'file';
}
protected function getModuleName(){
$machinename = \Drupal::request()->get('module');
return \Drupal::moduleHandler()->getName($machinename);
}
}
......@@ -14,17 +14,13 @@ use Drupal\xtcfile\API\LoadCsv;
* description = @Translation("CSV File for XTC description.")
* )
*/
class Csv extends FileBase {
class Csv extends FileBase
{
public function get(){
$this->buildPath();
if(file_exists($this->options['path'])){
$content = file_get_contents($this->options['path']);
$csv = New LoadCsv();
$this->content = $csv->getContent($content);
}
return $this->content;
protected function processContent(){
$csv = New LoadCsv();
$this->content = $csv->getContent($this->content);
}
}
......@@ -16,10 +16,14 @@ abstract class FileBase extends XtcHandlerPluginBase
$this->buildPath();
if(file_exists($this->options['path'])){
$this->content = file_get_contents($this->options['path']);
$this->processContent();
}
return $this->content;
}
protected function processContent(){
}
public function setOptions() : XtcHandlerPluginBase{
$options['path'] = $this->buildPath();
$this->options = $options;
......
......@@ -17,12 +17,8 @@ use Drupal\Component\Serialization\Json as JsonSerializer;
class Json extends FileBase
{
public function get(){
$this->buildPath();
if(file_exists($this->options['path'])){
$this->content = JsonSerializer::decode(file_get_contents($this->options['path']));
}
return $this->content;
protected function processContent(){
$this->content = JsonSerializer::decode($this->content);
}
}
......@@ -17,14 +17,9 @@ use Drupal\xtcfile\API\LoadMarkdown;
class Markdown extends FileBase
{
public function get(){
$this->buildPath();
if(file_exists($this->options['path'])){
$content = file_get_contents($this->options['path']);
$markdown = New LoadMarkdown();
$this->content = $markdown->getContent($content);
}
return $this->content;
protected function processContent(){
$markdown = New LoadMarkdown();
$this->content = $markdown->getContent($this->content);
}
}
<?php
namespace Drupal\xtcfile\Plugin\XtcHandler;
use Drupal\Core\Serialization\Yaml;
use Drupal\xtcfile\API\LoadMarkdown;
/**
* Plugin implementation of the xtc_handler.
*
* @XtcHandler(
* id = "mkdocs",
* label = @Translation("MkDocs File for XTC"),
* description = @Translation("MkDocs File for XTC description.")
* )
*/
class MkDocs extends FileBase
{
protected function processContent(){
if ('mkdocs.yml' == basename($this->profile['path'])){
$this->content = Yaml::decode($this->content);
}
else{
$markdown = New LoadMarkdown();
$this->content = $markdown->getContent($this->content);
}
}
}
<?php
namespace Drupal\xtcfile\Plugin\XtcHandler;
/**
* Plugin implementation of the xtc_handler.
*
* @XtcHandler(
* id = "readme",
* label = @Translation("Readme File for XTC"),
* description = @Translation("Readme File for XTC description.")
* )
*/
class Readme extends Markdown
{
}
......@@ -17,13 +17,8 @@ use Drupal\Core\Serialization\Yaml as YamlSerializer;
class Yaml extends FileBase
{
public function get(){
$this->buildPath();
if(file_exists($this->options['path'])){
$this->content = YamlSerializer::decode(file_get_contents($this->options['path']));
}
return $this->content;
protected function processContent(){
$this->content = YamlSerializer::decode($this->content);
}
}
{% if help or docs or readme %}
<li style="float: left; width:25%; height:25px;">
{{ name }}
{% if help %}
[ {{ help }} ]
{% endif %}
{% if docs %}
[ {{ docs }} ]
{% endif %}
{% if readme %}
[ {{ readme }} ]
{% endif %}
</li>
{% endif %}
<p>This page provides links to Readme page and Documentation based on MkDocs standards.</p>
<div>
<ul>
{% for link in links %}
{{ link }}
{% endfor %}
</ul>
</div>
<div class="col-sm-12 col-md-10 col-lg-10 text-center container-news">
<div>Back to <a href="{{ response.parent }}">parent</a></div>
{% if response.title is not empty %}
<h2>{{ response.title }}</h2>
{% endif %}
{% if response.content is not empty %}
<div class="contenu-text-news">
{{ response.content|raw }}
</div>
{% endif %}
{% if response.subpages is not empty %}
<h3>Sub-pages</h3>
<ul>
{% for key, page in response.subpages %}
{% for label, path in page %}
<li><a href="{{ url('<current>') }}-{{ key }}">{{ label }}</a></li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
</div>
<div class="col-sm-12 col-md-10 col-lg-10 text-center container-news">
{% if response.site_name is not empty %}
<h2>{{ response.site_name }}</h2>
{% endif %}
{% if response.site_description is not empty %}
<div class="contenu-text-news">
{{ response.site_description|raw }}
</div>
{% endif %}
<ul>
{% if response.repo_url is not empty %}
<li>Repository: <a href="{{ response.repo_url }}">{{ response.repo_url }}</a></li>
{% endif %}
</ul>
{% if response.pages is not empty %}
<h3>Pages</h3>
<ul>
{% for key, page in response.pages %}
{% for label, path in page %}
<li><a href="{{ url('<current>') }}/{{ key }}">{{ label }}</li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
</div>
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\xtc\XtendedContent\API\Config;
use Drupal\Core\Url;
/**
......@@ -13,18 +14,17 @@ use Drupal\Core\Url;
*/
function xtcfile_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.main':
$output = '<h2>' . t('Documentation') .
'</h2>';
$output .= '<p>' . t('Readme files and Documentation pages can be directly consulted from
the administration area.') . '</p>';
$output .= '<p>' . t('<a href=":documentation">This page</a> lists links to Readme files included in
the modules packages, and Documentation based on <b><a href=":mkdocs" target="_blank">MkDocs</a></b> standards.',
[':documentation' => Url::fromRoute('xtcfile.docs')->toString(), ':mkdocs' => 'https://www.mkdocs.org/']) . '</p>';
return ['#markup' => $output];
case 'help.page.xtcfile':
$variables = [
':xtcfile' => Url::fromRoute('help.page', ['name' => 'xtcfile'])->toString(),
];
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The <a href=":xtcfile">WebService Content for Dummy sources</a> module provide features to pull contents from Dummy source.', $variables) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<p>' . t('[to be completed]') . '</p>';
return $output;
return Config::getHelp('xtcfile');
}
}
......@@ -37,5 +37,28 @@ function xtcfile_theme($existing, $type, $theme, $path) {
'variables' => ['response' => NULL],
'template' => 'xtc-file',
],
'xtc_documentation' => [
'variables' => [
'links' => NULL
],
'template' => 'xtc-documentation',
],
'xtc_docs_links' => [
'variables' => [
'name' => '',