Skip to content

Commit

Permalink
Add html purifier transformer. remove unnecessary transformers. use c…
Browse files Browse the repository at this point in the history
…omposer for tests
  • Loading branch information
trsteel88 committed Nov 23, 2013
1 parent 78a7196 commit c28873f
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 210 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Tests/vendor/*
Tests/cache/*
Tests/logs/*
/composer.phar
/composer.lock
/vendor
/Tests/Resources/cache
/Tests/Resources/logs
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
language: php
php: 5.3

php:
- 5.3
- 5.4

env:
- SYMFONY_VERSION="2.3.*"

before_script:
- composer require --no-update symfony/framework-bundle:${SYMFONY_VERSION}
- composer install --dev --prefer-source

script: phpunit

notifications:
email:
- [email protected]
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getConfigTreeBuilder()
->children()
->variableNode('transformers')
->defaultValue(array(
'strip_js', 'strip_css', 'strip_comments'
//'html_purifier'
))
->info("Default data transformers for the submitted html.")
->end()
Expand Down
24 changes: 0 additions & 24 deletions Form/Transformer/StripCSS.php

This file was deleted.

24 changes: 0 additions & 24 deletions Form/Transformer/StripComments.php

This file was deleted.

24 changes: 0 additions & 24 deletions Form/Transformer/StripJS.php

This file was deleted.

24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
6. Configure data transformers

### Step 1: Add TrsteelCkeditorBundle to your composer.json
```js
{
"require": {
"Trsteel/ckeditor-bundle": "1.1.*@dev"
}
}
```

and update your project dependencies:

```bash
php composer.phar update Trsteel/ckeditor-bundle
php composer.phar require Trsteel/ckeditor-bundle 1.3.*
```

### Step 2: Enable the bundle
Expand All @@ -38,6 +29,7 @@ public function registerBundles()
$bundles = array(
// ...
new Trsteel\CkeditorBundle\TrsteelCkeditorBundle(),
new Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(),
);
}
```
Expand All @@ -61,7 +53,7 @@ An example configuration:
```yaml
trsteel_ckeditor:
class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
transformers: ['strip_js', 'strip_css', 'strip_comments']
transformers: ['html_purifier']
toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
toolbar_groups:
document: ['Source','-','Save','-','Templates']
Expand Down Expand Up @@ -108,7 +100,7 @@ Example form:
$form = $this->createFormBuilder($post)
->add('title', 'text')
->add('content', 'ckeditor', array(
'transformers' => array('strip_js', 'strip_css', 'strip_comments'),
'transformers' => array('html_purifier'),
'toolbar' => array('document','basicstyles'),
'toolbar_groups' => array(
'document' => array('Source')
Expand Down Expand Up @@ -138,13 +130,7 @@ Note: All parameters from config.yml can be overwritten in a form (excluding 'cl

Data transformers will automatically update the html content when the form is processed.

This bundle comes with several built-in transformers.

**strip_js:** Strips all javascript from the posted data

**strip_css:** Strips all css from the posted data

**strip_comments:** Strips all comments from html eg. <!-- This is a comment -->
The bundle comes with a html purifier transformer thanks to https://github.com/Exercise/HTMLPurifierBundle

If you do not want any transformers enabled you should disable them by:

Expand Down
26 changes: 6 additions & 20 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
parameters:
# trsteel_ckeditor.example.class: Trsteel\CkeditorBundle\Example

services:
# trsteel_ckeditor.example:
# class: %trsteel_ckeditor.example.class%
# arguments: [@service_id, "plain_value", %parameter%]
trsteel_ckeditor.form.type:
class: %trsteel_ckeditor.form.type.class%
arguments: [@service_container]
tags:
- { name: form.type, alias: ckeditor }
arguments: [ @service_container ]

trsteel_ckeditor.transformer.strip_js:
class: Trsteel\CkeditorBundle\Form\Transformer\StripJS
tags:
- { name: trsteel_ckeditor.transformer, alias: strip_js }

trsteel_ckeditor.transformer.strip_css:
class: Trsteel\CkeditorBundle\Form\Transformer\StripCSS
tags:
- { name: trsteel_ckeditor.transformer, alias: strip_css }

trsteel_ckeditor.transformer.strip_comments:
class: Trsteel\CkeditorBundle\Form\Transformer\StripComments
trsteel_ckeditor.transformer.html_purifier:
class: Exercise\HTMLPurifierBundle\Form\HTMLPurifierTransformer
public: false
arguments: [@exercise_html_purifier.default]
tags:
- { name: trsteel_ckeditor.transformer, alias: strip_comments }
- { name: trsteel_ckeditor.transformer, alias: html_purifier }
2 changes: 1 addition & 1 deletion Resources/doc/transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ $form = $this->createFormBuilder($post)
;
```

Note: If you override the transformers value none of the default transformers will be including (eg strip_js, strip_css etc)
Note: If you override the transformers value none of the default transformers will be including (eg html_purifier)
31 changes: 31 additions & 0 deletions Tests/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Trsteel\CkeditorBundle\Tests;

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
public function getRootDir()
{
return __DIR__.'/Resources';
}

public function registerBundles()
{
$bundles = array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Trsteel\CkeditorBundle\TrsteelCkeditorBundle(),
new \Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(),
);

return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/Resources/config/config.yml');
}
}
12 changes: 3 additions & 9 deletions Tests/Form/CkeditorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Trsteel\CkeditorBundle\Tests\Form;

use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Form\Forms;
use Trsteel\CkeditorBundle\Form\Type\CkeditorType;
use Trsteel\CkeditorBundle\Form\Transformer\StripJS;
use Trsteel\CkeditorBundle\Form\Transformer\StripCSS;
use Trsteel\CkeditorBundle\Form\Transformer\StripComments;
use Trsteel\CkeditorBundle\Tests\AppKernel;

class CkeditorTypeTest extends TypeTestCase
{
Expand All @@ -16,7 +14,7 @@ class CkeditorTypeTest extends TypeTestCase

public static function setUpBeforeClass()
{
self::$kernel = new \AppKernel('dev', true);
self::$kernel = new AppKernel('dev', true);
self::$kernel->boot();

self::$container = self::$kernel->getContainer();
Expand All @@ -33,10 +31,6 @@ public function setUp()

$ckeditorType = new CkeditorType($this->get('service_container'));

$ckeditorType->addTransformer(new StripJS(), 'strip_js');
$ckeditorType->addTransformer(new StripCSS(), 'strip_css');
$ckeditorType->addTransformer(new StripComments(), 'strip_comments');

$this->factory = Forms::createFormFactoryBuilder()
->addType($ckeditorType)
->getFormFactory();
Expand Down
File renamed without changes.
50 changes: 0 additions & 50 deletions Tests/autoload.php.dist

This file was deleted.

23 changes: 0 additions & 23 deletions Tests/bin/vendors

This file was deleted.

8 changes: 1 addition & 7 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?php

system(sprintf('php %s', escapeshellarg(__DIR__.'/bin/vendors')));

if (file_exists($file = __DIR__.'/autoload.php')) {
require_once $file;
} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) {
require_once $file;
}
require __DIR__.'/../vendor/autoload.php';
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
"php": ">=5.3.0",
"symfony/framework-bundle": "2.*,<2.4",
"symfony/form": ">=2.1,<2.4-dev",
"twig/twig": ">=1.1,<2.0-dev"

"twig/twig": ">=1.1,<2.0-dev",
"exercise/htmlpurifier-bundle": "dev-master"
},
"require-dev": {
"symfony/twig-bundle": "2.*,<2.4",
"symfony/yaml": "~2.0"
},
"autoload": {
"psr-0": { "Trsteel\\CkeditorBundle": "" }
Expand Down
Loading

0 comments on commit c28873f

Please sign in to comment.