Improvements in html engine (#5788)

* improvements in abapgit_html

* linter fix

* Try to workaround transpiler bug

* exclude uts from transpiler

* new -> create

Co-authored-by: Marc Bernard <59966492+mbtools@users.noreply.github.com>
This commit is contained in:
Alexander Tsybulsky 2022-10-06 23:34:01 +03:00 committed by GitHub
parent cda541692f
commit 3e4e631cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 217 additions and 12 deletions

View File

@ -9,6 +9,9 @@ CLASS zcl_abapgit_html DEFINITION
CONSTANTS c_indent_size TYPE i VALUE 2 ##NO_TEXT.
CLASS-METHODS class_constructor .
CLASS-METHODS create
RETURNING
VALUE(ri_instance) TYPE REF TO zif_abapgit_html.
CLASS-METHODS icon
IMPORTING
!iv_name TYPE string
@ -19,13 +22,16 @@ CLASS zcl_abapgit_html DEFINITION
VALUE(rv_str) TYPE string .
CLASS-METHODS checkbox
IMPORTING
iv_id TYPE string OPTIONAL
iv_checked TYPE abap_bool OPTIONAL
iv_id TYPE string OPTIONAL
iv_checked TYPE abap_bool OPTIONAL
RETURNING
VALUE(rv_html) TYPE string .
PROTECTED SECTION.
PRIVATE SECTION.
ALIASES add FOR zif_abapgit_html~add.
ALIASES wrap FOR zif_abapgit_html~wrap.
TYPES:
BEGIN OF ty_indent_context,
no_indent_jscss TYPE abap_bool,
@ -68,7 +74,7 @@ ENDCLASS.
CLASS zcl_abapgit_html IMPLEMENTATION.
CLASS ZCL_ABAPGIT_HTML IMPLEMENTATION.
METHOD checkbox.
@ -85,6 +91,7 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
ENDIF.
rv_html = rv_html && `/>`.
ENDMETHOD.
@ -94,12 +101,18 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
pattern = '<(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|LINK|META|PARAM|SOURCE|!)'
ignore_case = abap_false.
gv_spaces = repeat( val = ` `
occ = 200 ).
gv_spaces = repeat(
val = ` `
occ = 200 ).
ENDMETHOD.
METHOD create.
CREATE OBJECT ri_instance TYPE zcl_abapgit_html.
ENDMETHOD.
METHOD icon.
DATA: lv_hint TYPE string,
@ -356,6 +369,8 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
ASSERT 1 = 0. " Dev mistake
ENDCASE.
ri_self = me.
ENDMETHOD.
@ -371,6 +386,8 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
iv_style = iv_style
iv_title = iv_title ) ).
ri_self = me.
ENDMETHOD.
@ -380,6 +397,8 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
iv_id = iv_id
iv_checked = iv_checked ) ).
ri_self = me.
ENDMETHOD.
@ -391,6 +410,8 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
iv_hint = iv_hint
iv_onclick = iv_onclick ) ).
ri_self = me.
ENDMETHOD.
@ -432,5 +453,74 @@ CLASS zcl_abapgit_html IMPLEMENTATION.
METHOD zif_abapgit_html~set_title.
zif_abapgit_html~mv_chunk_title = iv_title.
ri_self = me.
ENDMETHOD.
METHOD zif_abapgit_html~td.
wrap(
iv_tag = 'td'
iv_content = iv_content
ii_content = ii_content
iv_id = iv_id
iv_class = iv_class
iv_hint = iv_hint ).
ri_self = me.
ENDMETHOD.
METHOD zif_abapgit_html~th.
wrap(
iv_tag = 'th'
iv_content = iv_content
ii_content = ii_content
iv_id = iv_id
iv_class = iv_class
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: lv_class TYPE string,
lv_id 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.
lv_open_tag = |<{ iv_tag }{ lv_id }{ lv_class }{ 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.
add( lv_open_tag ).
IF ii_content IS BOUND.
add( ii_content ).
ELSEIF iv_content IS NOT INITIAL.
add( iv_content ).
ENDIF.
IF lv_close_tag IS NOT INITIAL.
add( `</` && iv_tag && `>` ).
ENDIF.
ri_self = me.
ENDMETHOD.
ENDCLASS.

View File

@ -1,10 +1,13 @@
CLASS ltcl_html DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA: mo_html TYPE REF TO zif_abapgit_html.
DATA mo_html TYPE REF TO zif_abapgit_html.
METHODS:
wrap FOR TESTING RAISING zcx_abapgit_exception,
td FOR TESTING RAISING zcx_abapgit_exception,
th FOR TESTING RAISING zcx_abapgit_exception,
wrap_ii FOR TESTING RAISING zcx_abapgit_exception,
indent1 FOR TESTING RAISING zcx_abapgit_exception,
indent2 FOR TESTING RAISING zcx_abapgit_exception,
indent3 FOR TESTING RAISING zcx_abapgit_exception,
@ -119,4 +122,69 @@ CLASS ltcl_html IMPLEMENTATION.
ENDMETHOD.
METHOD td.
mo_html->td( 'Hello' ).
cl_abap_unit_assert=>assert_equals(
act = mo_html->render( )
exp =
'<td>' && cl_abap_char_utilities=>newline &&
' Hello' && cl_abap_char_utilities=>newline &&
'</td>' ).
ENDMETHOD.
METHOD th.
mo_html->th( 'Hello' ).
cl_abap_unit_assert=>assert_equals(
act = mo_html->render( )
exp =
'<th>' && cl_abap_char_utilities=>newline &&
' Hello' && cl_abap_char_utilities=>newline &&
'</th>' ).
ENDMETHOD.
METHOD wrap_ii.
mo_html->wrap(
iv_tag = 'td'
ii_content = zcl_abapgit_html=>create( )->add( 'Hello' ) ).
cl_abap_unit_assert=>assert_equals(
act = mo_html->render( )
exp =
'<td>' && cl_abap_char_utilities=>newline &&
' Hello' && cl_abap_char_utilities=>newline &&
'</td>' ).
ENDMETHOD.
METHOD wrap.
mo_html->wrap( iv_tag = 'td' ).
mo_html->wrap(
iv_tag = 'td'
iv_content = 'Hello' ).
mo_html->wrap(
iv_tag = 'td'
iv_class = 'class'
iv_hint = 'hint'
iv_id = 'id'
iv_content = 'Hello' ).
cl_abap_unit_assert=>assert_equals(
act = mo_html->render( )
exp =
'<td></td>' && cl_abap_char_utilities=>newline &&
'<td>' && cl_abap_char_utilities=>newline &&
' Hello' && cl_abap_char_utilities=>newline &&
'</td>' && cl_abap_char_utilities=>newline &&
'<td id="id" class="class" title="hint">' && cl_abap_char_utilities=>newline &&
' Hello' && cl_abap_char_utilities=>newline &&
'</td>' ).
ENDMETHOD.
ENDCLASS.

View File

@ -22,10 +22,14 @@ INTERFACE zif_abapgit_html PUBLIC.
METHODS set_title
IMPORTING
iv_title TYPE string.
iv_title TYPE string
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS add
IMPORTING
!ig_chunk TYPE any .
!ig_chunk TYPE any
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS render
IMPORTING
!iv_no_indent_jscss TYPE abap_bool OPTIONAL
@ -43,11 +47,15 @@ INTERFACE zif_abapgit_html PUBLIC.
!iv_class TYPE string OPTIONAL
!iv_id TYPE string OPTIONAL
!iv_style TYPE string OPTIONAL
!iv_title TYPE string OPTIONAL.
!iv_title TYPE string OPTIONAL
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS add_checkbox
IMPORTING
iv_id TYPE string
iv_checked TYPE abap_bool OPTIONAL.
iv_checked TYPE abap_bool OPTIONAL
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS a
IMPORTING
!iv_txt TYPE string
@ -74,6 +82,41 @@ INTERFACE zif_abapgit_html PUBLIC.
!iv_name TYPE string
!iv_hint TYPE string OPTIONAL
!iv_class TYPE string OPTIONAL
!iv_onclick TYPE string OPTIONAL .
!iv_onclick TYPE string OPTIONAL
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS wrap
IMPORTING
!iv_tag TYPE string
!iv_content TYPE string OPTIONAL
!ii_content TYPE REF TO zif_abapgit_html OPTIONAL
!iv_id TYPE string OPTIONAL
!iv_class TYPE string OPTIONAL
!iv_hint TYPE string OPTIONAL
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS td
IMPORTING
!iv_content TYPE string OPTIONAL
!ii_content TYPE REF TO zif_abapgit_html OPTIONAL
!iv_id TYPE string OPTIONAL
!iv_class TYPE string OPTIONAL
!iv_hint TYPE string OPTIONAL
PREFERRED PARAMETER iv_content
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
METHODS th
IMPORTING
!iv_content TYPE string OPTIONAL
!ii_content TYPE REF TO zif_abapgit_html OPTIONAL
!iv_id TYPE string OPTIONAL
!iv_class TYPE string OPTIONAL
!iv_hint TYPE string OPTIONAL
PREFERRED PARAMETER iv_content
RETURNING
VALUE(ri_self) TYPE REF TO zif_abapgit_html.
ENDINTERFACE.

View File

@ -83,6 +83,10 @@
{"object": "ZCX_ABAPGIT_EXCEPTION", "class": "ltcl_longtext", "method": "multiline_longtext"},
{"object": "ZCL_ABAPGIT_HTML", "class": "ltcl_html", "method": "style1", "note": "indentation is wrong in result, ASSERT failed, ??"},
{"object": "ZCL_ABAPGIT_HTML", "class": "ltcl_html", "method": "wrap"},
{"object": "ZCL_ABAPGIT_HTML", "class": "ltcl_html", "method": "wrap_ii"},
{"object": "ZCL_ABAPGIT_HTML", "class": "ltcl_html", "method": "td"},
{"object": "ZCL_ABAPGIT_HTML", "class": "ltcl_html", "method": "th"},
{"object": "ZCL_ABAPGIT_XML_PRETTY", "class": "ltcl_test", "method": "pretty1", "note": "ASSERT failed, ??, newline missing, offset off by one?"},
{"object": "ZCL_ABAPGIT_XML_PRETTY", "class": "ltcl_test", "method": "pretty2"},
{"object": "ZCL_ABAPGIT_XML_PRETTY", "class": "ltcl_test", "method": "pretty3"},