1<?php 2/** 3 * Bootstrap Wrapper Plugin: Column 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_column extends syntax_plugin_bootswrapper_bootstrap 11{ 12 13 public $p_type = 'block'; 14 public $pattern_start = '<col\b.*?>(?=.*?</col>)'; 15 public $pattern_end = '</col>'; 16 public $tag_name = 'col'; 17 public $tag_attributes = array( 18 19 'lg' => array( 20 'type' => 'integer', 21 'values' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 22 'min' => 1, 23 'max' => 12, 24 'required' => false, 25 'default' => null), 26 27 'md' => array( 28 'type' => 'integer', 29 'values' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 30 'min' => 1, 31 'max' => 12, 32 'required' => false, 33 'default' => null), 34 35 'sm' => array( 36 'type' => 'integer', 37 'values' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 38 'min' => 1, 39 'max' => 12, 40 'required' => false, 41 'default' => null), 42 43 'xs' => array( 44 'type' => 'integer', 45 'values' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 46 'min' => 1, 47 'max' => 12, 48 'required' => false, 49 'default' => null), 50 51 ); 52 53 public function render($mode, Doku_Renderer $renderer, $data) 54 { 55 56 if (empty($data)) { 57 return false; 58 } 59 60 if ($mode !== 'xhtml') { 61 return false; 62 } 63 64 /** @var Doku_Renderer_xhtml $renderer */ 65 list($state, $match, $pos, $attributes) = $data; 66 67 if ($state == DOKU_LEXER_ENTER) { 68 $col = ''; 69 70 foreach (array('lg', 'md', 'sm', 'xs') as $device) { 71 $col .= isset($attributes[$device]) ? "col-$device-{$attributes[$device]} " : ''; 72 } 73 74 $markup = '<div class="bs-wrap bs-wrap-col ' . trim($col) . '">'; 75 76 $renderer->doc .= $markup; 77 return true; 78 } 79 80 if ($state == DOKU_LEXER_UNMATCHED) { 81 $renderer->doc .= $match; 82 return true; 83 84 } 85 86 if ($state == DOKU_LEXER_EXIT) { 87 $renderer->doc .= "</div>"; 88 return true; 89 } 90 91 return true; 92 } 93} 94