All files / src/ui/core zcl_abapgit_html.clas.abap

92.22% Statements 569/617
58.46% Branches 38/65
100% Functions 1/1
92.22% Lines 569/617

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 6181x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x     1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x     523x     523x     523x 523x 523x 523x 523x 523x 523x 63x 63x 63x 63x     63x 460x 460x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 523x 426x 363x 426x 63x 63x 426x 426x 226x 226x 200x 200x 426x 523x 523x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x   5x 1x 1x 5x 5x 5x 1x 1x 5x 5x 5x 5x 5x 5x 518x           518x 1x 1x 1x 1x 1x 518x 61x 61x 518x 518x 518x 518x 439x 439x 439x 518x 518x 518x 1x 1x 1x   1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x     1x     1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 35x 35x 8x 8x 2x 8x 4x 4x 8x 6x 6x 8x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_html DEFINITION
  PUBLIC
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    INTERFACES zif_abapgit_html .
 
    CONSTANTS c_indent_size TYPE i VALUE 2 ##NO_TEXT.
 
    CLASS-METHODS class_constructor .
    CLASS-METHODS create
      IMPORTING
        !iv_initial_chunk  TYPE any OPTIONAL
      RETURNING
        VALUE(ri_instance) TYPE REF TO zif_abapgit_html.
 
    CLASS-METHODS icon
      IMPORTING
        !iv_name      TYPE string
        !iv_hint      TYPE string OPTIONAL
        !iv_class     TYPE string OPTIONAL
        !iv_onclick   TYPE string OPTIONAL
      RETURNING
        VALUE(rv_str) TYPE string .
    CLASS-METHODS checkbox
      IMPORTING
        iv_id          TYPE string OPTIONAL
        iv_checked     TYPE abap_bool OPTIONAL
      RETURNING
        VALUE(rv_html) TYPE string .
    CLASS-METHODS parse_data_attr
      IMPORTING
        iv_str              TYPE string OPTIONAL
      RETURNING
        VALUE(rs_data_attr) TYPE zif_abapgit_html=>ty_data_attr .
    CLASS-METHODS set_debug_mode
      IMPORTING
        iv_mode TYPE abap_bool.
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    CONSTANTS c_max_indent TYPE i VALUE 200.
 
    TYPES:
      BEGIN OF ty_indent_context,
        no_indent_jscss TYPE abap_bool,
        within_style    TYPE abap_bool,
        within_js       TYPE abap_bool,
        within_textarea TYPE abap_bool,
        indent          TYPE i,
        indent_str      TYPE string,
      END OF ty_indent_context .
    TYPES:
      BEGIN OF ty_study_result,
        style_open     TYPE abap_bool,
        style_close    TYPE abap_bool,
        script_open    TYPE abap_bool,
        script_close   TYPE abap_bool,
        textarea_open  TYPE abap_bool,
        textarea_close TYPE abap_bool,
        tag_close      TYPE abap_bool,
        curly_close    TYPE abap_bool,
        openings       TYPE i,
        closings       TYPE i,
        singles        TYPE i,
      END OF ty_study_result .
 
    CLASS-DATA go_single_tags_re TYPE REF TO cl_abap_regex .
    DATA mt_buffer TYPE string_table .
    CLASS-DATA gv_spaces TYPE string .
    CLASS-DATA gv_debug_mode TYPE abap_bool .
 
    METHODS indent_line
      CHANGING
        !cs_context TYPE ty_indent_context
        !cv_line    TYPE string .
    METHODS study_line
      IMPORTING
        !iv_line         TYPE string
        !is_context      TYPE ty_indent_context
      RETURNING
        VALUE(rs_result) TYPE ty_study_result .
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_HTML IMPLEMENTATION.
 
 
  METHOD checkbox.
 
    DATA: lv_checked TYPE string.
 
    IF iv_checked = abap_true.
      lv_checked = |checked|.
    ENDIF.
 
    rv_html = |<input type="checkbox" { lv_checked } |.
    IF iv_id IS NOT INITIAL.
      rv_html = rv_html && |id="{ iv_id }"|.
    ENDIF.
 
    rv_html = rv_html && `/>`.
 
  ENDMETHOD.
 
 
  METHOD class_constructor.
 
    CREATE OBJECT go_single_tags_re
      EXPORTING
        pattern     = '<(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|LINK|META|PARAM|SOURCE|!)'
        ignore_case = abap_false.
 
    gv_spaces = repeat(
      val = ` `
      occ = c_max_indent ).
 
  ENDMETHOD.
 
 
  METHOD set_debug_mode.
    gv_debug_mode = iv_mode.
  ENDMETHOD.
 
  METHOD create.
    CREATE OBJECT ri_instance TYPE zcl_abapgit_html.
    IF iv_initial_chunk IS NOT INITIAL.
      ri_instance->add( iv_initial_chunk ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD icon.
 
    DATA: lv_hint       TYPE string,
          lv_name       TYPE string,
          lv_color      TYPE string,
          lv_class      TYPE string,
          lv_onclick    TYPE string.
 
    SPLIT iv_name AT '/' INTO lv_name lv_color.
 
    IF iv_hint IS NOT INITIAL.
      lv_hint  = | title="{ iv_hint }"|.
    ENDIF.
    IF iv_onclick IS NOT INITIAL.
      lv_onclick = | onclick="{ iv_onclick }"|.
    ENDIF.
    IF iv_class IS NOT INITIAL.
      lv_class = | { iv_class }|.
    ENDIF.
    IF lv_color IS NOT INITIAL.
      lv_color = | { lv_color }|.
    ENDIF.
 
    rv_str = |<i class="icon icon-{ lv_name }{ lv_color }|.
    rv_str = |{ rv_str }{ lv_class }"{ lv_onclick }{ lv_hint }></i>|.
 
  ENDMETHOD.
 
 
  METHOD indent_line.
 
    DATA: ls_study  TYPE ty_study_result,
          lv_spaces TYPE i.
 
    ls_study = study_line(
      is_context = cs_context
      iv_line    = cv_line ).
 
    " No indent for textarea tags
    IF ls_study-textarea_open = abap_true.
      cs_context-within_textarea = abap_true.
      RETURN.
    ELSEIF ls_study-textarea_close = abap_true.
      cs_context-within_textarea = abap_false.
      RETURN.
    ELSEIF cs_context-within_textarea = abap_true.
      RETURN.
    ENDIF.
 
    " First closing tag - shift back exceptionally
    IF ( ls_study-script_close = abap_true
        OR ls_study-style_close = abap_true
        OR ls_study-curly_close = abap_true
        OR ls_study-tag_close = abap_true )
        AND cs_context-indent > 0.
      lv_spaces = ( cs_context-indent - 1 ) * c_indent_size.
      IF lv_spaces <= c_max_indent.
        cv_line  = gv_spaces(lv_spaces) && cv_line.
      ELSE.
        cv_line = gv_spaces && cv_line.
      ENDIF.
    ELSE.
      cv_line = cs_context-indent_str && cv_line.
    ENDIF.
 
    " Context status update
    CASE abap_true.
      WHEN ls_study-script_open.
        cs_context-within_js    = abap_true.
        cs_context-within_style = abap_false.
      WHEN ls_study-style_open.
        cs_context-within_js    = abap_false.
        cs_context-within_style = abap_true.
      WHEN ls_study-script_close OR ls_study-style_close.
        cs_context-within_js    = abap_false.
        cs_context-within_style = abap_false.
        ls_study-closings       = ls_study-closings + 1.
    ENDCASE.
 
    " More-less logic chosen due to possible double tags in a line '<a><b>'
    IF ls_study-openings <> ls_study-closings.
      IF ls_study-openings > ls_study-closings.
        cs_context-indent = cs_context-indent + 1.
      ELSEIF cs_context-indent > 0. " AND ls_study-openings < ls_study-closings
        cs_context-indent = cs_context-indent - 1.
      ENDIF.
      lv_spaces = cs_context-indent * c_indent_size.
      IF lv_spaces <= c_max_indent.
        cs_context-indent_str = gv_spaces(lv_spaces).
      ELSE.
        cv_line = gv_spaces && cv_line.
      ENDIF.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD parse_data_attr.
 
    SPLIT iv_str AT '=' INTO rs_data_attr-name rs_data_attr-value.
    IF rs_data_attr-name IS INITIAL.
      CLEAR rs_data_attr.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD study_line.
 
    DATA: lv_line TYPE string,
          lv_len  TYPE i.
 
    lv_line = to_upper( shift_left( val = iv_line
                                    sub = ` ` ) ).
    lv_len  = strlen( lv_line ).
 
    " Some assumptions for simplification and speed
    " - style & scripts tag should be opened/closed in a separate line
    " - style & scripts opening and closing in one line is possible but only once
 
    " TODO & Issues
    " - What if the string IS a well formed html already not just single line ?
 
    IF is_context-within_js = abap_true OR is_context-within_style = abap_true.
 
      IF is_context-within_js = abap_true AND lv_len >= 8 AND lv_line(8) = '</SCRIPT'.
        rs_result-script_close = abap_true.
      ELSEIF is_context-within_style = abap_true AND lv_len >= 7 AND lv_line(7) = '</STYLE'.
        rs_result-style_close = abap_true.
      ENDIF.
 
      IF is_context-no_indent_jscss = abap_false.
        IF lv_len >= 1 AND lv_line(1) = '}'.
          rs_result-curly_close = abap_true.
        ENDIF.
 
        FIND ALL OCCURRENCES OF '{' IN lv_line MATCH COUNT rs_result-openings.
        FIND ALL OCCURRENCES OF '}' IN lv_line MATCH COUNT rs_result-closings.
      ENDIF.
 
    ELSE.
      IF lv_len >= 7 AND lv_line(7) = '<SCRIPT'.
        FIND FIRST OCCURRENCE OF '</SCRIPT' IN lv_line.
        IF sy-subrc > 0. " Not found
          rs_result-script_open = abap_true.
        ENDIF.
      ENDIF.
      IF lv_len >= 6 AND lv_line(6) = '<STYLE'.
        FIND FIRST OCCURRENCE OF '</STYLE' IN lv_line.
        IF sy-subrc > 0. " Not found
          rs_result-style_open = abap_true.
        ENDIF.
      ENDIF.
      IF lv_len >= 2 AND lv_line(2) = '</'.
        rs_result-tag_close = abap_true.
      ENDIF.
 
      FIND ALL OCCURRENCES OF '<'  IN lv_line MATCH COUNT rs_result-openings.
      FIND ALL OCCURRENCES OF '</' IN lv_line MATCH COUNT rs_result-closings.
      IF rs_result-closings <> rs_result-openings.
* if everything is closings, there are no single tags
        FIND ALL OCCURRENCES OF REGEX go_single_tags_re IN lv_line MATCH COUNT rs_result-singles.
      ENDIF.
      rs_result-openings = rs_result-openings - rs_result-closings - rs_result-singles.
 
    ENDIF.
 
    " Textarea (same assumptions as above)
    IF is_context-within_textarea = abap_true AND lv_len >= 10 AND lv_line(10) = '</TEXTAREA'.
      rs_result-textarea_close = abap_true.
    ELSEIF is_context-within_textarea = abap_false AND lv_len >= 9 AND lv_line(9) = '<TEXTAREA'.
      FIND FIRST OCCURRENCE OF '</TEXTAREA' IN lv_line.
      IF sy-subrc > 0. " Not found
        rs_result-textarea_open = abap_true.
      ENDIF.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~a.
 
    DATA: lv_class TYPE string,
          lv_href  TYPE string,
          lv_click TYPE string,
          lv_id    TYPE string,
          lv_act   TYPE string,
          lv_style TYPE string,
          lv_title TYPE string.
 
    lv_class = iv_class.
 
    IF iv_opt CA zif_abapgit_html=>c_html_opt-strong.
      lv_class = lv_class && ' emphasis'.
    ENDIF.
    IF iv_opt CA zif_abapgit_html=>c_html_opt-cancel.
      lv_class = lv_class && ' attention'.
    ENDIF.
    IF iv_opt CA zif_abapgit_html=>c_html_opt-crossout.
      lv_class = lv_class && ' crossout grey'.
    ENDIF.
    IF lv_class IS NOT INITIAL.
      SHIFT lv_class LEFT DELETING LEADING space.
      lv_class = | class="{ lv_class }"|.
    ENDIF.
 
    lv_href = ' href="#"'. " Default, dummy
    lv_act  = iv_act.
    IF ( iv_act IS NOT INITIAL OR iv_typ = zif_abapgit_html=>c_action_type-dummy )
        AND iv_opt NA zif_abapgit_html=>c_html_opt-crossout.
      CASE iv_typ.
        WHEN zif_abapgit_html=>c_action_type-url.
          IF iv_query IS NOT INITIAL.
            lv_act = lv_act && `?` && iv_query.
          ENDIF.
          lv_href  = | href="{ lv_act }"|.
        WHEN zif_abapgit_html=>c_action_type-sapevent.
          IF iv_query IS NOT INITIAL.
            lv_act = lv_act && `?` && iv_query.
          ENDIF.
          lv_href  = | href="sapevent:{ lv_act }"|.
        WHEN zif_abapgit_html=>c_action_type-onclick.
          lv_href  = ' href="#"'.
          lv_click = | onclick="{ iv_act }"|.
        WHEN zif_abapgit_html=>c_action_type-dummy.
          lv_href  = ' href="#"'.
      ENDCASE.
    ENDIF.
 
    IF iv_id IS NOT INITIAL.
      lv_id = | id="{ iv_id }"|.
    ENDIF.
 
    IF iv_style IS NOT INITIAL.
      lv_style = | style="{ iv_style }"|.
    ENDIF.
 
    IF iv_title IS NOT INITIAL.
      lv_title = | title="{ iv_title }"|.
    ENDIF.
 
    " Debug option to display href-link on hover
    IF gv_debug_mode = abap_true.
      lv_title = | title="{ escape(
        val    = lv_href
        format = cl_abap_format=>e_html_attr ) }"|.
    ENDIF.
 
    rv_str = |<a{ lv_id }{ lv_class }{ lv_href }{ lv_click }{ lv_style }{ lv_title }>|
          && |{ iv_txt }</a>|.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~add.
 
    DATA: lv_type       TYPE c,
          li_renderable TYPE REF TO zif_abapgit_gui_renderable,
          lx_error      TYPE REF TO zcx_abapgit_exception,
          lo_html       TYPE REF TO zcl_abapgit_html.
 
    FIELD-SYMBOLS: <lt_tab> TYPE string_table.
 
    lv_type = cl_abap_typedescr=>describe_by_data( ig_chunk )->type_kind.
 
    CASE lv_type.
      WHEN 'C' OR 'g'.  " Char or string
        APPEND ig_chunk TO mt_buffer.
      WHEN 'h'.         " Table
        ASSIGN ig_chunk TO <lt_tab>. " Assuming table of strings ! Will dump otherwise
        APPEND LINES OF <lt_tab> TO mt_buffer.
      WHEN 'r'.         " Object ref
        ASSERT ig_chunk IS BOUND. " Dev mistake
        TRY.
            lo_html ?= ig_chunk.
          CATCH cx_sy_move_cast_error.
            TRY.
                li_renderable ?= ig_chunk.
                lo_html ?= li_renderable->render( ).
              CATCH cx_sy_move_cast_error.
                ASSERT 1 = 0. " Dev mistake
              CATCH zcx_abapgit_exception INTO lx_error.
                lo_html ?= create( |<span class="error">Render error: { lx_error->get_text( ) }</span>| ).
            ENDTRY.
        ENDTRY.
        APPEND LINES OF lo_html->mt_buffer TO mt_buffer.
      WHEN OTHERS.
        ASSERT 1 = 0. " Dev mistake
    ENDCASE.
 
    ri_self = me.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~add_a.
 
    zif_abapgit_html~add( zif_abapgit_html~a(
      iv_txt   = iv_txt
      iv_act   = iv_act
      iv_query = iv_query
      iv_typ   = iv_typ
      iv_opt   = iv_opt
      iv_class = iv_class
      iv_id    = iv_id
      iv_style = iv_style
      iv_title = iv_title ) ).
 
    ri_self = me.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~add_checkbox.
 
    zif_abapgit_html~add( checkbox(
      iv_id      = iv_id
      iv_checked = iv_checked ) ).
 
    ri_self = me.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~add_icon.
 
    zif_abapgit_html~add( icon(
      iv_name    = iv_name
      iv_class   = iv_class
      iv_hint    = iv_hint
      iv_onclick = iv_onclick ) ).
 
    ri_self = me.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~div.
    zif_abapgit_html~wrap(
      iv_tag   = 'div'
      iv_content = iv_content
      ii_content = ii_content
      is_data_attr  = is_data_attr
      it_data_attrs = it_data_attrs
      iv_id    = iv_id
      iv_class = iv_class ).
    ri_self = me.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~icon.
 
    rv_str = icon(
      iv_name    = iv_name
      iv_hint    = iv_hint
      iv_class   = iv_class
      iv_onclick = iv_onclick ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~is_empty.
    rv_yes = boolc( lines( mt_buffer ) = 0 ).
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~render.
 
    DATA: ls_context TYPE ty_indent_context,
          lt_temp    TYPE string_table.
 
    FIELD-SYMBOLS: <lv_line>   LIKE LINE OF lt_temp,
                   <lv_line_c> LIKE LINE OF lt_temp.
 
    IF iv_no_line_breaks = abap_true.
      CONCATENATE LINES OF mt_buffer INTO rv_html.
    ELSE.
      ls_context-no_indent_jscss = iv_no_indent_jscss.
 
      LOOP AT mt_buffer ASSIGNING <lv_line>.
        APPEND <lv_line> TO lt_temp ASSIGNING <lv_line_c>.
        indent_line( CHANGING cs_context = ls_context cv_line = <lv_line_c> ).
      ENDLOOP.
 
      CONCATENATE LINES OF lt_temp INTO rv_html SEPARATED BY cl_abap_char_utilities=>newline.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~set_title.
    zif_abapgit_html~mv_chunk_title = iv_title.
    ri_self = me.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~td.
    zif_abapgit_html~wrap(
      iv_format_single_line = iv_format_single_line
      iv_tag   = 'td'
      iv_content = iv_content
      ii_content = ii_content
      iv_id    = iv_id
      iv_class = iv_class
      is_data_attr  = is_data_attr
      it_data_attrs = it_data_attrs
      iv_hint  = iv_hint ).
    ri_self = me.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~th.
    zif_abapgit_html~wrap(
      iv_format_single_line = iv_format_single_line
      iv_tag   = 'th'
      iv_content = iv_content
      ii_content = ii_content
      iv_id    = iv_id
      iv_class = iv_class
      is_data_attr  = is_data_attr
      it_data_attrs = it_data_attrs
      iv_hint  = iv_hint ).
    ri_self = me.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html~wrap.
 
    DATA lv_open_tag TYPE string.
    DATA lv_close_tag TYPE string.
    DATA ls_data_attr LIKE LINE OF it_data_attrs.
 
    DATA: lv_class TYPE string,
          lv_id    TYPE string,
          lv_data_attr TYPE string,
          lv_title TYPE string.
 
    IF iv_id IS NOT INITIAL.
      lv_id = | id="{ iv_id }"|.
    ENDIF.
 
    IF iv_class IS NOT INITIAL.
      lv_class = | class="{ iv_class }"|.
    ENDIF.
 
    IF iv_hint IS NOT INITIAL.
      lv_title = | title="{ iv_hint }"|.
    ENDIF.
 
    IF is_data_attr IS NOT INITIAL.
      lv_data_attr = | data-{ is_data_attr-name }="{ is_data_attr-value }"|.
    ENDIF.
 
    LOOP AT it_data_attrs INTO ls_data_attr.
      lv_data_attr = lv_data_attr && | data-{ ls_data_attr-name }="{ ls_data_attr-value }"|.
    ENDLOOP.
 
    lv_open_tag = |<{ iv_tag }{ lv_id }{ lv_class }{ lv_data_attr }{ lv_title }>|.
    lv_close_tag = |</{ iv_tag }>|.
 
    IF ii_content IS NOT BOUND AND iv_content IS INITIAL.
      lv_open_tag = lv_open_tag && lv_close_tag.
      CLEAR lv_close_tag.
    ENDIF.
 
    IF iv_format_single_line = abap_true AND iv_content IS NOT INITIAL.
      zif_abapgit_html~add( lv_open_tag && iv_content && lv_close_tag ).
    ELSE.
      zif_abapgit_html~add( lv_open_tag ).
      IF ii_content IS BOUND.
        zif_abapgit_html~add( ii_content ).
      ELSEIF iv_content IS NOT INITIAL.
        zif_abapgit_html~add( iv_content ).
      ENDIF.
      IF lv_close_tag IS NOT INITIAL.
        zif_abapgit_html~add( lv_close_tag ).
      ENDIF.
    ENDIF.
 
    ri_self = me.
 
  ENDMETHOD.
ENDCLASS.