DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:section_editor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
devel:section_editor [2015-05-27 13:59] 130.112.1.3devel:section_editor [2018-04-06 21:42] (current) – Update for upcoming release "Greebo" LarsDW223
Line 7: Line 7:
 The XHTML renderer provides two methods for the DIV section edit marking: The XHTML renderer provides two methods for the DIV section edit marking:
  
-  * [[xref>startSectionEdit()|startSectionEdit($bytepos_start, $section_type, $section_title = null)]] \\ Returns a classname and save the position. +  * [[xref>startSectionEdit()|startSectionEdit($start, $data)]] \\ Returns a classname and save the position. 
-  * [[xref>finishSectionEdit()|finishSectionEdit($bytepos_end = null)]] \\ Places a marker with data about this editable section.+  * [[xref>finishSectionEdit()|finishSectionEdit($end = null, $hid = null)]] \\ Places a marker with data about this editable section.
  
 These are used to create markers in the xhtml output of the renderer and after the render is done, a replacement or remove of the markers by [[xref>html_secedit|html_secedit($text,$show=true)]] is executed. These are used to create markers in the xhtml output of the renderer and after the render is done, a replacement or remove of the markers by [[xref>html_secedit|html_secedit($text,$show=true)]] is executed.
  
 Note that ''finishSectionEdit()'' assumes correctly nested edit sections. To use this methods, you will need to save your byte positions in your ''handle()'' method of your syntax plugin. Note that ''finishSectionEdit()'' assumes correctly nested edit sections. To use this methods, you will need to save your byte positions in your ''handle()'' method of your syntax plugin.
 +
 +Before DokuWiki release "Greebo" the method signatures were different:
 +
 +  * startSectionEdit($bytepos_start, $section_type, $section_title = null)
 +  * finishSectionEdit($bytepos_end = null)
 +
 +But do not worry. You can easily write backwards compatible code by checking the definition of ''SEC_EDIT_PATTERN'' as done in the example code below.
  
 A step-by-step example for a syntax plugin: A step-by-step example for a syntax plugin:
Line 22: Line 29:
         // sufficiently new         // sufficiently new
         if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) {         if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) {
-            // FIXME: Insert plugin name here as section type +            // Prepare section edit data in a backwards compatible way. 
-            // If this section has a distinguishable name, you may add it to +            // FIXME: Insert plugin name here as 'target' (previously section type) 
-            // the method call as well+            $sectionEditData = ['target' => 'plugin_exampleplugin']; 
 +            if (!defined('SEC_EDIT_PATTERN')) { 
 +                // backwards-compatibility for Frusterick Manners (2017-02-19) 
 +                $sectionEditData = 'plugin_exampleplugin'; 
 +            } 
             /* @var Doku_Renderer_xhtml $renderer */             /* @var Doku_Renderer_xhtml $renderer */
             $class = $renderer->startSectionEdit($data['bytepos_start'],             $class = $renderer->startSectionEdit($data['bytepos_start'],
-                                                 'plugin_exampleplugin');+                                                 $sectionEditData); 
 +        } 
 +        $renderer->doc .= '<div class="' . $class . '">'; 
 + 
 +        // FIXME: Put your content here 
 + 
 +        $renderer->doc .= '</div>'; 
 +        // Add section edit infos only in XHTML renderers which are 
 +        // sufficiently new 
 +        if ($format === 'xhtml' && 
 +            method_exists($renderer, 'finishSectionEdit')) { 
 +            /* @var Doku_Renderer_xhtml $renderer */ 
 +            $renderer->finishSectionEdit($data['bytepos_end']); 
 +        } 
 +    } 
 +</file> 
 + 
 +If the section of your plugin has a distinguishable name, you may add it to the method call as well. In this case the old and new method signatures are to different to achieve backwards compatibility by just assigning different values to ''$sectionEditData''. It requires two different method calls: 
 + 
 +<file php syntax.php> 
 +    public function render($format, Doku_Renderer $renderer, $data) { 
 +        $class = ''; 
 +        // Add section edit infos only in XHTML renderers which are 
 +        // sufficiently new 
 +        if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) { 
 +            // Call 'startSectionEdit' in two different ways... 
 +            if (defined('SEC_EDIT_PATTERN')) { 
 +                // FIXME: Insert plugin name here as 'target' 
 +                // and section name as 'name' 
 +                $sectionEditData = ['target' => 'plugin_exampleplugin', 
 +                                    'name' => 'section-name']; 
 + 
 +                /* @var Doku_Renderer_xhtml $renderer */ 
 +                $class = $renderer->startSectionEdit($data['bytepos_start'], 
 +                                                     $sectionEditData); 
 +            } else { 
 +                // backwards-compatibility for Frusterick Manners (2017-02-19) 
 +                // FIXME: Insert plugin name here as section type 
 +                // and section name as title 
 +                /* @var Doku_Renderer_xhtml $renderer */ 
 +                $class = $renderer->startSectionEdit($data['bytepos_start'], 
 +                             'plugin_exampleplugin', 'section-name'); 
 +            }
         }         }
         $renderer->doc .= '<div class="' . $class . '">';         $renderer->doc .= '<div class="' . $class . '">';
devel/section_editor.txt · Last modified: 2018-04-06 21:42 by LarsDW223

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki