Permalink
Please sign in to comment.
Browse files
extension support + contrib info
and renamed 'filters' to 'extensions'
- Loading branch information...
Showing
with
531 additions
and 42 deletions.
- +57 −0 README.md
- +77 −0 extensions/i18n.php
- +80 −0 extensions/number.php
- +107 −0 extensions/text.php
- +136 −0 extensions/time.php
- +74 −42 views/twig.php
@@ -0,0 +1,77 @@ | ||
+<?php | ||
+/** | ||
+ * TwigView Filters for CakePHP | ||
+ * | ||
+ * - I18n Filter - | ||
+ * | ||
+ * @version 0.7.rock-lobster | ||
+ * @package app.views | ||
+ * @subpackage app.views.twig-filters | ||
+ * @author Kjell Bublitz <m3nt0r.de@gmail.com> | ||
+ * @license MIT License | ||
+ */ | ||
+ | ||
+/** | ||
+ * I18n - Extension for Filterset | ||
+ * | ||
+ * @package app.views.twig-extensions | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class Twig_Extension_I18n extends Twig_Extension { | ||
+ public function getName() { | ||
+ return 'I18n'; | ||
+ } | ||
+ public function getFilters() { | ||
+ return array( | ||
+ 'trans' => new Twig_Filter_Function('TwigView_Filter_I18n::trans'), | ||
+ ); | ||
+ } | ||
+} | ||
+TwigView::registerExtension(__FILE__, 'Twig_Extension_I18n'); | ||
+ | ||
+/** | ||
+ * NumberHelper - Filter Set | ||
+ * | ||
+ * @package app.views.twig-filters | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class TwigView_Filter_I18n extends TwigView_Extension { | ||
+ | ||
+ /** | ||
+ * Combines __, __n, __d, __dn | ||
+ * | ||
+ * Function is selected by the number of arguments given. | ||
+ * | ||
+ * - {{ 'Word'|trans }} | ||
+ * - {{ 'Word'|trans('users') }} | ||
+ * - {{ 'Word'|trans('Words', 5) }} | ||
+ * - {{ 'Word'|trans('Words', 'users', 5) }} | ||
+ * | ||
+ * @param string $text | ||
+ * @param string $param1 (plural, domain or empty(default)) | ||
+ * @param mixed $param2 | ||
+ * @param mixed $param3 | ||
+ * @return string | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function trans($text, $param1=null, $param2=null, $param3=null) { | ||
+ | ||
+ // 'Word'|trans('Words', 'users', 5) | ||
+ if (is_numeric($param3)) { | ||
+ return __dn($domain=$param2, $singular=$text, $plural=$param1, $count=$param3, true); | ||
+ } | ||
+ | ||
+ // 'Word'|trans('Words', 5) | ||
+ if (is_numeric($param2)) { | ||
+ return __n($singular=$text, $plural=$param1, $count=$param2, true); | ||
+ } | ||
+ | ||
+ // 'Word'|trans('users') | ||
+ if (!empty($param1) && !is_numeric($param1)) { | ||
+ return __d($domain=$param1, $text, true); | ||
+ } | ||
+ | ||
+ return __($text, true); | ||
+ } | ||
+ | ||
+} |
@@ -0,0 +1,80 @@ | ||
+<?php | ||
+/** | ||
+ * TwigView Filters for CakePHP | ||
+ * | ||
+ * - NumberHelper - | ||
+ * | ||
+ * @version 0.7.rock-lobster | ||
+ * @package app.views | ||
+ * @subpackage app.views.twig-filters | ||
+ * @author Kjell Bublitz <m3nt0r.de@gmail.com> | ||
+ * @license MIT License | ||
+ */ | ||
+App::import('Helper', 'Number'); | ||
+ | ||
+/** | ||
+ * NumberHelper - Extension for Filterset | ||
+ * | ||
+ * @package app.views.twig-extensions | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class Twig_Extension_Number extends Twig_Extension { | ||
+ public function getName() { | ||
+ return 'NumberHelper'; | ||
+ } | ||
+ public function getFilters() { | ||
+ return array( | ||
+ 'size' => new Twig_Filter_Function('TwigView_Filter_Number::size'), | ||
+ 'pct' => new Twig_Filter_Function('TwigView_Filter_Number::percentage'), | ||
+ 'curr' => new Twig_Filter_Function('TwigView_Filter_Number::currency'), | ||
+ 'p' => new Twig_Filter_Function('TwigView_Filter_Number::precision'), | ||
+ ); | ||
+ } | ||
+} | ||
+TwigView::registerExtension(__FILE__, 'Twig_Extension_Number'); | ||
+ | ||
+/** | ||
+ * NumberHelper - Filter Set | ||
+ * | ||
+ * @package app.views.twig-filters | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class TwigView_Filter_Number extends TwigView_Extension { | ||
+ | ||
+ /** | ||
+ * Wrapper to Number->toReadableSize() | ||
+ * | ||
+ * @param integer $length Size in bytes | ||
+ */ | ||
+ static function size($var) { | ||
+ return self::helperObject('NumberHelper')->toReadableSize($var); | ||
+ } | ||
+ /** | ||
+ * Wrapper to Number->toPercentage() | ||
+ * | ||
+ * @param float $number A floating point number | ||
+ * @param integer $precision The precision of the returned number | ||
+ */ | ||
+ static function percentage($var, $p=2) { | ||
+ return self::helperObject('NumberHelper')->toPercentage($var, $p); | ||
+ } | ||
+ /** | ||
+ * Wrapper to Number->currency() | ||
+ * | ||
+ * @param float $number | ||
+ * @param string $currency Valid values are 'USD', 'EUR', 'GBP' | ||
+ * @param array $options f.e. 'before' and 'after' options. | ||
+ */ | ||
+ static function currency($var, $curr='USD', $opts=array()) { | ||
+ return self::helperObject('NumberHelper')->currency($var, $curr, $opts); | ||
+ } | ||
+ /** | ||
+ * Wrapper to Number->precision() | ||
+ * | ||
+ * @param float $number A floating point number | ||
+ * @param integer $precision The precision of the returned number | ||
+ */ | ||
+ static function precision($var, $p=2) { | ||
+ return self::helperObject('NumberHelper')->precision($var, $p); | ||
+ } | ||
+} |
@@ -0,0 +1,107 @@ | ||
+<?php | ||
+/** | ||
+ * TwigView Filters for CakePHP | ||
+ * | ||
+ * - TextHelper - | ||
+ * | ||
+ * @version 0.7.rock-lobster | ||
+ * @package app.views | ||
+ * @subpackage app.views.twig-filters | ||
+ * @author Kjell Bublitz <m3nt0r.de@gmail.com> | ||
+ * @license MIT License | ||
+ */ | ||
+App::import('Helper', 'Text'); | ||
+ | ||
+/** | ||
+ * TextHelper - Extension for Filterset | ||
+ * | ||
+ * @package app.views.twig-extensions | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class Twig_Extension_Text extends Twig_Extension { | ||
+ public function getName() { | ||
+ return 'TextHelper'; | ||
+ } | ||
+ public function getFilters() { | ||
+ return array( | ||
+ 'stripLinks' => new Twig_Filter_Function('TwigView_Filter_Text::stripLinks'), | ||
+ 'autoLink' => new Twig_Filter_Function('TwigView_Filter_Text::autoLink'), | ||
+ 'truncate' => new Twig_Filter_Function('TwigView_Filter_Text::truncate'), | ||
+ 'excerpt' => new Twig_Filter_Function('TwigView_Filter_Text::excerpt'), | ||
+ 'highlight' => new Twig_Filter_Function('TwigView_Filter_Text::highlight'), | ||
+ ); | ||
+ } | ||
+} | ||
+TwigView::registerExtension(__FILE__, 'Twig_Extension_Text'); | ||
+ | ||
+/** | ||
+ * TextHelper - Filter Set | ||
+ * | ||
+ * @package app.views.twig-filters | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+class TwigView_Filter_Text extends TwigView_Extension { | ||
+ | ||
+ /** | ||
+ * TextHelper::stripLinks | ||
+ * | ||
+ * @param string $var | ||
+ * @return void | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function stripLinks($var) { | ||
+ return self::helperObject('TextHelper')->stripLinks($var); | ||
+ } | ||
+ | ||
+ /** | ||
+ * TextHelper::autoLink | ||
+ * | ||
+ * @param string $var | ||
+ * @return void | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function autoLink($var) { | ||
+ return self::helperObject('TextHelper')->autoLink($var); | ||
+ } | ||
+ | ||
+ /** | ||
+ * TextHelper::truncate | ||
+ * | ||
+ * @param string $var | ||
+ * @param integer $length Length of returned string, including ellipsis. | ||
+ * @param array $options An array of html attributes and options. | ||
+ * @return void | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function truncate($var, $length = 100, $options = array()) { | ||
+ return self::helperObject('TextHelper')->truncate($var, $length, $options); | ||
+ } | ||
+ | ||
+ /** | ||
+ * TextHelper::excerpt | ||
+ * | ||
+ * @param string $var | ||
+ * @param string $phrase Phrase that will be searched for | ||
+ * @param integer $radius The amount of characters that will be returned on each side of the founded phrase | ||
+ * @param string $ending Ending that will be appended (default: '...') | ||
+ * @return void | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function excerpt($var, $phrase, $radius = 100, $ending = '...') { | ||
+ return self::helperObject('TextHelper')->excerpt($var, $phrase, $radius, $ending); | ||
+ } | ||
+ | ||
+ /** | ||
+ * TextHelper::highlight | ||
+ * | ||
+ * @param string $var | ||
+ * @param string $phrase The phrase that will be searched | ||
+ * @param array $options An array of html attributes and options. | ||
+ * @return void | ||
+ * @author Kjell Bublitz | ||
+ */ | ||
+ static function highlight($var, $phrase, $options = array()) { | ||
+ return self::helperObject('TextHelper')->highlight($var, $phrase, $options); | ||
+ } | ||
+} | ||
+ |

Oops, something went wrong.
0 comments on commit
f67225d