Skip to content

Commit

Permalink
added experemental support for decoda v4
Browse files Browse the repository at this point in the history
  • Loading branch information
helios committed Nov 13, 2012
1 parent d914913 commit 9062dac
Show file tree
Hide file tree
Showing 29 changed files with 62 additions and 27 deletions.
Empty file modified .gitignore
100755 → 100644
Empty file.
7 changes: 6 additions & 1 deletion .travis.yml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ language: php

php:
- 5.3
- 5.4
env:
- SYMFONY_VERSION=2.0.*
- SYMFONY_VERSION=2.1.*
- SYMFONY_VERSION=dev-master

before_script:
- curl -s http://getcomposer.org/installer | php --
- php composer.phar install --dev
- php composer.phar require symfony/framework-bundle:2.0.17
- php composer.phar require symfony/framework-bundle:${SYMFONY_VERSION}

script: phpunit --coverage-text

Expand Down
Empty file modified CHANGELOG.md
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions Decoda/Decoda.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FM\BbcodeBundle\Decoda;

use \Decoda as BaseDecoda;
use mjohnson\decoda\Decoda as BaseDecoda;

class Decoda extends BaseDecoda
{
Expand All @@ -13,7 +13,7 @@ class Decoda extends BaseDecoda
*/
public function __construct($string = '', $messages = array())
{
spl_autoload_register(array($this, 'loadFile'));


$this->setMessages($messages);
$this->reset($string, true);
Expand Down
54 changes: 34 additions & 20 deletions Decoda/DecodaManager.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
use FM\BbcodeBundle\Decoda\Decoda;
use FM\BbcodeBundle\Decoda\DecodaPhpEngine;
use Symfony\Component\DependencyInjection\ContainerInterface;
use mjohnson\decoda\filters\Filter,
mjohnson\decoda\filters\DefaultFilter,
mjohnson\decoda\filters\BlockFilter,
mjohnson\decoda\filters\CodeFilter,
mjohnson\decoda\filters\EmailFilter,
mjohnson\decoda\filters\ImageFilter,
mjohnson\decoda\filters\ListFilter,
mjohnson\decoda\filters\QuoteFilter,
mjohnson\decoda\filters\TextFilter,
mjohnson\decoda\filters\UrlFilter,
mjohnson\decoda\filters\VideoFilter;
use mjohnson\decoda\hooks\CensorHook,
mjohnson\decoda\hooks\ClickableHook,
mjohnson\decoda\hooks\CodeHook,
mjohnson\decoda\hooks\EmoticonHook,
mjohnson\decoda\hooks\Hook;

/**
* @author Al Ganiev <[email protected]>
Expand Down Expand Up @@ -33,7 +49,6 @@ public function __construct(Decoda $value, array $filters = array(), array $hook
$this->filters = $filters;
$this->hooks = $hooks;
$this->whitelist = $whitelist;

}

public static function add_filter($name, $filter){
Expand All @@ -49,8 +64,6 @@ public static function add_templatePath( $path ){
static::$extra_paths[] = $path;
}



/**
* Applies filter specified in parameter
* @param \FM\BbcodeBundle\Decoda\Decoda $code
Expand All @@ -60,43 +73,44 @@ public static function add_templatePath( $path ){
*/
protected function apply_filter(Decoda $code, $filter)
{
//default, block, code, email, image, list, quote, text, url, video ]
//default, block, code, email, image, list, quote, text, url, video
if(isset(static::$extra_filters[$filter])){
$extra_filter = static::$extra_filters[$filter] instanceof \DecodaFilter ? static::$extra_filters[$filter] : new static::$extra_filters[$filter]();
$extra_filter = static::$extra_filters[$filter] instanceof Filter ? static::$extra_filters[$filter] : new static::$extra_filters[$filter]();
$code->addFilter($extra_filter);
return $code;
}

switch ($filter) {
case 'block':
$code->addFilter(new \BlockFilter());
$code->addFilter(new BlockFilter());
break;
case 'code':
$code->addFilter(new \CodeFilter());
$code->addFilter(new CodeFilter());
break;
case 'email':
$code->addFilter(new \EmailFilter());
$code->addFilter(new EmailFilter());
break;
case 'image':
$code->addFilter(new \ImageFilter());
$code->addFilter(new ImageFilter());
break;
case 'list':
$code->addFilter(new \ListFilter());
$code->addFilter(new ListFilter());
break;
case 'quote':
$code->addFilter(new \QuoteFilter());
$code->addFilter(new QuoteFilter());
break;
case 'text':
$code->addFilter(new \TextFilter());
$code->addFilter(new TextFilter());
break;
case 'url':
$code->addFilter(new \UrlFilter());
$code->addFilter(new UrlFilter());
break;
case 'video':
$code->addFilter(new \VideoFilter());
$code->addFilter(new VideoFilter());
break;
case 'default':
$code->addFilter(new \DefaultFilter());
$code->addFilter(new DefaultFilter());
break;
default:
return $code;
}
Expand All @@ -112,20 +126,20 @@ protected function apply_hook(Decoda $code, $hook)
{

if(isset(static::$extra_hooks[$hook])){
$extra_hook = static::$extra_hooks[$hook] instanceof \DecodaHook ? static::$extra_hooks[$hook] : new static::$extra_hooks[$hook]();
$extra_hook = static::$extra_hooks[$hook] instanceof Hook ? static::$extra_hooks[$hook] : new static::$extra_hooks[$hook]();
$code->addFilter($extra_hook);
return $code;
}

switch ($hook) {
case 'censor':
$code->addHook(new \CensorHook());
$code->addHook(new CensorHook());
break;
case 'clickable':
$code->addHook(new \ClickableHook());
$code->addHook(new ClickableHook());
break;
case 'emoticon':
$code->addHook(new \EmoticonHook());
$code->addHook(new EmoticonHook());
break;
}
return $code;
Expand Down Expand Up @@ -153,7 +167,7 @@ public function getResult()
$decodaPhpEngine->setpath($extraPath);
}

$this->value->setTemplateEngine($decodaPhpEngine);
$this->value->setEngine($decodaPhpEngine);


foreach($this->filters as $filter)
Expand Down
8 changes: 5 additions & 3 deletions Decoda/DecodaPhpEngine.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace FM\BbcodeBundle\Decoda;
use mjohnson\decoda\engines\PhpEngine;
use mjohnson\decoda\filters\Filter;
use Exception;
/**
* DecodaPhpEngine
Expand All @@ -13,7 +15,7 @@
* @license http://opensource.org/licenses/mit-license.php - Licensed under The MIT License
* @link http://milesj.me/code/php/decoda
*/
class DecodaPhpEngine implements \DecodaTemplateEngineInterface
class DecodaPhpEngine extends PhpEngine
{
/**
* Current path.
Expand Down Expand Up @@ -113,10 +115,10 @@ public function render(array $tag, $content)
* Sets the current filter.
*
* @access public
* @param DecodaFilter $filter
* @param \mjohnson\decoda\filters\Filter $filter
* @return DecodaTemplateEngineInterface
*/
public function setFilter(\DecodaFilter $filter)
public function setFilter(Filter $filter)
{
$this->_filter = $filter;

Expand Down
14 changes: 14 additions & 0 deletions Decoda/Hook/EmoticonHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace FM\BbcodeBundle\Decoda\Hook;

use mjohnson\decoda\hooks\EmoticonHook;

class EmoticonHook2 extends EmoticonHook
{

public function setConfig(array $config) {
$this->_config = $config;
}

}
Empty file modified DependencyInjection/Configuration.php
100755 → 100644
Empty file.
Empty file modified DependencyInjection/FMBbcodeExtension.php
100755 → 100644
Empty file.
Empty file modified FMBbcodeBundle.php
100755 → 100644
Empty file.
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified Resources/config/bbcode.xml
100755 → 100644
Empty file.
Empty file modified Resources/config/messages.json
100755 → 100644
Empty file.
Empty file modified Templating/BbcodeExtension.php
100755 → 100644
Empty file.
Empty file modified Templating/Helper/BbcodeHelper.php
100755 → 100644
Empty file.
Empty file modified Tests/AppKernel.php
100755 → 100644
Empty file.
Empty file modified Tests/DependencyInjection/FMBbcodeExtensionTest.php
100755 → 100644
Empty file.
Empty file modified Tests/FunctionalTestBundle/FunctionalTestBundle.php
100755 → 100644
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified Tests/Templating/BbcodeExtensionTest.php
100755 → 100644
Empty file.
Empty file modified Tests/Templating/Helper/BbcodeHelperTest.php
100755 → 100644
Empty file.
Empty file modified Tests/TwigBasedTestCase.php
100755 → 100644
Empty file.
Empty file modified Tests/bootstrap.php
100755 → 100644
Empty file.
Empty file modified Tests/config/config.yml
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.3.2",
"mjohnson/decoda": "3.*"
"mjohnson/decoda": "4.0.2"
},
"autoload": {
"psr-0": { "FM\\BbcodeBundle": "" }
Expand Down
Empty file modified phpunit.xml.dist
100755 → 100644
Empty file.

0 comments on commit 9062dac

Please sign in to comment.