Skip to content

Commit

Permalink
In: Add support for non apib includes
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jun 18, 2018
1 parent 066bdd6 commit 443af54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/PHPDraft/In/ApibFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ private function get_apib($filename)
$this->file_check($filename);
$file = file_get_contents($filename);
$matches = [];
preg_match_all('<!-- include\(([a-z0-9_.\/]*?).apib\) -->', $file, $matches);
foreach ($matches[1] as $value) {
$file = str_replace('<!-- include(' . $value . '.apib) -->',
$this->get_apib($this->location . $value . '.apib'), $file);
preg_match_all('<!-- include\(([a-z0-9_.\/]*?)(\.[a-z]*?)\) -->', $file, $matches);
for ($i = 0; $i < count($matches[1]); $i++) {
$file = str_replace('<!-- include(' . $matches[1][$i] . $matches[2][$i] . ') -->',
$this->get_apib($this->location . $matches[1][$i] . $matches[2][$i]), $file);
}

preg_match_all('<!-- schema\(([a-z0-9_.\/\:]*?)\) -->', $file, $matches);
Expand All @@ -89,6 +89,8 @@ private function get_apib($filename)
*
* @param string $filename File to check
*
* @throws ExecutionException when the file could not be found.
*
* @return void
*/
private function file_check($filename)
Expand Down
8 changes: 5 additions & 3 deletions src/PHPDraft/In/Tests/ApibFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class ApibFileParserTest extends BaseTest
{

/**
* Set up tests
* @return void
* Set up tests.
*
* @return void Test is now set up.
*/
public function setUp()
{
Expand Down Expand Up @@ -88,7 +89,8 @@ public function testParseBasic()
$full_property->setAccessible(true);

$text = "FORMAT: 1A\nHOST: https://owner-api.teslamotors.com\nEXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n";
$text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.\n\nTEST\nhello";
$text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.\n\nTEST";
$text .="\n\n# Hello\nThis is a test.\nhello";

$this->assertSame($text, $full_property->getValue($this->class));
$this->assertSame($text, $this->class->__toString());
Expand Down
3 changes: 3 additions & 0 deletions tests/statics/drafter/apib/include.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Hello
This is a test.
1 change: 1 addition & 0 deletions tests/statics/drafter/apib/including.apib
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SOMETHING: INFO
This is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.

<!-- include(include.apib) -->
<!-- include(include.md) -->
<!-- schema(include.apib) -->

0 comments on commit 443af54

Please sign in to comment.