Skip to content

Commit

Permalink
Fixed issue#6
Browse files Browse the repository at this point in the history
  • Loading branch information
maherelgamil committed Dec 31, 2016
1 parent 831bf22 commit 6e16d04
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"require": {
"illuminate/support": "5.1.*|5.2.*|5.3.*",
"illuminate/filesystem": "5.1.*|5.2.*|5.3.*",
"illuminate/events": "5.1.*|5.2.*|5.3.*",
"illuminate/container": "5.1.*|5.2.*|5.3.*",
"illuminate/contracts": "5.1.*|5.2.*|5.3.*",
"erusev/parsedown": "^1.6",
"erusev/parsedown-extra": "0.7.*"
},
Expand Down
73 changes: 66 additions & 7 deletions src/Laradown.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
namespace Buzzylab\Laradown;

use ParsedownExtra;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Container\Container;

class Laradown extends ParsedownExtra
{

/**
* The IoC container instance.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;

/**
* @var
* @var Filesystem
*/
protected $files;
protected $filesystem;

/**
* Indicator for markdown collect block.
Expand All @@ -20,14 +30,47 @@ class Laradown extends ParsedownExtra

/**
* Laradown constructor.
*
* @param Filesystem $filesystem
*/
public function __construct()
public function __construct(Filesystem $filesystem)
{
parent::__construct();

$this->files = app('files');
$this->filesystem = $filesystem;
}

/**
* Set the IoC container instance.
*
* @param \Illuminate\Contracts\Container\Container $container
*
* @return $this
*/
public function setContainer(Container $container)
{
$this->container = $container;

return $this;
}
/**
* Get the IoC container instance or any of it's services.
*
* @param string|null $service
*
* @return object
*/
public function getContainer($service = null)
{
return is_null($service) ? ($this->container ?: app()) : ($this->container[$service] ?: app($service));
}

/**
* Handlers for all elements
*
* @param array $Element
* @return string
*/
protected function element(array $Element)
{
$markup = '';
Expand All @@ -51,7 +94,15 @@ protected function element(array $Element)
*/
public function convert($markdown)
{
return $this->text($markdown);
// Fire converting event
$this->getContainer('events')->fire('laradown.entity.converting');

$text = $this->text($markdown);

// Fire converted event
$this->getContainer('events')->fire('laradown.entity.converted');

return $text;
}

/**
Expand All @@ -71,6 +122,9 @@ public function render($markdown)
*/
public function collect()
{
// Fire collecting event
$this->getContainer('events')->fire('laradown.entity.collecting');

// Make indicator true
$this->collect_indicator = true;

Expand All @@ -89,6 +143,9 @@ public function endCollect()
// Get the markdown content from block
$markdown = ob_get_clean();

// Fire collected event
$this->getContainer('events')->fire('laradown.entity.collected');

// Convert the markdown content to html
return $this->convert($markdown);
}
Expand Down Expand Up @@ -123,11 +180,13 @@ public function loadStyle($file = null)
}

// check if style file exists
if ($this->files->exists($file)) {
$content = $this->files->get($file);
if ($this->filesystem->exists($file)) {
$content = $this->filesystem->get($file);
}

// Finally return style
return "<style>{$content}</style>";
}


}
7 changes: 4 additions & 3 deletions src/MarkdownServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Buzzylab\Laradown;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use ParsedownExtra;

class MarkdownServiceProvider extends ServiceProvider
{
Expand All @@ -22,9 +22,10 @@ public function boot()
public function register()
{
$this->app->singleton('markdown', function () {
$parsedown = new ParsedownExtra();

return new Laradown($parsedown);
$filesystem = new Filesystem();

return new Laradown($filesystem);
});
}

Expand Down

0 comments on commit 6e16d04

Please sign in to comment.