From 3f492a1bf54dc8b62dc42300d28b6ee06c47529a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 22 Aug 2014 22:06:02 -0700 Subject: [PATCH] Add a simple FILTERS pragma example. This includes examples of both section and interpolation filters. --- test/fixtures/examples/filters/Filters.php | 88 +++++++++++++++++++ .../examples/filters/filters.mustache | 4 + test/fixtures/examples/filters/filters.txt | 50 +++++++++++ 3 files changed, 142 insertions(+) create mode 100644 test/fixtures/examples/filters/Filters.php create mode 100644 test/fixtures/examples/filters/filters.mustache create mode 100644 test/fixtures/examples/filters/filters.txt diff --git a/test/fixtures/examples/filters/Filters.php b/test/fixtures/examples/filters/Filters.php new file mode 100644 index 0000000..1899ab4 --- /dev/null +++ b/test/fixtures/examples/filters/Filters.php @@ -0,0 +1,88 @@ + 'Alabama', + 'ak' => 'Alaska', + 'az' => 'Arizona', + 'ar' => 'Arkansas', + 'ca' => 'California', + 'co' => 'Colorado', + 'ct' => 'Connecticut', + 'de' => 'Delaware', + 'fl' => 'Florida', + 'ga' => 'Georgia', + 'hi' => 'Hawaii', + 'id' => 'Idaho', + 'il' => 'Illinois', + 'in' => 'Indiana', + 'ia' => 'Iowa', + 'ks' => 'Kansas', + 'ky' => 'Kentucky', + 'la' => 'Louisiana', + 'me' => 'Maine', + 'md' => 'Maryland', + 'ma' => 'Massachusetts', + 'mi' => 'Michigan', + 'mn' => 'Minnesota', + 'ms' => 'Mississippi', + 'mo' => 'Missouri', + 'mt' => 'Montana', + 'ne' => 'Nebraska', + 'nv' => 'Nevada', + 'nh' => 'New Hampshire', + 'nj' => 'New Jersey', + 'nm' => 'New Mexico', + 'ny' => 'New York', + 'nc' => 'North Carolina', + 'nd' => 'North Dakota', + 'oh' => 'Ohio', + 'ok' => 'Oklahoma', + 'or' => 'Oregon', + 'pa' => 'Pennsylvania', + 'ri' => 'Rhode Island', + 'sc' => 'South Carolina', + 'sd' => 'South Dakota', + 'tn' => 'Tennessee', + 'tx' => 'Texas', + 'ut' => 'Utah', + 'vt' => 'Vermont', + 'va' => 'Virginia', + 'wa' => 'Washington', + 'wv' => 'West Virginia', + 'wi' => 'Wisconsin', + 'wy' => 'Wyoming', + ); + + // The next few functions are ugly, because they have to work in PHP 5.2... + // for everyone who doesn't have to support 5.2, please, for the love, make + // your ViewModel return closures rather than `array($this, '...')` + // + // :) + + public function upcase() + { + return array($this, '_upcase'); + } + + public function _upcase($val) + { + return strtoupper($val); + } + + public function eachPair() + { + return array($this, '_eachPair'); + } + + public function _eachPair($val) + { + $ret = array(); + foreach ($val as $key => $value) { + array_push($ret, compact('key', 'value')); + } + + return $ret; + } +} diff --git a/test/fixtures/examples/filters/filters.mustache b/test/fixtures/examples/filters/filters.mustache new file mode 100644 index 0000000..50f1465 --- /dev/null +++ b/test/fixtures/examples/filters/filters.mustache @@ -0,0 +1,4 @@ +{{%FILTERS}} +{{# states | eachPair }} +{{ key | upcase }}: {{ value }} +{{/ states }} \ No newline at end of file diff --git a/test/fixtures/examples/filters/filters.txt b/test/fixtures/examples/filters/filters.txt new file mode 100644 index 0000000..67466fd --- /dev/null +++ b/test/fixtures/examples/filters/filters.txt @@ -0,0 +1,50 @@ +AL: Alabama +AK: Alaska +AZ: Arizona +AR: Arkansas +CA: California +CO: Colorado +CT: Connecticut +DE: Delaware +FL: Florida +GA: Georgia +HI: Hawaii +ID: Idaho +IL: Illinois +IN: Indiana +IA: Iowa +KS: Kansas +KY: Kentucky +LA: Louisiana +ME: Maine +MD: Maryland +MA: Massachusetts +MI: Michigan +MN: Minnesota +MS: Mississippi +MO: Missouri +MT: Montana +NE: Nebraska +NV: Nevada +NH: New Hampshire +NJ: New Jersey +NM: New Mexico +NY: New York +NC: North Carolina +ND: North Dakota +OH: Ohio +OK: Oklahoma +OR: Oregon +PA: Pennsylvania +RI: Rhode Island +SC: South Carolina +SD: South Dakota +TN: Tennessee +TX: Texas +UT: Utah +VT: Vermont +VA: Virginia +WA: Washington +WV: West Virginia +WI: Wisconsin +WY: Wyoming