diff --git a/Controller/FrontController.php b/Controller/FrontController.php
new file mode 100644
index 0000000..55aaaf4
--- /dev/null
+++ b/Controller/FrontController.php
@@ -0,0 +1,19 @@
+root('rating_filter');
+
+ $rootNode
+ ->children()
+ ->integerNode('max_rating')
+ ->defaultValue(5)
+ ->end()
+ ->scalarNode('star_full_template')
+ ->defaultValue('')
+ ->end()
+ ->scalarNode('set_star_half_empty_template')
+ ->defaultValue('')
+ ->end()
+ ->scalarNode('set_star_empty')
+ ->defaultValue('')
+ ->end()
+ ->end()
+ ;
+
+ return $treeBuilder;
+ }
+}
diff --git a/DependencyInjection/KarolNetTwigRatingFilterExtension.php b/DependencyInjection/KarolNetTwigRatingFilterExtension.php
new file mode 100644
index 0000000..3aaaff8
--- /dev/null
+++ b/DependencyInjection/KarolNetTwigRatingFilterExtension.php
@@ -0,0 +1,29 @@
+processConfiguration($configuration, $configs);
+
+ $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.yml');
+ $container->setParameter('rating_filter', $config);
+ }
+}
diff --git a/KarolNetTwigRatingFilterBundle.php b/KarolNetTwigRatingFilterBundle.php
new file mode 100644
index 0000000..884762c
--- /dev/null
+++ b/KarolNetTwigRatingFilterBundle.php
@@ -0,0 +1,9 @@
+'
+ set_star_half_empty_template: ''
+ set_star_empty: ''
+
+services:
+ karol_net.twig_extension.rating:
+ class: KarolNet\TwigRatingFilterBundle\Twig\RatingExtension
+ public: false
+ arguments:
+ - "%rating_filter%"
+ tags:
+ - { name: twig.extension }
diff --git a/Resources/translations/messages.fr.xlf b/Resources/translations/messages.fr.xlf
new file mode 100644
index 0000000..fd59e6c
--- /dev/null
+++ b/Resources/translations/messages.fr.xlf
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+ J'aime Symfony2
+
+
+
+
diff --git a/Resources/views/Front/index.html.twig b/Resources/views/Front/index.html.twig
new file mode 100644
index 0000000..12aa636
--- /dev/null
+++ b/Resources/views/Front/index.html.twig
@@ -0,0 +1,5 @@
+{% extends '::base.html.twig' %}
+
+{% block body %}
+ {{ 2 | rating }}
+{% endblock %}
\ No newline at end of file
diff --git a/Resources/views/Rating/starEmpty.html.twig b/Resources/views/Rating/starEmpty.html.twig
new file mode 100644
index 0000000..7052f4f
--- /dev/null
+++ b/Resources/views/Rating/starEmpty.html.twig
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Resources/views/Rating/starFull.html.twig b/Resources/views/Rating/starFull.html.twig
new file mode 100644
index 0000000..4b7c560
--- /dev/null
+++ b/Resources/views/Rating/starFull.html.twig
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Resources/views/Rating/starHalfEmpty.html.twig b/Resources/views/Rating/starHalfEmpty.html.twig
new file mode 100644
index 0000000..fef7e5c
--- /dev/null
+++ b/Resources/views/Rating/starHalfEmpty.html.twig
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/Twig/RatingExtension.php b/Twig/RatingExtension.php
new file mode 100644
index 0000000..a8c560b
--- /dev/null
+++ b/Twig/RatingExtension.php
@@ -0,0 +1,60 @@
+maxRate = $configuration['max_rating'];
+ $this->starFull = $configuration['star_full_template'];
+ $this->starHalfEmpty = $configuration['set_star_half_empty_template'];
+ $this->starEmpty = $configuration['set_star_empty'];
+ }
+
+ public function getFilters()
+ {
+ return [
+ new \Twig_SimpleFilter(
+ 'rating',
+ [$this, 'showRating'],
+ ['is_safe' => ['html']]
+ ),
+ ];
+ }
+
+ public function showRating($rating)
+ {
+ $output = '';
+
+ for($count = 0; $count < $this->maxRate; $count++) {
+
+ if ($rating < $count) {
+ $output = $output . $this->starEmpty;
+ } elseif($rating == $count) {
+ $output = $output . $this->starHalfEmpty;
+ }else {
+ $output = $output . $this->starFull;
+ }
+ }
+
+ return $output;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return 'rating_extension';
+ }
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index a01fd6b..e14bb4c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,5 @@
{
- "name": "karolnet/rating-filter",
+ "name": "karolnet/twig-rating-filter",
"description": "Rating filter for twig",
"license": "MIT",
"type": "symfony-bundle",
@@ -14,6 +14,6 @@
"php": ">=5.3.3"
},
"autoload": {
- "psr-4": { "KarolNet\\RatingFilterBundle\\": "" }
+ "psr-4": { "KarolNet\\TwigRatingFilterBundle\\": "" }
}
}