Completed
Push — feature-markdown ( c8929c...6d3c30 )
by Cees-Jan
02:53
created

TwigTemplateTask::bake()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 10
cts 12
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 4
nop 2
crap 3.0416
1
<?php
2
3
/**
4
 * This file is part of TwigView.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Shell\Task;
12
13
use Bake\Shell\Task\TemplateTask;
14
use Cake\Console\Shell;
15
use Cake\Core\Configure;
16
use Cake\Utility\Inflector;
17
18
/**
19
 * Task class for creating and updating twig view template files.
20
 *
21
 */
22
class TwigTemplateTask extends TemplateTask
23
{
24
25
    public function name()
26
    {
27
        return 'twig_template';
28
    }
29
30
    /**
31
     * Assembles and writes bakes the twig view file.
32
     *
33
     * @param string $action Action to bake.
34
     * @param string $content Content to write.
35
     * @return string Generated file content.
36
     */
37 4
    public function bake($action, $content = '')
38
    {
39 4
        if ($content === true) {
40 4
            $content = $this->getContent($action);
41 4
        }
42 4
        if (empty($content)) {
43
            $this->err("<warning>No generated content for '{$action}.ctp', not generating template.</warning>");
44
45
            return false;
46
        }
47 4
        $this->out("\n" . sprintf('Baking `%s` view twig template file...', $action), 1, Shell::QUIET);
48 4
        $path = $this->getPath();
49 4
        $filename = $path . Inflector::underscore($action) . '.twig';
50 4
        $this->createFile($filename, $content);
51
52 4
        return $content;
53
    }
54
}
55