├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── Exception.php ├── LICENSE ├── README.md ├── ViewRenderer.php ├── composer.json ├── composer.lock ├── phpunit.xml.dist └── tests └── unit ├── .gitignore ├── TestCase.php ├── bootstrap.php ├── config ├── .gitignore └── main.php ├── filters └── EscapedFilter.php ├── renderer └── MainTest.php ├── runtime └── .gitignore └── views ├── extend.pug ├── filters.pug └── main.pug /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /vendor 3 | /coverage 4 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | build: 2 | environment: 3 | php: 4 | version: 5.5.12 5 | dependencies: 6 | before: 7 | - composer global require "fxp/composer-asset-plugin:~1.1" 8 | tests: 9 | override: 10 | - phpunit 11 | imports: 12 | - php 13 | checks: 14 | php: 15 | code_rating: true 16 | duplication: true 17 | tools: 18 | php_sim: false 19 | php_cpd: false 20 | php_pdepend: true 21 | php_analyzer: true 22 | php_changetracking: true 23 | external_code_coverage: 24 | timeout: 2100 # Timeout in seconds. 25 | filter: 26 | excluded_paths: 27 | - tests/* 28 | - vendor/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.5 5 | - 5.6 6 | - hhvm 7 | - hhvm-nightly 8 | 9 | matrix: 10 | fast_finish: true 11 | allow_failures: 12 | - php: hhvm 13 | - php: hhvm-nightly 14 | 15 | sudo: false 16 | 17 | cache: 18 | directories: 19 | - vendor 20 | 21 | install: 22 | - travis_retry composer self-update && composer --version 23 | - travis_retry composer global require "fxp/composer-asset-plugin:~1.1" 24 | - export PATH="$HOME/.composer/vendor/bin:$PATH" 25 | - travis_retry composer install --prefer-dist --no-interaction 26 | 27 | script: 28 | - phpunit --verbose --coverage-clover=coverage/coverage.clover 29 | 30 | after_script: 31 | - travis_retry wget https://scrutinizer-ci.com/ocular.phar 32 | - php ocular.phar code-coverage:upload --format=php-clover coverage/coverage.clover -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2017-01-24 - 0.0.1 2 | ------------------- 3 | * Initialize extension. 4 | -------------------------------------------------------------------------------- /Exception.php: -------------------------------------------------------------------------------- 1 | [ 53 | // ... 54 | 'view' => [ 55 | // ... 56 | 'renderers' => [ 57 | 'pug' => 'rmrevin\\yii\\pug\\ViewRenderer', 58 | ], 59 | ] 60 | ] 61 | ]; 62 | ``` 63 | 64 | That's all! Now you can use pug templates. 65 | -------------------------------------------------------------------------------- /ViewRenderer.php: -------------------------------------------------------------------------------- 1 | false, 33 | 'extension' => '.pug', 34 | 'upToDateCheck' => true, 35 | ]; 36 | /** 37 | * @var array Custom filters. 38 | * Keys of the array are names to call in template, values are names of functions or static methods of some class. 39 | * Example: `['rot13' => 'str_rot13', 'jsonEncode' => '\yii\helpers\Json::encode']`. 40 | * In the template you can use it like this: `{{ 'test'|rot13 }}` or `{{ model|jsonEncode }}`. 41 | */ 42 | public $filters = []; 43 | /** 44 | * @var Pug pug environment object that renders pug templates 45 | */ 46 | public $pug; 47 | 48 | public function init() 49 | { 50 | $cachePath = empty($this->cachePath) ? false : Yii::getAlias($this->cachePath); 51 | 52 | if (!empty($cachePath) && !file_exists($cachePath)) { 53 | FileHelper::createDirectory($cachePath); 54 | } 55 | 56 | if (!empty($cachePath) && !is_readable($cachePath)) { 57 | throw new Exception(\Yii::t('app', 'Pug cache path is not readable.')); 58 | } 59 | 60 | if (!empty($cachePath) && !is_writeable($cachePath)) { 61 | throw new Exception(\Yii::t('app', 'Pug cache path is not writable.')); 62 | } 63 | 64 | $this->pug = new Pug(array_merge([ 65 | 'cache' => $cachePath, 66 | ], $this->options)); 67 | 68 | // Adding custom filters 69 | if (!empty($this->filters)) { 70 | foreach ($this->filters as $name => $handler) { 71 | $this->addFilter($name, $handler); 72 | } 73 | } 74 | } 75 | 76 | /** 77 | * Renders a view file. 78 | * 79 | * This method is invoked by [[View]] whenever it tries to render a view. 80 | * Child classes must implement this method to render the given view file. 81 | * 82 | * @param View $view the view object used for rendering the file. 83 | * @param string $file the view file. 84 | * @param array $params the parameters to be passed to the view file. 85 | * 86 | * @return string the rendering result 87 | */ 88 | public function render($view, $file, $params) 89 | { 90 | return $this->pug->render($file, $params); 91 | } 92 | 93 | /** 94 | * Adds custom filter 95 | * @param string $name 96 | * @param callable $handler 97 | */ 98 | public function addFilter($name, $handler) 99 | { 100 | $this->pug->filter($name, $handler); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rmrevin/yii2-pug", 3 | "description": "Yii2 Pug (ex Jade) extension", 4 | "keywords": [ 5 | "yii", 6 | "pug", 7 | "jade", 8 | "view", 9 | "renderer" 10 | ], 11 | "type": "yii2-extension", 12 | "license": "MIT", 13 | "minimum-stability": "stable", 14 | "support": { 15 | "issues": "https://github.com/rmrevin/yii2-pug/issues", 16 | "source": "https://github.com/rmrevin/yii2-pug" 17 | }, 18 | "authors": [ 19 | { 20 | "name": "Revin Roman", 21 | "email": "roman@rmrevin.com", 22 | "homepage": "https://rmrevin.com/" 23 | } 24 | ], 25 | "require": { 26 | "php": ">=5.4.0", 27 | "yiisoft/yii2": "2.0.*", 28 | "pug-php/pug": "~2.5" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "rmrevin\\yii\\pug\\": "" 33 | } 34 | }, 35 | "extra": { 36 | "asset-installer-paths": { 37 | "npm-asset-library": "vendor/npm", 38 | "bower-asset-library": "vendor/bower" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "d5d23bc439a873bcd666efdba0cb9cc0", 8 | "packages": [ 9 | { 10 | "name": "bower-asset/jquery", 11 | "version": "2.2.4", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/jquery/jquery-dist.git", 15 | "reference": "c0185ab7c75aab88762c5aae780b9d83b80eda72" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/c0185ab7c75aab88762c5aae780b9d83b80eda72", 20 | "reference": "c0185ab7c75aab88762c5aae780b9d83b80eda72", 21 | "shasum": "" 22 | }, 23 | "type": "bower-asset-library", 24 | "extra": { 25 | "bower-asset-main": "dist/jquery.js", 26 | "bower-asset-ignore": [ 27 | "package.json" 28 | ] 29 | }, 30 | "license": [ 31 | "MIT" 32 | ], 33 | "keywords": [ 34 | "browser", 35 | "javascript", 36 | "jquery", 37 | "library" 38 | ] 39 | }, 40 | { 41 | "name": "bower-asset/jquery.inputmask", 42 | "version": "3.2.7", 43 | "source": { 44 | "type": "git", 45 | "url": "https://github.com/RobinHerbots/Inputmask.git", 46 | "reference": "5a72c563b502b8e05958a524cdfffafe9987be38" 47 | }, 48 | "dist": { 49 | "type": "zip", 50 | "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38", 51 | "reference": "5a72c563b502b8e05958a524cdfffafe9987be38", 52 | "shasum": "" 53 | }, 54 | "require": { 55 | "bower-asset/jquery": ">=1.7" 56 | }, 57 | "type": "bower-asset-library", 58 | "extra": { 59 | "bower-asset-main": [ 60 | "./dist/inputmask/inputmask.js" 61 | ], 62 | "bower-asset-ignore": [ 63 | "**/*", 64 | "!dist/*", 65 | "!dist/inputmask/*", 66 | "!dist/min/*", 67 | "!dist/min/inputmask/*", 68 | "!extra/bindings/*", 69 | "!extra/dependencyLibs/*", 70 | "!extra/phone-codes/*" 71 | ] 72 | }, 73 | "license": [ 74 | "http://opensource.org/licenses/mit-license.php" 75 | ], 76 | "description": "jquery.inputmask is a jquery plugin which create an input mask.", 77 | "keywords": [ 78 | "form", 79 | "input", 80 | "inputmask", 81 | "jquery", 82 | "mask", 83 | "plugins" 84 | ] 85 | }, 86 | { 87 | "name": "bower-asset/punycode", 88 | "version": "v1.3.2", 89 | "source": { 90 | "type": "git", 91 | "url": "https://github.com/bestiejs/punycode.js.git", 92 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" 93 | }, 94 | "dist": { 95 | "type": "zip", 96 | "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3", 97 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3", 98 | "shasum": "" 99 | }, 100 | "type": "bower-asset-library", 101 | "extra": { 102 | "bower-asset-main": "punycode.js", 103 | "bower-asset-ignore": [ 104 | "coverage", 105 | "tests", 106 | ".*", 107 | "component.json", 108 | "Gruntfile.js", 109 | "node_modules", 110 | "package.json" 111 | ] 112 | } 113 | }, 114 | { 115 | "name": "bower-asset/yii2-pjax", 116 | "version": "v2.0.6", 117 | "source": { 118 | "type": "git", 119 | "url": "https://github.com/yiisoft/jquery-pjax.git", 120 | "reference": "60728da6ade5879e807a49ce59ef9a72039b8978" 121 | }, 122 | "dist": { 123 | "type": "zip", 124 | "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/60728da6ade5879e807a49ce59ef9a72039b8978", 125 | "reference": "60728da6ade5879e807a49ce59ef9a72039b8978", 126 | "shasum": "" 127 | }, 128 | "require": { 129 | "bower-asset/jquery": ">=1.8" 130 | }, 131 | "type": "bower-asset-library", 132 | "extra": { 133 | "bower-asset-main": "./jquery.pjax.js", 134 | "bower-asset-ignore": [ 135 | ".travis.yml", 136 | "Gemfile", 137 | "Gemfile.lock", 138 | "CONTRIBUTING.md", 139 | "vendor/", 140 | "script/", 141 | "test/" 142 | ] 143 | }, 144 | "license": [ 145 | "MIT" 146 | ] 147 | }, 148 | { 149 | "name": "cebe/markdown", 150 | "version": "1.1.1", 151 | "source": { 152 | "type": "git", 153 | "url": "https://github.com/cebe/markdown.git", 154 | "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166" 155 | }, 156 | "dist": { 157 | "type": "zip", 158 | "url": "https://api.github.com/repos/cebe/markdown/zipball/c30eb5e01fe021cc5bba2f9ee0eeef96d4931166", 159 | "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166", 160 | "shasum": "" 161 | }, 162 | "require": { 163 | "lib-pcre": "*", 164 | "php": ">=5.4.0" 165 | }, 166 | "require-dev": { 167 | "cebe/indent": "*", 168 | "facebook/xhprof": "*@dev", 169 | "phpunit/phpunit": "4.1.*" 170 | }, 171 | "bin": [ 172 | "bin/markdown" 173 | ], 174 | "type": "library", 175 | "extra": { 176 | "branch-alias": { 177 | "dev-master": "1.1.x-dev" 178 | } 179 | }, 180 | "autoload": { 181 | "psr-4": { 182 | "cebe\\markdown\\": "" 183 | } 184 | }, 185 | "notification-url": "https://packagist.org/downloads/", 186 | "license": [ 187 | "MIT" 188 | ], 189 | "authors": [ 190 | { 191 | "name": "Carsten Brandt", 192 | "email": "mail@cebe.cc", 193 | "homepage": "http://cebe.cc/", 194 | "role": "Creator" 195 | } 196 | ], 197 | "description": "A super fast, highly extensible markdown parser for PHP", 198 | "homepage": "https://github.com/cebe/markdown#readme", 199 | "keywords": [ 200 | "extensible", 201 | "fast", 202 | "gfm", 203 | "markdown", 204 | "markdown-extra" 205 | ], 206 | "time": "2016-09-14T20:40:20+00:00" 207 | }, 208 | { 209 | "name": "ezyang/htmlpurifier", 210 | "version": "v4.9.0", 211 | "source": { 212 | "type": "git", 213 | "url": "https://github.com/ezyang/htmlpurifier.git", 214 | "reference": "a1c09b09e398687deeb8e309a6305def4b43439b" 215 | }, 216 | "dist": { 217 | "type": "zip", 218 | "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/a1c09b09e398687deeb8e309a6305def4b43439b", 219 | "reference": "a1c09b09e398687deeb8e309a6305def4b43439b", 220 | "shasum": "" 221 | }, 222 | "require": { 223 | "php": ">=5.2" 224 | }, 225 | "require-dev": { 226 | "simpletest/simpletest": "^1.1" 227 | }, 228 | "type": "library", 229 | "autoload": { 230 | "psr-0": { 231 | "HTMLPurifier": "library/" 232 | }, 233 | "files": [ 234 | "library/HTMLPurifier.composer.php" 235 | ] 236 | }, 237 | "notification-url": "https://packagist.org/downloads/", 238 | "license": [ 239 | "LGPL" 240 | ], 241 | "authors": [ 242 | { 243 | "name": "Edward Z. Yang", 244 | "email": "admin@htmlpurifier.org", 245 | "homepage": "http://ezyang.com" 246 | } 247 | ], 248 | "description": "Standards compliant HTML filter written in PHP", 249 | "homepage": "http://htmlpurifier.org/", 250 | "keywords": [ 251 | "html" 252 | ], 253 | "time": "2017-01-13T12:31:37+00:00" 254 | }, 255 | { 256 | "name": "js-phpize/js-phpize", 257 | "version": "1.2.1", 258 | "source": { 259 | "type": "git", 260 | "url": "https://github.com/pug-php/js-phpize.git", 261 | "reference": "3faa4fd7d11f85c8b9280125a7f7dec5b6dff769" 262 | }, 263 | "dist": { 264 | "type": "zip", 265 | "url": "https://api.github.com/repos/pug-php/js-phpize/zipball/3faa4fd7d11f85c8b9280125a7f7dec5b6dff769", 266 | "reference": "3faa4fd7d11f85c8b9280125a7f7dec5b6dff769", 267 | "shasum": "" 268 | }, 269 | "require": { 270 | "php": ">=5.3.0" 271 | }, 272 | "require-dev": { 273 | "codeclimate/php-test-reporter": "dev-master", 274 | "phpunit/phpunit": ">=4.8" 275 | }, 276 | "type": "library", 277 | "autoload": { 278 | "psr-0": { 279 | "JsPhpize": "src/" 280 | } 281 | }, 282 | "notification-url": "https://packagist.org/downloads/", 283 | "license": [ 284 | "MIT" 285 | ], 286 | "authors": [ 287 | { 288 | "name": "Kyle Katarn", 289 | "email": "kylekatarnls@gmail.com" 290 | } 291 | ], 292 | "description": "Convert js-like syntax to standalone PHP code.", 293 | "time": "2017-01-09T15:34:06+00:00" 294 | }, 295 | { 296 | "name": "pug-php/pug", 297 | "version": "2.5.3", 298 | "source": { 299 | "type": "git", 300 | "url": "https://github.com/pug-php/pug.git", 301 | "reference": "339bc73949cea13fc9c89da09368170818efa03e" 302 | }, 303 | "dist": { 304 | "type": "zip", 305 | "url": "https://api.github.com/repos/pug-php/pug/zipball/339bc73949cea13fc9c89da09368170818efa03e", 306 | "reference": "339bc73949cea13fc9c89da09368170818efa03e", 307 | "shasum": "" 308 | }, 309 | "require": { 310 | "js-phpize/js-phpize": "^1.2", 311 | "php": ">=5.3.0" 312 | }, 313 | "replace": { 314 | "kylekatarnls/jade-php": "self.version" 315 | }, 316 | "require-dev": { 317 | "codeclimate/php-test-reporter": ">=0.3", 318 | "phpunit/phpunit": ">=4.0" 319 | }, 320 | "type": "library", 321 | "autoload": { 322 | "psr-0": { 323 | "Pug\\": "src/", 324 | "Jade\\": "src/" 325 | } 326 | }, 327 | "notification-url": "https://packagist.org/downloads/", 328 | "license": [ 329 | "MIT" 330 | ], 331 | "authors": [ 332 | { 333 | "name": "Janez Troha", 334 | "email": "janez.troha@gmail.com", 335 | "homepage": "http://flavors.me/dz0ny", 336 | "role": "Maintainer" 337 | }, 338 | { 339 | "name": "Luke GB", 340 | "email": "git@lukegb.com", 341 | "homepage": "http://twitter.com/lukegb", 342 | "role": "Maintainer" 343 | }, 344 | { 345 | "name": "Ronan Tessier", 346 | "email": "ronan.tessier@vaconsulting.lu", 347 | "homepage": "http://github.com/ronan-gloo", 348 | "role": "Maintainer" 349 | }, 350 | { 351 | "name": "kylekatarnls", 352 | "email": "jade-php@selfbuild.fr", 353 | "homepage": "http://github.com/kylekatarnls", 354 | "role": "Developer" 355 | }, 356 | { 357 | "name": "volter9", 358 | "homepage": "https://github.com/volter9", 359 | "role": "Developer" 360 | }, 361 | { 362 | "name": "sisoftrg", 363 | "homepage": "https://github.com/sisoftrg", 364 | "role": "Developer" 365 | }, 366 | { 367 | "name": "hackaugusto", 368 | "homepage": "https://github.com/hackaugusto", 369 | "role": "Developer" 370 | }, 371 | { 372 | "name": "peniar", 373 | "homepage": "https://github.com/peniar", 374 | "role": "Developer" 375 | }, 376 | { 377 | "name": "NSinopoli", 378 | "homepage": "https://github.com/NSinopoli", 379 | "role": "Developer" 380 | }, 381 | { 382 | "name": "DJRanger", 383 | "homepage": "https://github.com/DJRanger", 384 | "role": "Contributor" 385 | }, 386 | { 387 | "name": "fcrosfly", 388 | "homepage": "https://github.com/fcrosfly", 389 | "role": "Contributor" 390 | }, 391 | { 392 | "name": "Soviut", 393 | "homepage": "http://github.com/Soviut", 394 | "role": "Contributor" 395 | }, 396 | { 397 | "name": "just-paja", 398 | "homepage": "http://github.com/just-paja", 399 | "role": "Contributor" 400 | }, 401 | { 402 | "name": "cjonasw", 403 | "homepage": "http://github.com/cjonasw", 404 | "role": "Contributor" 405 | }, 406 | { 407 | "name": "s4msung", 408 | "homepage": "http://github.com/s4msung", 409 | "role": "Contributor" 410 | }, 411 | { 412 | "name": "sadjow", 413 | "homepage": "http://github.com/sadjow", 414 | "role": "Contributor" 415 | }, 416 | { 417 | "name": "hkjels", 418 | "homepage": "http://github.com/hkjels", 419 | "role": "Contributor" 420 | }, 421 | { 422 | "name": "krizalys", 423 | "homepage": "http://github.com/krizalys", 424 | "role": "Contributor" 425 | }, 426 | { 427 | "name": "sszigeti", 428 | "homepage": "http://github.com/sszigeti", 429 | "role": "Contributor" 430 | }, 431 | { 432 | "name": "Konstantin Kudryashov", 433 | "email": "konstantin.kudryashov@knplabs.com", 434 | "homepage": "http://about.me/everzet", 435 | "role": "Developer" 436 | }, 437 | { 438 | "name": "Marco \"Debo\" De Bortoli", 439 | "homepage": "https://github.com/debo", 440 | "role": "contributor" 441 | } 442 | ], 443 | "description": "HAML-like template engine for PHP 5.3", 444 | "homepage": "https://github.com/pug-php/pug", 445 | "keywords": [ 446 | "jade", 447 | "minification", 448 | "pug", 449 | "template" 450 | ], 451 | "time": "2017-01-17T11:40:56+00:00" 452 | }, 453 | { 454 | "name": "yiisoft/yii2", 455 | "version": "2.0.10", 456 | "source": { 457 | "type": "git", 458 | "url": "https://github.com/yiisoft/yii2-framework.git", 459 | "reference": "5bfcb7a6dfa9771e2248eb8c4448613330f343ff" 460 | }, 461 | "dist": { 462 | "type": "zip", 463 | "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/5bfcb7a6dfa9771e2248eb8c4448613330f343ff", 464 | "reference": "5bfcb7a6dfa9771e2248eb8c4448613330f343ff", 465 | "shasum": "" 466 | }, 467 | "require": { 468 | "bower-asset/jquery": "2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", 469 | "bower-asset/jquery.inputmask": "~3.2.2", 470 | "bower-asset/punycode": "1.3.*", 471 | "bower-asset/yii2-pjax": "~2.0.1", 472 | "cebe/markdown": "~1.0.0 | ~1.1.0", 473 | "ext-ctype": "*", 474 | "ext-mbstring": "*", 475 | "ezyang/htmlpurifier": "~4.6", 476 | "lib-pcre": "*", 477 | "php": ">=5.4.0", 478 | "yiisoft/yii2-composer": "~2.0.4" 479 | }, 480 | "bin": [ 481 | "yii" 482 | ], 483 | "type": "library", 484 | "extra": { 485 | "branch-alias": { 486 | "dev-master": "2.0.x-dev" 487 | } 488 | }, 489 | "autoload": { 490 | "psr-4": { 491 | "yii\\": "" 492 | } 493 | }, 494 | "notification-url": "https://packagist.org/downloads/", 495 | "license": [ 496 | "BSD-3-Clause" 497 | ], 498 | "authors": [ 499 | { 500 | "name": "Qiang Xue", 501 | "email": "qiang.xue@gmail.com", 502 | "homepage": "http://www.yiiframework.com/", 503 | "role": "Founder and project lead" 504 | }, 505 | { 506 | "name": "Alexander Makarov", 507 | "email": "sam@rmcreative.ru", 508 | "homepage": "http://rmcreative.ru/", 509 | "role": "Core framework development" 510 | }, 511 | { 512 | "name": "Maurizio Domba", 513 | "homepage": "http://mdomba.info/", 514 | "role": "Core framework development" 515 | }, 516 | { 517 | "name": "Carsten Brandt", 518 | "email": "mail@cebe.cc", 519 | "homepage": "http://cebe.cc/", 520 | "role": "Core framework development" 521 | }, 522 | { 523 | "name": "Timur Ruziev", 524 | "email": "resurtm@gmail.com", 525 | "homepage": "http://resurtm.com/", 526 | "role": "Core framework development" 527 | }, 528 | { 529 | "name": "Paul Klimov", 530 | "email": "klimov.paul@gmail.com", 531 | "role": "Core framework development" 532 | }, 533 | { 534 | "name": "Dmitry Naumenko", 535 | "email": "d.naumenko.a@gmail.com", 536 | "role": "Core framework development" 537 | } 538 | ], 539 | "description": "Yii PHP Framework Version 2", 540 | "homepage": "http://www.yiiframework.com/", 541 | "keywords": [ 542 | "framework", 543 | "yii2" 544 | ], 545 | "time": "2016-10-20T12:02:50+00:00" 546 | }, 547 | { 548 | "name": "yiisoft/yii2-composer", 549 | "version": "2.0.5", 550 | "source": { 551 | "type": "git", 552 | "url": "https://github.com/yiisoft/yii2-composer.git", 553 | "reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2" 554 | }, 555 | "dist": { 556 | "type": "zip", 557 | "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2", 558 | "reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2", 559 | "shasum": "" 560 | }, 561 | "require": { 562 | "composer-plugin-api": "^1.0" 563 | }, 564 | "require-dev": { 565 | "composer/composer": "^1.0" 566 | }, 567 | "type": "composer-plugin", 568 | "extra": { 569 | "class": "yii\\composer\\Plugin", 570 | "branch-alias": { 571 | "dev-master": "2.0.x-dev" 572 | } 573 | }, 574 | "autoload": { 575 | "psr-4": { 576 | "yii\\composer\\": "" 577 | } 578 | }, 579 | "notification-url": "https://packagist.org/downloads/", 580 | "license": [ 581 | "BSD-3-Clause" 582 | ], 583 | "authors": [ 584 | { 585 | "name": "Qiang Xue", 586 | "email": "qiang.xue@gmail.com" 587 | } 588 | ], 589 | "description": "The composer plugin for Yii extension installer", 590 | "keywords": [ 591 | "composer", 592 | "extension installer", 593 | "yii2" 594 | ], 595 | "time": "2016-12-20T13:26:02+00:00" 596 | } 597 | ], 598 | "packages-dev": [], 599 | "aliases": [], 600 | "minimum-stability": "stable", 601 | "stability-flags": [], 602 | "prefer-stable": false, 603 | "prefer-lowest": false, 604 | "platform": { 605 | "php": ">=5.4.0" 606 | }, 607 | "platform-dev": [] 608 | } 609 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | ./ 11 | 12 | ./tests 13 | ./vendor 14 | 15 | 16 | 17 | 18 | 19 | ./tests/unit/renderer 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/unit/.gitignore: -------------------------------------------------------------------------------- 1 | runtime/cache/* -------------------------------------------------------------------------------- /tests/unit/TestCase.php: -------------------------------------------------------------------------------- 1 | mockApplication(); 26 | } 27 | 28 | protected function tearDown() 29 | { 30 | parent::tearDown(); 31 | } 32 | 33 | /** 34 | * Populates Yii::$app with a new application 35 | * The application will be destroyed on tearDown() automatically. 36 | * @param string $appClass 37 | */ 38 | protected function mockApplication($appClass = '\yii\console\Application') 39 | { 40 | // for update self::$params 41 | $this->getParam('id'); 42 | 43 | /** @var \yii\console\Application $app */ 44 | new $appClass(self::$params); 45 | } 46 | 47 | /** 48 | * Destroys application in Yii::$app by setting it to null. 49 | */ 50 | protected function destroyApplication() 51 | { 52 | \Yii::$app = null; 53 | } 54 | 55 | /** 56 | * Returns a test configuration param from /data/config.php 57 | * @param string $name params name 58 | * @param mixed $default default value to use when param is not set. 59 | * @return mixed the value of the configuration param 60 | */ 61 | public function getParam($name, $default = null) 62 | { 63 | if (self::$params === null) { 64 | self::$params = require(__DIR__ . '/config/main.php'); 65 | $main_local = __DIR__ . '/config/main-local.php'; 66 | if (file_exists($main_local)) { 67 | self::$params = ArrayHelper::merge(self::$params, require($main_local)); 68 | } 69 | } 70 | 71 | return isset(self::$params[$name]) ? self::$params[$name] : $default; 72 | } 73 | 74 | /** 75 | * @return \yii\base\View|\yii\web\View 76 | */ 77 | public function getView() 78 | { 79 | return \Yii::$app->view; 80 | } 81 | 82 | /** 83 | * @return \rmrevin\yii\pug\ViewRenderer 84 | */ 85 | public function getPugRenderer() 86 | { 87 | $renderer = \Yii::$app->view->renderers['pug']; 88 | 89 | if (is_array($renderer) || is_string($renderer)) { 90 | $renderer = \Yii::createObject($renderer); 91 | } 92 | 93 | \Yii::$app->view->renderers['pug'] = $renderer; 94 | 95 | return $renderer; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /tests/unit/bootstrap.php: -------------------------------------------------------------------------------- 1 | 'testapp', 11 | 'basePath' => $baseDir, 12 | 'aliases' => [ 13 | '@app' => $baseDir, 14 | '@runtime' => $baseDir . '/runtime', 15 | ], 16 | 'components' => [ 17 | 'view' => [ 18 | 'renderers' => [ 19 | 'pug' => [ 20 | 'class' => 'rmrevin\\yii\\pug\\ViewRenderer', 21 | 'filters' => [ 22 | 'escaped' => 'rmrevin\\yii\\pug\\tests\\unit\\filters\\EscapedFilter' 23 | ], 24 | ], 25 | ], 26 | ], 27 | ], 28 | ]; -------------------------------------------------------------------------------- /tests/unit/filters/EscapedFilter.php: -------------------------------------------------------------------------------- 1 | block->nodes as $line) { 26 | $output[] = $compiler->interpolate($line->value); 27 | } 28 | 29 | return htmlentities(implode("\n", $output)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/unit/renderer/MainTest.php: -------------------------------------------------------------------------------- 1 | getCachePath(); 24 | 25 | FileHelper::removeDirectory($cachePath); 26 | } 27 | 28 | public function testMain() 29 | { 30 | $view = $this->getView(); 31 | 32 | $result = $view->renderFile('@app/views/main.pug'); 33 | 34 | $this->assertEquals($result, '

