Skip to content

Commit

Permalink
Refactoring and added markdown engines
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Jun 1, 2014
1 parent 7ef21cd commit 881e7e5
Show file tree
Hide file tree
Showing 18 changed files with 566 additions and 32 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ CHANGE LOG

## V2.0 Beta 1 (Upcoming - July 2014)

* Upgrade to Laravel 4.2
* Upgrade to Laravel ~4.1
* Moved to parsedown
* Refactoring
* Added markdown engines


## V1.1 (21/04/2014)
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Laravel Markdown

## What Is Laravel Markdown?

Laravel Markdown is a simple [Parsedown](https://github.com/erusev/parsedown) wrapper for [Laravel 4.2](http://laravel.com).
Laravel Markdown is a simple [Parsedown](https://github.com/erusev/parsedown) wrapper for [Laravel 4.1+](http://laravel.com).

* Laravel Markdown was created by, and is maintained by [Graham Campbell](https://github.com/GrahamCampbell).
* Laravel Markdown relies on Emanuil Rusev's [Parsedown](https://github.com/erusev/parsedown) package.
Expand All @@ -26,7 +26,7 @@ Laravel Markdown is a simple [Parsedown](https://github.com/erusev/parsedown) wr
## System Requirements

* PHP 5.4.7+ or HHVM 3.1+ is required.
* You will need [Laravel 4.2](http://laravel.com) because this package is designed for it.
* You will need [Laravel 4.1+](http://laravel.com) because this package is designed for it.
* You will need [Composer](https://getcomposer.org) installed to load the dependencies of Laravel Markdown.


Expand All @@ -47,7 +47,17 @@ You can register the Markdown facade in the `aliases` key of your `app/config/ap

## Configuration

Laravel Markdown requires no configuration. Just follow the simple install instructions and go!
Laravel Markdown supports optional configuration.

To get started, first publish the package config file:

php artisan config:publish graham-campbell/markdown

There is one config options:

**Enable The Engines**

This option (`'engines'`) specifies if the view engines are enabled so you can write markdown views and have them compiled into html. The following extensions are currently supported: `'.md'`, `'.md.php'`, and `'.md.blade.php'`. You may disable the engines if they are conflicting with another package. The default value for this setting is `true`.


## Usage
Expand All @@ -58,8 +68,6 @@ This is the class of most interest. It is bound to the ioc container as `'markdo

The `'render'` method will parse a string as markdown using Emanuil Rusev's [Parsedown](https://github.com/erusev/parsedown) package, and will return a string of html.

Any methods not found on this markdown class will actually fall back to the parsedown class with a dynamic call function, so every other method on the pasedown class is available in exactly the same way it would otherwise be.

**Facades\Markdown**

This facade will dynamically pass static method calls to the `'markdown'` object in the ioc container which by default is the `Classes\Markdown` class.
Expand All @@ -70,6 +78,8 @@ This class contains no public methods of interest. This class should be added to

**Further Information**

There are other classes in this package that are not documented here. This is because they are not intended for public use and are used internally by this package.

Feel free to check out the [API Documentation](http://grahamcampbell.github.io/Laravel-Markdown
) for Laravel Markdown.

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graham-campbell/markdown",
"description": "Markdown Is A Simple PHP Markdown Wrapper For Laravel 4.2",
"description": "Markdown Is A Simple PHP Markdown Wrapper For Laravel 4.1+",
"keywords": ["laravel", "framework", "markdown", "php markdown", "markdown wrapper", "php markdown wrapper", "Markdown", "Laravel Markdown", "Laravel-Markdown", "Graham Campbell", "GrahamCampbell"],
"license": "Apache-2.0",
"authors": [
Expand All @@ -11,7 +11,8 @@
],
"require": {
"php": ">=5.4.7",
"illuminate/support": "4.2.*",
"illuminate/support": "~4.1",
"illuminate/view": "~4.1",
"erusev/parsedown": "~1.0"
},
"require-dev": {
Expand Down
12 changes: 0 additions & 12 deletions src/Classes/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,4 @@ public function getParsedown()
{
return $this->parsedown;
}

/**
* Dynamically call all other methods on the parsedown object.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array(array($this->parsedown, $method), $parameters);
}
}
77 changes: 77 additions & 0 deletions src/Engines/BladeMarkdownEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* This file is part of Laravel Markdown by Graham Campbell.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace GrahamCampbell\Markdown\Engines;

use Illuminate\View\Engines\CompilerEngine;
use GrahamCampbell\Markdown\Classes\Markdown;
use Illuminate\View\Compilers\CompilerInterface;

/**
* This is the php markdown engine class.
*
* @package Laravel-Markdown
* @author Graham Campbell
* @copyright Copyright 2013-2014 Graham Campbell
* @license https://github.com/GrahamCampbell/Laravel-Markdown/blob/master/LICENSE.md
* @link https://github.com/GrahamCampbell/Laravel-Markdown
*/
class BladeMarkdownEngine extends CompilerEngine
{
/**
* The markdown instance.
*
* @var \GrahamCampbell\Markdown\Classes\Markdown
*/
protected $markdown;

/**
* Create a new instance.
*
* @param \Illuminate\View\Compilers\CompilerInterface $compiler
* @param \GrahamCampbell\Markdown\Classes\Markdown $markdown
* @return void
*/
public function __construct(CompilerInterface $compiler, Markdown $markdown)
{
parent::__construct($compiler);
$this->markdown = $markdown;
}

/**
* Get the evaluated contents of the view.
*
* @param string $path
* @param array $data
* @return string
*/
public function get($path, array $data = array())
{
$contents = parent::get($path, $data);

return $this->markdown->render($contents);
}

/**
* Return the markdown instance.
*
* @return \GrahamCampbell\Markdown\Classes\Markdown
*/
public function getMarkdown()
{
return $this->markdown;
}
}
74 changes: 74 additions & 0 deletions src/Engines/MarkdownEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of Laravel Markdown by Graham Campbell.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace GrahamCampbell\Markdown\Engines;

use Illuminate\View\Engines\EngineInterface;
use GrahamCampbell\Markdown\Classes\Markdown;

/**
* This is the markdown engine class.
*
* @package Laravel-Markdown
* @author Graham Campbell
* @copyright Copyright 2013-2014 Graham Campbell
* @license https://github.com/GrahamCampbell/Laravel-Markdown/blob/master/LICENSE.md
* @link https://github.com/GrahamCampbell/Laravel-Markdown
*/
class MarkdownEngine implements EngineInterface
{
/**
* The markdown instance.
*
* @var \GrahamCampbell\Markdown\Classes\Markdown
*/
protected $markdown;

/**
* Create a new instance.
*
* @param \GrahamCampbell\Markdown\Classes\Markdown $markdown
* @return void
*/
public function __construct(Markdown $markdown)
{
$this->markdown = $markdown;
}

/**
* Get the evaluated contents of the view.
*
* @param string $path
* @param array $data
* @return string
*/
public function get($path, array $data = array())
{
$contents = file_get_contents($path);

return $this->markdown->render($contents);
}

/**
* Return the markdown instance.
*
* @return \GrahamCampbell\Markdown\Classes\Markdown
*/
public function getMarkdown()
{
return $this->markdown;
}
}
74 changes: 74 additions & 0 deletions src/Engines/PhpMarkdownEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of Laravel Markdown by Graham Campbell.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace GrahamCampbell\Markdown\Engines;

use Illuminate\View\Engines\PhpEngine;
use GrahamCampbell\Markdown\Classes\Markdown;

/**
* This is the php markdown engine class.
*
* @package Laravel-Markdown
* @author Graham Campbell
* @copyright Copyright 2013-2014 Graham Campbell
* @license https://github.com/GrahamCampbell/Laravel-Markdown/blob/master/LICENSE.md
* @link https://github.com/GrahamCampbell/Laravel-Markdown
*/
class PhpMarkdownEngine extends PhpEngine
{
/**
* The markdown instance.
*
* @var \GrahamCampbell\Markdown\Classes\Markdown
*/
protected $markdown;

/**
* Create a new instance.
*
* @param \GrahamCampbell\Markdown\Classes\Markdown $markdown
* @return void
*/
public function __construct(Markdown $markdown)
{
$this->markdown = $markdown;
}

/**
* Get the evaluated contents of the view.
*
* @param string $path
* @param array $data
* @return string
*/
public function get($path, array $data = array())
{
$contents = parent::get($path, $data);

return $this->markdown->render($contents);
}

/**
* Return the markdown instance.
*
* @return \GrahamCampbell\Markdown\Classes\Markdown
*/
public function getMarkdown()
{
return $this->markdown;
}
}
56 changes: 56 additions & 0 deletions src/MarkdownServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,62 @@ class MarkdownServiceProvider extends ServiceProvider
public function boot()
{
$this->package('graham-campbell/markdown', 'graham-campbell/markdown', __DIR__);

// setup blade engines if enabled
if ($this->app['config']['graham-campbell/markdown::engines']) {
$this->enableMarkdownEngine();
$this->enablePhpMarkdownEngine();
$this->enableBladeMarkdownEngine();
}
}

/**
* Enable the markdown engine.
*
* @return void
*/
protected function enableMarkdownEngine()
{
$app = $this->app;

$app['view']->addExtension('md', 'md', function () use ($app) {
$markdown = $app['markdown'];

return new Engines\MarkdownEngine($markdown);
});
}

/**
* Enable the php markdown engine.
*
* @return void
*/
protected function enablePhpMarkdownEngine()
{
$app = $this->app;

$app['view']->addExtension('md.php', 'phpmd', function () use ($app) {
$markdown = $app['markdown'];

return new Engines\PhpMarkdownEngine($markdown);
});
}

/**
* Enable the blade markdown engine.
*
* @return void
*/
protected function enableBladeMarkdownEngine()
{
$app = $this->app;

$app['view']->addExtension('md.blade.php', 'blademd', function () use ($app) {
$compiler = $app['blade.compiler'];
$markdown = $app['markdown'];

return new Engines\BladeMarkdownEngine($compiler, $markdown);
});
}

/**
Expand Down
Loading

0 comments on commit 881e7e5

Please sign in to comment.