Skip to content

Commit

Permalink
Bugfixes + basic styling support
Browse files Browse the repository at this point in the history
Fix #22, #23, #21, #12, #24, #26, #27 thereby cleaning up for 1.4
  • Loading branch information
SMillerDev committed Oct 28, 2016
1 parent 768a213 commit ce65846
Show file tree
Hide file tree
Showing 25 changed files with 779 additions and 669 deletions.
16 changes: 13 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Set up include path for source handling
*/
set_include_path(get_include_path().":".__DIR__.'/src/');
set_include_path(get_include_path() . ":" . __DIR__ . '/src/');

/**
* Set up required classes (with the autoloader)
Expand All @@ -14,13 +14,23 @@
use PHPDraft\Parse\JsonToHTML;

define('VERSION', '0');

$values = UI::main($argv);

$apib = new ApibFileParser($values['file']);
$json = new Drafter($apib);
$html = new JsonToHTML($json->parseToJson());
$html->get_html($values['template'], $values['image']);
$html->sorting = $values['sorting'];
$html->get_html($values['template'], $values['image'], $values['css'], $values['js']);


function phpdraft_var_dump($var)
{
if (defined('__PHPDRAFT_PHAR__')) {
return;
}
echo '<pre>';
var_dump($var);
echo '</pre>';
}

?>
10 changes: 6 additions & 4 deletions src/PHPDraft/In/ApibFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class ApibFileParser
{
/**
* Complete API Blueprint
*
* @var string
*/
protected $full_apib;

/**
* Location of the API Blueprint to parse
*
* @var string
*/
protected $location;
Expand All @@ -29,7 +31,7 @@ class ApibFileParser
*/
public function __construct($filename = 'index.apib')
{
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';
$this->location = pathinfo($filename, PATHINFO_DIRNAME) . '/';

$this->full_apib = $this->get_apib($filename);
}
Expand All @@ -49,16 +51,16 @@ function get_apib($filename)
$matches = [];
preg_match_all('<!-- include\(([a-z_.\/]*?).apib\) -->', $file, $matches);
foreach ($matches[1] as $value) {
$file = str_replace('<!-- include(' . $value . '.apib) -->', $this->get_apib($this->location . $value . '.apib'), $file);
$file = str_replace('<!-- include(' . $value . '.apib) -->',
$this->get_apib($this->location . $value . '.apib'), $file);
}

return $file;
}

private function file_check($filename)
{
if(!file_exists($filename))
{
if (!file_exists($filename)) {
file_put_contents('php://stderr', "API File not found: $filename\n");
exit(1);
}
Expand Down
14 changes: 5 additions & 9 deletions src/PHPDraft/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Category extends HierarchyElement
{
/**
* API Structure element
*
* @var DataStructureElement[]
*/
public $structures = [];
Expand All @@ -28,10 +29,8 @@ class Category extends HierarchyElement
function parse($object)
{
parent::parse($object);
foreach ($object->content as $key => $item)
{
switch ($item->element)
{
foreach ($object->content as $key => $item) {
switch ($item->element) {
case 'resource':
$resource = new Resource($this);
$this->children[] = $resource->parse($item);
Expand All @@ -42,12 +41,9 @@ function parse($object)
$struct->deps = $deps;
$struct->parse($item, $deps);

if (isset($item->content[0]->meta->id))
{
if (isset($item->content[0]->meta->id)) {
$this->structures[$item->content[0]->meta->id] = $struct;
}
else
{
} else {
$this->structures[] = $struct;
}

Expand Down
31 changes: 17 additions & 14 deletions src/PHPDraft/Model/Elements/ArrayStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
class ArrayStructureElement extends DataStructureElement implements StructureElement
{

/**
* Type of objects in the array
*
* @var
*/
public $type_of;

public function parse($item, &$dependencies)
{
$this->element = (isset($item->element)) ? $item->element : 'array';
$this->value = (isset($item->content)) ? $item->content : NULL;
$this->value = (isset($item->content)) ? $item->content : null;

if (isset($item->content))
{
foreach ($item->content as $key => $sub_item)
{
if (isset($item->content)) {
foreach ($item->content as $key => $sub_item) {
$this->type[$key] = $sub_item->element;
switch ($sub_item->element)
{
switch ($sub_item->element) {
case 'array':
$value = new ArrayStructureElement();
$this->value[$key] = $value->parse($sub_item, $dependencies);
Expand All @@ -38,7 +42,7 @@ public function parse($item, &$dependencies)
$this->value[$key] = $value->parse($sub_item, $dependencies);
break;
default:
$this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : NULL;
$this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : null;
break;
}
}
Expand All @@ -49,18 +53,17 @@ public function parse($item, &$dependencies)

function __toString()
{
if (!is_array($this->type))
{
if (!is_array($this->type)) {
return '';
}
$return = '<ul class="list-group">';
foreach ($this->type as $key => $item)
{
foreach ($this->type as $key => $item) {
$type =
(in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-', strtolower($item)) . '">' . $item . '</a>';
(in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-',
strtolower($item)) . '">' . $item . '</a>';

$value =
(isset($this->value[$key])) ? ': <span class="example-value pull-right">' . json_encode($this->value[$key]) . '</span>' : NULL;
(isset($this->value[$key])) ? ': <span class="example-value pull-right">' . json_encode($this->value[$key]) . '</span>' : null;

$return .= '<li class="list-group-item">' . $type . $value . '</li>';
}
Expand Down
Loading

0 comments on commit ce65846

Please sign in to comment.