Browse Source

Finished navigation generator, added ProjectFolder

master
anghenfil 3 years ago
parent
commit
4fd40ed53b
  1. 63
      src/Navigation.php
  2. 25
      src/ProjectFolder.php
  3. 33
      src/SimpleCodeViewer.php
  4. 40
      templates/main.php
  5. 1
      templates/navigation-file.php
  6. 5
      templates/navigation-folder.php

63
src/Navigation.php

@ -9,16 +9,63 @@
namespace ShitHub\SimpleCodeViewer;
use anghenfil\Templater\InvalidVariableStoreException;
use anghenfil\Templater\TemplateParser;
use anghenfil\Templater\VariableStore;
class Navigation{
private $base_directory;
private $project;
private $metapath = "";
public function generateNavigation($base_directory, $project){
$this->base_directory = $base_directory;
$this->project = $project;
$this->metapath = $this->base_directory.'project-'.$this->project.'/.metainfo';
private $projectfolder;
private $currentfile = 0;
public function __construct($projectfolder){
if($projectfolder instanceof ProjectFolder){
$this->projectfolder = $projectfolder;
}else{
throw new \InvalidArgumentException("Expected valid projectfolder");
}
}
public function generateNavigation(){
if(SimpleCodeViewer::DEBUG_MODE)
print("generating navigation ...");
return $this->translateIntoHTML($this->projectfolder);
}
private function translateIntoHTML(Folder $key2){
$returned = "";
foreach ($key2->getChildrens() as $key) {
if(SimpleCodeViewer::DEBUG_MODE)
print("analysing ".$key->getName()."\n");
if ($key instanceof Folder) {
$folderstorage = new VariableStore(array("subfolder_number", "subfolder_name", "subfolder_content"), true, true);
$folderstorage->set_variable("subfolder_number", $key->getId());
$folderstorage->set_variable("subfolder_name", $key->getName());
$folderstorage->set_variable("subfolder_content", $this->translateIntoHTML($key));
try {
$folderparser = new TemplateParser("templates/navigation-folder.php", $folderstorage);
$folderparser->setVarChar("[{", "}]");
} catch (InvalidVariableStoreException $e) {
}
$returned .= $folderparser->parse();
} elseif ($key instanceof File) {
$filestorage = new VariableStore(array("file_number", "file_name", "file_is_current"), true, true);
$filestorage->set_variable("file_number", $key->getId());
$filestorage->set_variable("file_name", $key->getName());
if($this->currentfile == $key->getId()){
$filestorage->set_variable("file_is_current", "class=\"current\"");
}
try {
$fileparser = new TemplateParser("templates/navigation-file.php", $filestorage);
$fileparser->setVarChar("[{", "}]");
} catch (InvalidVariableStoreException $e) {
}
$returned .= $fileparser->parse();
}
}
return $returned;
}
}

25
src/ProjectFolder.php

@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: anghenfil
* Date: 03.08.18
* Time: 22:11
*/
namespace ShitHub\SimpleCodeViewer;
class ProjectFolder extends Folder{
private $language;
private $date;
private $authorid;
private $authorname;
public function __construct($id, $name, $language, $date, $authorid, $authorname){
$this->language = $language;
$this->date = $date;
$this->authorid = $authorid;
$this->authorname = $authorname;
parent::__construct($id, $name);
}
}

33
src/SimpleCodeViewer.php

@ -14,8 +14,7 @@ class SimpleCodeViewer{
const DEBUG_MODE = true;
private $metapath;
private $navigation;
private $parentnode;
private $mainfolder;
private $projectfolder;
/**
* CodeViewer constructor.
@ -26,25 +25,43 @@ class SimpleCodeViewer{
public function __construct($project, $file = null, $editmode = false){
if (self::checkProject($project)) {
$this->projectID = $project;
$this->navigation = new Navigation($project);
//TODO: validation and so
$this->metapath = SimpleCodeViewer::BASE_DIRECTORY.'project-'.$this->projectID.'/.metainfo';
$this->loadMetaFile();
$this->loadMetaFile(); //TODO: Cashing
$this->navigation = new Navigation($this->projectfolder);
$this->navigation->generateNavigation();
} else {
throw new \InvalidArgumentException("Valid projectID as first parameter (int) required");
}
}
private function loadMetaFile(){ //TODO: Mode to SimpleCodeViewer class
/**
* Prints whole codeviewer
*/
public function printCodeViewer(){
print($this->generateCodeViewer());
}
/**
* Generates html code for CodeViewer
* @return String html code for CodeViewer
*/
public function generateCodeViewer(){
}
private function loadMetaFile(){
if(file_exists(SimpleCodeViewer::BASE_DIRECTORY.'project-'.$this->projectID.'/.metainfo')){ //Metafile of project exists?
$xml = simplexml_load_file($this->metapath);
if($xml == false){
throw new InvalidProjectException("Can't parse Metainfo for project ".$this->projectID);
}else{//TODO get general project infos
$mainfolder = new Folder(0, $xml->Project->Name);
}else{//TODO: get general project infos
$this->projectfolder = new ProjectFolder(0, $xml->Project->Name, $xml->Project->Language, $xml->Project->Date, $xml->Project->Author->ID, $xml->Project->Author->Name);
$key = $xml->Project->Files;
$this->parseFileFolder($key, $mainfolder);
$this->parseFileFolder($key, $this->projectfolder);
}
}else{
throw new InvalidProjectException("Metainfo for project ".$this->projectID." missing.");

40
templates/main.php

@ -0,0 +1,40 @@
<div class="container-fluid">
<div class="codeviewer">
<div class="row defaultborder tabrow">
<div class="col-2">
<div class="navigation-tab">
<strong>[{projectname}]</strong>
<span style="float: right;"><svg class="hidetabicon"><use xlink:href="icons/solid.svg#minus-circle"></use></svg><svg hidden class="expandtabicon"><use xlink:href="icons/solid.svg#plus-circle"></use></svg></span>
</div>
</div>
<span class="divider" id="tabdivider"></span>
<div class="col">
<div class="editor-tab">
<em>[{filepath}]</em>
<em style="float:right;">[{lines}]</em>
</div>
</div>
</div>
<div class="row defaultborder contentrow">
<div class="col-2 navigationcol">
<div class="navigation-main">
</div>
</div>
<span class="longdivider editordivider"></span>
<div class="col">
<div class="editor-main">
<div class="row">
<div class="numcol">
</div>
<span class="longdivider editordivider"></span>
<div class="col codecol">
</div>
</div>
</div>
</div>
</div>
</div>
</div>

1
templates/navigation-file.php

@ -0,0 +1 @@
<span><button [{file_is_current}]>[{file_name}]</button></span>

5
templates/navigation-folder.php

@ -0,0 +1,5 @@
<svg class="expandicon expand" id="subfolder-[{subfolder_number}]"><use id="subfolder-[{subfolder_number}]-svguse" xlink:href="icons/solid.svg#caret-down"></use></svg><span class="expand" id="subfolder-[{subfolder_number}]"><button>[{subfolder_name}]</button></span>
<br>
<div class="subfolder" id="subfolder-[{subfolder_number}]-content" style="display:inline">
[{subfolder_content}]
</div>
Loading…
Cancel
Save