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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 7x 7x 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 1x 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 8x 8x 8x 8x 8x 8x 8x 12x 12x 12x 12x 12x 1x | CLASS zcl_abapgit_gui_css_processor DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. METHODS: constructor IMPORTING ii_asset_manager TYPE REF TO zif_abapgit_gui_asset_manager, add_file IMPORTING iv_url TYPE string, process RETURNING VALUE(rv_result) TYPE string RAISING zcx_abapgit_exception. PROTECTED SECTION. PRIVATE SECTION. TYPES: BEGIN OF ty_css_var, name TYPE string, value TYPE string, END OF ty_css_var, ty_css_vars TYPE SORTED TABLE OF ty_css_var WITH UNIQUE KEY name. METHODS: get_css_vars_in_string IMPORTING iv_string TYPE string RETURNING VALUE(rt_variables) TYPE ty_css_vars, resolve_var_recursively IMPORTING iv_variable_name TYPE string CHANGING ct_variables TYPE ty_css_vars RAISING zcx_abapgit_exception. DATA: mi_asset_manager TYPE REF TO zif_abapgit_gui_asset_manager, mt_files TYPE string_table. ENDCLASS. CLASS ZCL_ABAPGIT_GUI_CSS_PROCESSOR IMPLEMENTATION. METHOD add_file. APPEND iv_url TO mt_files. ENDMETHOD. METHOD constructor. mi_asset_manager = ii_asset_manager. ENDMETHOD. METHOD get_css_vars_in_string. CONSTANTS: lc_root_pattern TYPE string VALUE `:root\s*\{([^\}]*)\}`, lc_variable_pattern TYPE string VALUE `\-\-([\w\d-]+)\s*:\s*([^\n\r;]*);`. DATA: lv_root TYPE string, lo_matcher TYPE REF TO cl_abap_matcher, lo_regex TYPE REF TO cl_abap_regex, ls_variable LIKE LINE OF rt_variables. " Only the :root element may define variables for now FIND FIRST OCCURRENCE OF REGEX lc_root_pattern IN iv_string SUBMATCHES lv_root. IF sy-subrc = 0 AND lv_root IS NOT INITIAL. CREATE OBJECT lo_regex EXPORTING pattern = lc_variable_pattern. lo_matcher = lo_regex->create_matcher( text = lv_root ). WHILE lo_matcher->find_next( ) = abap_true. ls_variable-name = lo_matcher->get_submatch( 1 ). ls_variable-value = lo_matcher->get_submatch( 2 ). INSERT ls_variable INTO TABLE rt_variables. IF sy-subrc <> 0. MODIFY TABLE rt_variables FROM ls_variable. ENDIF. ENDWHILE. ENDIF. ENDMETHOD. METHOD process. DATA: lt_contents TYPE STANDARD TABLE OF string, lv_content TYPE string, lt_css_variables TYPE ty_css_vars, lt_css_vars_in_file TYPE ty_css_vars. FIELD-SYMBOLS: <lv_url> TYPE string, <ls_css_variable> LIKE LINE OF lt_css_vars_in_file, <lv_content> LIKE LINE OF lt_contents. " 1. Determine all variables and their values. Later definitions overwrite previous ones. LOOP AT mt_files ASSIGNING <lv_url>. lv_content = mi_asset_manager->get_text_asset( iv_url = <lv_url> iv_assert_subtype = 'css' ). lt_css_vars_in_file = get_css_vars_in_string( lv_content ). LOOP AT lt_css_vars_in_file ASSIGNING <ls_css_variable>. INSERT <ls_css_variable> INTO TABLE lt_css_variables. IF sy-subrc <> 0. MODIFY TABLE lt_css_variables FROM <ls_css_variable>. ENDIF. ENDLOOP. APPEND lv_content TO lt_contents. ENDLOOP. " 2. Replace all variable usages in variables LOOP AT lt_css_variables ASSIGNING <ls_css_variable> WHERE value CS 'var(--'. resolve_var_recursively( EXPORTING iv_variable_name = <ls_css_variable>-name CHANGING ct_variables = lt_css_variables ). ENDLOOP. " 3. Replace all other variable usages by inlining the values. LOOP AT lt_contents ASSIGNING <lv_content>. LOOP AT lt_css_variables ASSIGNING <ls_css_variable>. REPLACE ALL OCCURRENCES OF |var(--{ <ls_css_variable>-name })| IN <lv_content> WITH <ls_css_variable>-value. ENDLOOP. ENDLOOP. rv_result = concat_lines_of( table = lt_contents sep = cl_abap_char_utilities=>newline ). ENDMETHOD. METHOD resolve_var_recursively. CONSTANTS: lc_variable_usage_pattern TYPE string VALUE `var\(\-\-([^\)]*)\)`. DATA: lv_variable_name TYPE string. FIELD-SYMBOLS: <ls_variable> LIKE LINE OF ct_variables, <ls_other_variable> LIKE LINE OF ct_variables. READ TABLE ct_variables WITH TABLE KEY name = iv_variable_name ASSIGNING <ls_variable>. IF sy-subrc = 0. DO. FIND FIRST OCCURRENCE OF REGEX lc_variable_usage_pattern IN <ls_variable>-value SUBMATCHES lv_variable_name. IF sy-subrc = 0. resolve_var_recursively( EXPORTING iv_variable_name = lv_variable_name CHANGING ct_variables = ct_variables ). READ TABLE ct_variables WITH TABLE KEY name = lv_variable_name ASSIGNING <ls_other_variable>. REPLACE FIRST OCCURRENCE OF |var(--{ lv_variable_name })| IN <ls_variable>-value WITH <ls_other_variable>-value. ELSE. EXIT. ENDIF. ENDDO. ELSE. zcx_abapgit_exception=>raise( |CSS variable { iv_variable_name } not resolvable| ). ENDIF. ENDMETHOD. ENDCLASS. |