Skip to content

Commit bb0ff2c

Browse files
Add support for dashed YAML syntax (#260)
1 parent 87a3228 commit bb0ff2c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Blueprint.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function appPath()
3232
public function parse($content)
3333
{
3434
$content = str_replace(["\r\n", "\r"], "\n", $content);
35+
$content = preg_replace('/^(\s*)-\s*/m', '\1', $content);
3536

3637
$content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', function ($matches) {
3738
return $matches[1].strtolower($matches[2]).': '.$matches[2];

tests/Feature/BlueprintTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,38 @@ public function it_parses_the_readme_example_with_different_platform_eols()
275275
$this->assertEquals($expected, $this->subject->parse($definition_windows_eol));
276276
}
277277

278+
/**
279+
* @test
280+
*/
281+
public function it_parses_yaml_using_dashed_syntax()
282+
{
283+
$definition = $this->fixture('drafts/readme-example-dashes.yaml');
284+
285+
$expected = [
286+
'models' => [
287+
'Post' => [
288+
'title' => 'string:400',
289+
'content' => 'longtext',
290+
],
291+
],
292+
'controllers' => [
293+
'Post' => [
294+
'index' => [
295+
'query' => 'all:posts',
296+
'render' => 'post.index with:posts',
297+
],
298+
'store' => [
299+
'validate' => 'title, content',
300+
'save' => 'post',
301+
'redirect' => 'post.index',
302+
],
303+
],
304+
],
305+
];
306+
307+
$this->assertEquals($expected, $this->subject->parse($definition));
308+
}
309+
278310
/**
279311
* @test
280312
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- models:
2+
- Post:
3+
- title: string:400
4+
- content: longtext
5+
6+
- controllers:
7+
- Post:
8+
- index:
9+
- query: all:posts
10+
- render: post.index with:posts
11+
12+
- store:
13+
- validate: title, content
14+
- save: post
15+
- redirect: post.index

0 commit comments

Comments
 (0)