Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a better way to load twig-markdown extension #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions README-composer.mkd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Installation with composer

- Install composer in your project:

```shell
curl -s http://getcomposer.org/installer | php
```

- Create a composer.json file in your project root:

```javascript
{
"repositories": [
{
"type": "package",
"package": {
"name": "michelf/php-markdown",
"version": "1.0",
"dist": {
"url": "https://github.com/michelf/php-markdown/zipball/extra",
"type": "zip"
},
"autoload": {
"files": [
"markdown.php"
]
}
}
},
{
"type": "vcs",
"url": "http://github.com/geta6/Twig-Markdown"
}
],
"require": {
"michelf/php-markdown": "1.*",
"geta6/twig-markdown": "@dev"
}
}
```

- Install via composer

```shell
php composer.phar install
```

## Usage

```php
require 'vendor/autoload.php';

$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);
$twig->addExtension(new Twig_Extension_Markdown());

echo $twig->render('
{% markdown %}
###Hello {{ name }}!###
{% endmarkdown %}
', array('name' => 'Twig-Markdown'));
```
5 changes: 3 additions & 2 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ or
```php
$app->register(~~twig~~);

include __DIR__.'/../vendor/twig-markdown/lib/Twig/Extensions/Core.php';
$app['twig']->addExtension(new Twig_Markdown_Extension());
include '/path/to/markdown.php';
include __DIR__.'/../vendor/twig-markdown/lib/Twig/Extensions/Markdown.php';
$app['twig']->addExtension(new Twig_Extension_Markdown());
```

## todo
Expand Down
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "geta6/twig-markdown",
"authors": [
{
"name": "getakura",
"email": "getakura@gmail.com"
}
],
"require": {
"twig/twig": "1.*"
},
"autoload": {
"psr-0" : {
"Twig_" : "lib/"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
define('ENT_SUBSTITUTE', 8);
}

class Twig_Markdown_Extension extends Twig_Extension
class Twig_Extension_Markdown extends Twig_Extension
{
public function getTokenParsers()
{
include_once dirname(__FILE__).'/../TokenParser/Markdown.php';
return array(
new Twig_TokenParser_Markdown(),
);
Expand All @@ -33,7 +32,6 @@ public function getName()

function twig_markdown($data)
{
include_once dirname(__FILE__).'/../Markdown/markdown.php';
return Markdown($data);
}

1 change: 0 additions & 1 deletion lib/Twig/Node/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'markdown'
*/
public function compile(Twig_Compiler $compiler)
{
include_once dirname(__FILE__).'/../Markdown/markdown.php';
$compiler
->addDebugInfo($this)
->write("ob_start();\n")
Expand Down
2 changes: 0 additions & 2 deletions lib/Twig/TokenParser/Markdown.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

include_once dirname(__FILE__).'/../Node/Markdown.php';

class Twig_TokenParser_Markdown extends Twig_TokenParser
{
/**
Expand Down