Skip to content

Commit

Permalink
Removed format_price filter
Browse files Browse the repository at this point in the history
  • Loading branch information
parisek committed Aug 14, 2021
1 parent 669861f commit 308b900
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 69 deletions.
24 changes: 0 additions & 24 deletions CommonExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down Expand Up @@ -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.');
}
}
}
51 changes: 7 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 (<sup>1</sup>⁄<sub>16</sub>)
- ordinal suffixes (1<sup>st</sup>, 2<sup>nd</sup>)
* 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
<h1>{{ "Lorem Ipsum"|typography }}</h1>
{{ uniqueId() }}
```

```twig
{{ title|typography({'set_dewidow': FALSE}) }}
```

```twig
{% typography %}
<h1>Lorem Ipsum</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper semper nunc, a hendrerit leo auctor ultricies.
</p>
{% endtypography %}
```

## Inspiration
- [Twig Extension Symfony Bundle](https://github.com/debach/typography-bundle)
- [Twig Typography Drupal Module](https://www.drupal.org/project/twig_typography)
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 308b900

Please sign in to comment.