Skip to content

Commit

Permalink
pug instance options depends by WP_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
ramensoup committed Jan 25, 2018
1 parent 5825e05 commit 858acad
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/all_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ function __construct() {
$this->addFile('theme_helper_test.php');
$this->addFile('url_helper_test.php');
$this->addFile('number_helper_test.php');
$this->addFile('render_helper_test.php');
}
}
34 changes: 34 additions & 0 deletions tests/render_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,38 @@ function test_render_template_pug_with_locals() {
);
}

function test_pug_instance_options_with_wp_debug_false() {
ob_start();

$this->assertEqual(
array(
'pretty' => true,
'expressionLanguage' => 'php',
'extension' => '.pug',
'cache' => Wordless::theme_temp_path(),
'strict' => true,
'debug' => false,
'enable_profiler' => false
),
WordlessPugOptions::get_options()
);
}

function test_pug_instance_options_with_wp_debug_true() {
define('WP_DEBUG', true);

$this->assertEqual(
array(
'pretty' => true,
'expressionLanguage' => 'php',
'extension' => '.pug',
'cache' => Wordless::theme_temp_path(),
'strict' => true,
'debug' => true,
'enable_profiler' => true
),
WordlessPugOptions::get_options()
);
}

}
16 changes: 16 additions & 0 deletions wordless/helpers/pug/wordless_pug_options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class WordlessPugOptions {
public static function get_options() {
$wp_debug = defined('WP_DEBUG') ? WP_DEBUG : false;
return array(
'pretty' => true,
'expressionLanguage' => 'php',
'extension' => '.pug',
'cache' => Wordless::theme_temp_path(),
'strict' => true,
'debug' => $wp_debug,
'enable_profiler' => $wp_debug
);
}
}
10 changes: 3 additions & 7 deletions wordless/helpers/render_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ function render_template($name, $locals = array()) {
break;

case 'pug':
require_once('pug/wordless_pug_options.php');

if ($this->ensure_dir($tmp_dir)) {
$pug = new Pug(array(
'pretty' => true,
'expressionLanguage' => 'php',
'extension' => '.pug',
'cache' => $tmp_dir,
'strict' => true
));
$pug = new Pug(WordlessPugOptions::get_options());

$pug->displayFile($template_path, $locals);
} else {
Expand Down

0 comments on commit 858acad

Please sign in to comment.