diff --git a/CommonExtension.php b/CommonExtension.php index 4d29d89..011cbe7 100644 --- a/CommonExtension.php +++ b/CommonExtension.php @@ -3,21 +3,12 @@ namespace Parisek\Twig; use Symfony\Component\Yaml\Yaml; -use CommerceGuys\Intl\Currency\CurrencyRepository; -use CommerceGuys\Intl\NumberFormat\NumberFormatRepository; -use CommerceGuys\Intl\Formatter\CurrencyFormatter; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; final class CommonExtension extends AbstractExtension { - private $numberFormatterPrototype; - - public function __construct(\NumberFormatter $numberFormatterPrototype = null) { - $this->numberFormatterPrototype = $numberFormatterPrototype; - } - public function getFunctions() { return [ new TwigFunction('uniqueId', [ @@ -63,19 +54,4 @@ public function getUniqueId() { public function yamlParse($content) { return Yaml::parse($content); } - - public function formatPrice($price, array $options = []) { - if (empty($price)) { - return ''; - } - elseif (is_array($price) && isset($price['currency_code']) && isset($price['number'])) { - $numberFormatRepository = new NumberFormatRepository; - $currencyRepository = new CurrencyRepository; - $currencyFormatter = new CurrencyFormatter($numberFormatRepository, $currencyRepository); - return $currencyFormatter->format($price['number'], $price['currency_code'], $options); - } - else { - throw new \InvalidArgumentException('The "format_price" filter must be given an array with "number" and "currency_code" keys.'); - } - } } diff --git a/README.md b/README.md index 63d7365..9e56890 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,25 @@ -Twig Typography Extension -======================= -Uses [PHP-Typography](https://github.com/mundschenk-at/php-typography) library and exposes it as Twig Extension. See [class-settings.php](https://github.com/mundschenk-at/php-typography/blob/0fa6cf412124171360eebab59ca77769c67c9740/src/class-settings.php#L247) for possible options. - -* Hyphenation — over 50 languages supported -* Space control, including: - - widow protection - - gluing values to units - - forced internal wrapping of long URLs & email addresses -* Intelligent character replacement, including smart handling of: - - quote marks (‘single’, “double”) - - dashes ( – ) - - ellipses (…) - - trademarks, copyright & service marks (™ ©) - - math symbols (5×5×5=53) - - fractions (1⁄16) - - ordinal suffixes (1st, 2nd) -* CSS hooks for styling: - - ampersands, - - uppercase words, - - numbers, - - initial quotes & guillemets. +Twig Common Extension +===================== ## Installation -Twig Attribute Extension can be easily installed using [composer](http://getcomposer.org/) +Twig Common Extension can be easily installed using [composer](http://getcomposer.org/) - composer require parisek/twig-typography + composer require parisek/twig-common ## Usage ```php $twig = new Twig_Environment($loader); -$twig->addExtension(new Parisek\Twig\AttributeExtension(__DIR__ . '/typography.yml')); +$twig->addExtension(new Parisek\Twig\CommonExtension()); ``` ## Template ```twig -{{ title|typography }} +{% set sidebar = source('sidebar.yml')|yaml_parse %} ``` ```twig -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper semper nunc, a hendrerit leo auctor ultricies. -
-{% endtypography %} -``` - -## Inspiration -- [Twig Extension Symfony Bundle](https://github.com/debach/typography-bundle) -- [Twig Typography Drupal Module](https://www.drupal.org/project/twig_typography) diff --git a/composer.json b/composer.json index c502fc8..bbaf65a 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,6 @@ "require": { "php": ">=7.3.0", "symfony/yaml": "^3.4|^4.2|^5.0", - "commerceguys/intl": "^1.0", "twig/twig": "^2.4|^3.0" }, "autoload": {