1<?php
2/**
3 * Bootstrap Wrapper Plugin: Nav (Pills & Tabs)
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2020, Giuseppe Di Terlizzi
8 */
9
10class syntax_plugin_bootswrapper_nav extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $p_type         = 'block';
14    public $pattern_start  = '<nav.*?>(?=.*?</nav>)';
15    public $pattern_end    = '</nav>';
16    public $nav_type       = null;
17    public $tag_name       = 'nav';
18    public $tag_attributes = array(
19
20        'type'      => array(
21            'type'     => 'string',
22            'values'   => array('tabs', 'pills'),
23            'required' => true,
24            'default'  => 'pills'),
25
26        'stacked'   => array(
27            'type'     => 'boolean',
28            'values'   => array(0, 1),
29            'required' => false,
30            'default'  => false),
31
32        'justified' => array(
33            'type'     => 'boolean',
34            'values'   => array(0, 1),
35            'required' => false,
36            'default'  => false),
37
38        'fade'      => array(
39            'type'     => 'boolean',
40            'values'   => array(0, 1),
41            'required' => false,
42            'default'  => false),
43
44    );
45
46    public function render($mode, Doku_Renderer $renderer, $data)
47    {
48
49        if (empty($data)) {
50            return false;
51        }
52
53        if ($mode !== 'xhtml') {
54            return false;
55        }
56
57        /** @var Doku_Renderer_xhtml $renderer */
58        list($state, $match, $pos, $attributes) = $data;
59
60        if ($state == DOKU_LEXER_ENTER) {
61            $html5data = array();
62
63            if (!empty($this->nav_type)) {
64                $attributes['type'] = $this->nav_type;
65            }
66
67            foreach ($attributes as $key => $value) {
68                $html5data[] = 'data-nav-' . $key . '="' . $value . '"';
69            }
70
71            $markup = '<div class="bs-wrap bs-wrap-nav" ' . implode(' ', $html5data) . '>';
72
73            $renderer->doc .= $markup;
74            return true;
75        }
76
77        if ($state == DOKU_LEXER_EXIT) {
78            $renderer->doc .= "</div>";
79            return true;
80        }
81
82        return true;
83    }
84}
85