Skip to content

Commit

Permalink
add some love !
Browse files Browse the repository at this point in the history
* Symfony 5
* Documentation
* Travis
  • Loading branch information
nicolassing committed Feb 20, 2020
1 parent 1d37e38 commit bd23617
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,5 +2,6 @@
.php_cs.cache
composer.lock
phpunit.xml
.phpunit.result.cache
vendor/
.idea/
.idea/
31 changes: 31 additions & 0 deletions .php_cs.dist
@@ -0,0 +1,31 @@
<?php

$header = <<<EOF
This file is part of the FOSUserBundle package.
(c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'header_comment' => ['header' => $header],
'linebreak_after_opening_tag' => true,
'no_php4_constructor' => true,
'no_useless_else' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_strict' => true,
'phpdoc_no_empty_return' => false,
])
->setUsingCache(true)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
)
;
36 changes: 36 additions & 0 deletions .travis.yml
@@ -0,0 +1,36 @@

language: php

dist: bionic
sudo: false

cache:
directories:
- $HOME/.composer/cache/files
- .phpunit

env:
global:
- SYMFONY_PHPUNIT_DIR=.phpunit

matrix:
fast_finish: true
include:
- php: 7.2
- php: 7.3
# Test against dev versions
- php: nightly
env: DEPENDENCIES=dev
allow_failures:
- env: DEPENDENCIES=dev

before_install:
- composer self-update
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony:"$SYMFONY_VERSION"; fi

install:
- composer update $COMPOSER_FLAGS
- ./vendor/bin/simple-phpunit install

script: ./vendor/bin/simple-phpunit -v --coverage-text
16 changes: 11 additions & 5 deletions DependencyInjection/Configuration.php
@@ -1,5 +1,12 @@
<?php

/*
* This file is part of the FOSUserBundle package.
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nicolassing\QuillBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -10,12 +17,12 @@
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('nicolassing_quill');
$treeBuilder = new TreeBuilder('nicolassing_quill');
$rootNode = $treeBuilder->getRootNode();

$supportedThemes = array('snow', 'bubble');
$supportedThemes = ['snow', 'bubble'];

$rootNode
->children()
Expand All @@ -38,5 +45,4 @@ public function getConfigTreeBuilder()

return $treeBuilder;
}

}
13 changes: 10 additions & 3 deletions DependencyInjection/NicolassingQuillExtension.php
@@ -1,23 +1,30 @@
<?php

/*
* This file is part of the FOSUserBundle package.
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nicolassing\QuillBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\FileLocator;

/**
* @author Nicolas Assing <nicolas.assing@gmail.com>
*/
class NicolassingQuillExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('nicolassing_quill.config', $config);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}
}
}
19 changes: 13 additions & 6 deletions Form/Type/QuillType.php
@@ -1,5 +1,12 @@
<?php

/*
* This file is part of the FOSUserBundle package.
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nicolassing\QuillBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
Expand All @@ -20,23 +27,23 @@ public function __construct(array $config)
$this->config = $config;
}

public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$view->vars['theme'] = $options['theme'];
$view->vars['height'] = $options['height'];
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(
array(
[
'theme' => $this->config['theme'],
'height' => $this->config['height']
)
'height' => $this->config['height'],
]
);
}

public function getParent()
public function getParent(): string
{
return TextareaType::class;
}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Nicolas Assing
Copyright (c) 2018-2020 Nicolas Assing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 7 additions & 0 deletions NicolassingQuillBundle.php
@@ -1,5 +1,12 @@
<?php

/*
* This file is part of the FOSUserBundle package.
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nicolassing\QuillBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down
57 changes: 56 additions & 1 deletion README.md
@@ -1 +1,56 @@
# NicolassingQuillBundle
# NicolassingQuillBundle

This bundle integrate [quilljs](https://quilljs.com/docs) in your Symfony project.

## Installation ##

Add the `nicolassing/quill-bundle` package to your `require` section in the `composer.json` file.

``` bash
$ composer require nicolassing/quill-bundle
```

## Usage ##

Configure `quill` client(s) in your `config/packages/nicolassing_quill.yaml`:

``` yaml
nicolassing_quill:
theme: snow
height: 10rem
```

There is 2 themes available
* snow (default)
* bubble

Add a quill widget into your form
``` php
namespace App\Form\Type;

use Symfony\Component\Form\AbstractType;
use Nicolassing\QuillBundle\Form\Type\QuillType;
use Symfony\Component\Form\FormBuilderInterface;

class FooType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('bar', QuillType::class)
;
}
}
```

Add javascript and stylesheet in your twig template
``` twig
<!-- Include stylesheet -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
{{ form_row(form.bar) }}
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script src="bundles/nicolassingquill/js/nicolassing_quill.js"></scriptt>
```
6 changes: 3 additions & 3 deletions Resources/views/Form/fields.html.twig
@@ -1,8 +1,8 @@
{% block quill_widget %}
{% spaceless %}
{% apply spaceless %}
<div class="quill" data-theme="{{ theme }}" data-id="{{ id }}" style="height: {{ height }}">
{{ value|raw }}
</div>
<input type="hidden" {{ block('widget_attributes') }} value="{{ value }}" />
{% endspaceless %}
{% endblock %}
{% endapply %}
{% endblock %}
25 changes: 15 additions & 10 deletions Tests/DepencyInjection/NicolassingQuillExtensionTest.php
@@ -1,9 +1,17 @@
<?php

/*
* This file is part of the FOSUserBundle package.
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nicolassing\QuillBundle\Tests\DependencyInjection;

use Nicolassing\QuillBundle\DependencyInjection\NicolassingQuillExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Parser;

Expand All @@ -12,37 +20,33 @@
*/
class NicolassingQuillExtensionTest extends TestCase
{
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testLoadThrowsExceptionUnlessThemeSet()
{
$loader = new NicolassingQuillExtension();
$config = $this->getFullConfig();
unset($config['theme']);
$loader->load(array($config), new ContainerBuilder());
$this->expectException(InvalidConfigurationException::class);
$loader->load([$config], new ContainerBuilder());
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testLoadThrowsExceptionUnlessHeightSet()
{
$loader = new NicolassingQuillExtension();
$config = $this->getFullConfig();
unset($config['height']);
$loader->load(array($config), new ContainerBuilder());
$this->expectException(InvalidConfigurationException::class);
$loader->load([$config], new ContainerBuilder());
}

public function testLoadConfig()
{
$configuration = new ContainerBuilder();
$loader = new NicolassingQuillExtension();
$config = $this->getFullConfig();
$loader->load(array($config), $configuration);
$loader->load([$config], $configuration);

$this->assertTrue($configuration->hasParameter('nicolassing_quill.config'));
$this->assertEquals(['theme' => 'snow', 'height' => '10rem'], $configuration->getParameter('nicolassing_quill.config'));
$this->assertSame(['theme' => 'snow', 'height' => '10rem'], $configuration->getParameter('nicolassing_quill.config'));
}

protected function getFullConfig()
Expand All @@ -52,6 +56,7 @@ protected function getFullConfig()
height: 10rem
EOF;
$parser = new Parser();

return $parser->parse($yaml);
}
}

0 comments on commit bd23617

Please sign in to comment.