Skip to content

Commit

Permalink
Add dump to file
Browse files Browse the repository at this point in the history
  • Loading branch information
grachevko committed Sep 3, 2020
1 parent 477554e commit 7923e45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,11 @@ Callback Example

---------------------------------------
```

#### Dump to File

Instead of returning markdown as a string you can easy dump result to file.

```php
Markdown::builder()->h1('Hello world!')->dump('index.md');
```
9 changes: 5 additions & 4 deletions bin/readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
};

$markdown = Markdown::builder()
Markdown::builder()
->h1('Markdown Builder')
->p('A helper class to create markdown.')
->p('This README.md generated by this library, check '.Markdown::link('bin/readme.php', 'bin/readme.php').' for details.')
Expand All @@ -54,6 +54,7 @@
->h4('Callback')
->p('If you want to add blocks from complex logic or iterable value, but don\'t want to stop chain calls you can use callback.')
->callback($parseFileCallback, 'callback')
->getMarkdown();

\file_put_contents(\dirname(__DIR__).'/README.md', $markdown);
->h4('Dump to File')
->p('Instead of returning markdown as a string you can easy dump result to file.')
->code('Markdown::builder()->h1(\'Hello world!\')->dump(\'index.md\');', 'php')
->dump(\dirname(__DIR__).'/README.md');
8 changes: 8 additions & 0 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use function array_map;
use function explode;
use function file_put_contents;
use function implode;
use function is_callable;
use function mb_strlen;
Expand Down Expand Up @@ -227,4 +228,11 @@ public function table(array $headers, $values): self

return $this;
}

public function dump(string $file): self
{
file_put_contents($file, $this->getMarkdown());

return $this;
}
}

0 comments on commit 7923e45

Please sign in to comment.