Hello world

This is a test

'); 35 | 36 | $this->checkAndRemoveCachePath(1); 37 | } 38 | 39 | public function testExtends() 40 | { 41 | $view = $this->getView(); 42 | 43 | $result = $view->renderFile('@app/views/extend.pug'); 44 | 45 | $this->assertEquals($result, '

Hello world

This is a test

this is additional

'); 46 | 47 | $this->checkAndRemoveCachePath(1); 48 | } 49 | 50 | public function testFilters() 51 | { 52 | $view = $this->getView(); 53 | $Pug = $this->getPugRenderer(); 54 | 55 | $Pug->addFilter('strip_tags', function ($node, $compiler) { 56 | $output = []; 57 | 58 | foreach ($node->block->nodes as $line) { 59 | $output[] = $compiler->interpolate($line->value); 60 | } 61 | 62 | return strip_tags(implode("\n", $output)); 63 | }); 64 | 65 | $result = $view->renderFile('@app/views/filters.pug'); 66 | 67 | // print_r($result); 68 | // die(); 69 | 70 | $this->assertEquals($result, "
html string\n
<p>html string</p>
"); 71 | 72 | $this->checkAndRemoveCachePath(1); 73 | } 74 | 75 | protected function checkAndRemoveCachePath($count) 76 | { 77 | $cachePath = $this->getCachePath(); 78 | $files = FileHelper::findFiles($cachePath); 79 | 80 | $this->assertEquals(count($files), $count); 81 | 82 | FileHelper::removeDirectory($cachePath); 83 | } 84 | 85 | protected function getCachePath() 86 | { 87 | $Pug = $this->getPugRenderer(); 88 | 89 | return \Yii::getAlias($Pug->cachePath); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tests/unit/runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !assets -------------------------------------------------------------------------------- /tests/unit/views/extend.pug: -------------------------------------------------------------------------------- 1 | extends main 2 | 3 | block additional 4 | p this is additional 5 | -------------------------------------------------------------------------------- /tests/unit/views/filters.pug: -------------------------------------------------------------------------------- 1 | :css 2 | p { font-size: 1rem; color: black; } 3 | 4 | div 5 | :strip_tags 6 |

html string

7 | 8 | div 9 | :escaped 10 |

html string

11 | -------------------------------------------------------------------------------- /tests/unit/views/main.pug: -------------------------------------------------------------------------------- 1 | variable = "test" 2 | 3 | div.test-block 4 | p Hello world 5 | p This is a #{variable} 6 | block additional 7 | --------------------------------------------------------------------------------