1<?php
2/**
3 * Mikio Syntax Plugin: TabGroup
4 *
5 * @link        http://github.com/nomadjimbob/mikioplugin
6 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author      James Collins <james.collins@outlook.com.au>
8 */
9
10if (!defined('DOKU_INC')) die();
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(dirname(__FILE__).'/core.php');
13
14class syntax_plugin_mikioplugin_tabgroup extends syntax_plugin_mikioplugin_core {
15    public $tag                 = 'tab-group';
16    public $hasEndTag           = true;
17    public $options             = array(
18        'pills'     => array('type'     => 'boolean',   'default'   => 'false'),
19    );
20
21    public function getAllowedTypes() {  return array(); }
22
23    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
24        $classes = $this->buildClass($data, array('pills'));
25
26        $renderer->doc .= '<ul class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-group' . $classes . '">';
27    }
28
29
30    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
31
32    }
33
34
35    public function render_lexer_unmatched(Doku_Renderer $renderer, $data) {
36        $items = [];
37        $bar = '';
38        $content = '';
39        $first = true;
40
41        $tabOptions = array(
42            'title'     => array('type' => 'text',      'default'   => ''),
43            'disabled'  => array('type' => 'boolean',   'default'   => 'false'),
44        );
45
46        $tabs = $this->findTags($this->tagPrefix . 'tab', $data, $tabOptions);
47
48        foreach($tabs as $tab) {
49            $classes = $this->buildClass($tab['options'], array('disabled'));
50
51            $bar .= '<li class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-item' . $classes . '"><a class="' . $this->elemClass . ($first ? ' mikiop-active' : '') . '" data-toggle="tab" href="#">' . $tab['options']['title'] . '</a></li>';
52            $content .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-pane' . ($first ? ' mikiop-show' : '') . '"><p>' . $tab['content'] . '</p></div>';
53
54            $first = false;
55        }
56
57        $renderer->doc .= $bar . '</ul><div class="' . $this->elemClass . ' ' . $this->classPrefix . 'tab-content">' . $content . '</div>';
58    }
59}
60?>
61