Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gorkalaucirica committed Sep 15, 2015
0 parents commit dc70aff
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Builder/DocumentationBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* This file is part of the Knowledge Base project.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\Builder;

use LIN3S\KnowledgeBase\Iterator\Interfaces\IteratorInterface;
use LIN3S\KnowledgeBase\Registry\GeneratorRegistry;

/**
* Document builder class.
*
* @author Gorka Laucirica <gorka@lin3s.com>
* @author Beñat Espiña <bespina@lin3s.com>
*/
final class DocumentationBuilder
{
/**
* The iterator.
*
* @var \LIN3S\KnowledgeBase\Iterator\Interfaces\IteratorInterface
*/
private $iterator;

/**
* The generator registry.
*
* @var \LIN3S\KnowledgeBase\Registry\GeneratorRegistry
*/
private $generatorRegistry;

/**
* Constructor.
*
* @param \LIN3S\KnowledgeBase\Iterator\Interfaces\IteratorInterface $iterator The iterator
* @param \LIN3S\KnowledgeBase\Registry\GeneratorRegistry $generatorRegistry The generator registry
*/
public function __construct(IteratorInterface $iterator, GeneratorRegistry $generatorRegistry)
{
$this->iterator = $iterator;
$this->generatorRegistry = $generatorRegistry;
}

/**
* Index build method.
*
* Its responsibility is to call the parseFile
* and generate methods from generator.
*/
public function build()
{
$files = $this->iterator->getFiles();
$generators = $this->generatorRegistry->generators();

foreach ($files as $file) {
foreach ($generators as $generator) {
$generator->parseFile($file);
}
}

foreach ($generators as $generator) {
$generator->generate();
}
}
}
90 changes: 90 additions & 0 deletions Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/*
* This file is part of the Knowledge Base project.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase;

use LIN3S\KnowledgeBase\Templating\TemplateInterface;

/**
* Configuration class.
*
* @author Gorka Laucirica <gorka@lin3s.com>
* @author Beñat Espiña <bespina@lin3s.com>
*/
final class Configuration
{
/**
* The docs path.
*
* @var string
*/
private $docsPath;

/**
* The build path.
*
* @var string
*/
private $buildPath;

/**
* The template.
*
* @var \LIN3S\KnowledgeBase\Templating\TemplateInterface
*/
private $template;

/**
* Constructor.
*
* @param string $docsPath Path where the docs are located
* @param string $buildPath Path where the generated docs will be placed
* @param \LIN3S\KnowledgeBase\Templating\TemplateInterface $template The template
* @param string $assetsBaseUrl Base url templates will use to find assets
*/
public function __construct($docsPath, $buildPath, TemplateInterface $template, $assetsBaseUrl = '/templates')
{
$this->docsPath = $docsPath;
$this->buildPath = $buildPath;
$this->template = $template;
$this->assetsBaseUrl = $assetsBaseUrl;
}

/**
* Gets the build path.
*
* @return string
*/
public function buildPath()
{
return $this->buildPath;
}

/**
* Gets the docs path.
*
* @return string
*/
public function docsPath()
{
return $this->docsPath;
}

/**
* The template.
*
* @return \LIN3S\KnowledgeBase\Templating\TemplateInterface
*/
public function template()
{
return $this->template;
}
}
87 changes: 87 additions & 0 deletions File/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of the Knowledge Base project.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\File;

use LIN3S\KnowledgeBase\File\Interfaces\FileInterface;

/**
* File abstract class.
*
* @author Gorka Laucirica <gorka@lin3s.com>
* @author Beñat Espiña <bespina@lin3s.com>
*/
abstract class File implements FileInterface
{
/**
* The content.
*
* @var string
*/
protected $content;

/**
* The name.
*
* @var string
*/
protected $name;

/**
* The path.
*
* @var string
*/
protected $path;

/**
* Constructor.
*
* @param string $name The name
* @param string $path The path
* @param string $content The content
*/
public function __construct($name, $path = __DIR__, $content = null)
{
$this->name = $name;
$this->path = $path;
$this->content = $content;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}

/**
* {@inheritdoc}
*/
public function getContent()
{
return $this->content;
}

/**
* {@inheritdoc}
*/
public function getPath()
{
return $this->path;
}

/**
* {@inheritdoc}
*/
abstract public function getExtension();
}
49 changes: 49 additions & 0 deletions File/Interfaces/FileInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Knowledge Base project.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\File\Interfaces;

/**
* File interface.
*
* @author Gorka Laucirica <gorka@lin3s.com>
* @author Beñat Espiña <bespina@lin3s.com>
*/
interface FileInterface
{
/**
* Returns file name without path nor extension.
*
* @return string
*/
public function getName();

/**
* Returns raw file content.
*
* @return string
*/
public function getContent();

/**
* Returns relative to docs folder file path without filename nor extension.
*
* @return string
*/
public function getPath();

/**
* Returns file extension without the dot. For example (md)
*
* @return string
*/
public function getExtension();
}
30 changes: 30 additions & 0 deletions File/MarkdownFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Knowledge Base project.
*
* Copyright (c) 2015 LIN3S <info@lin3s.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LIN3S\KnowledgeBase\File;

/**
* Markdown file class.
*
* @author Beñat Espiña <bespina@lin3s.com>
*/
final class MarkdownFile extends File
{
const EXTENSION = 'md';

/**
* {@inheritdoc}
*/
public function getExtension()
{
return self::EXTENSION;
}
}
Loading

0 comments on commit dc70aff

Please sign in to comment.