All files / output zcl_abapgit_gui_html_processor.clas.mjs

99.36% Statements 157/158
70.27% Branches 26/37
38.46% Functions 10/26
99.36% Lines 157/158

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 1581x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 5x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 3x 3x 3x 4x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 6x 3x 3x 4x 2x 2x 2x 3x 4x 5x 1x 1x 1x 1x 1x 5x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 2x 5x 5x 5x 2x 2x 2x 3x 4x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x   1x 4x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x
const {cx_root} = await import("./cx_root.clas.mjs");
// zcl_abapgit_gui_html_processor.clas.abap
class zcl_abapgit_gui_html_processor {
  static INTERNAL_TYPE = 'CLAS';
  static INTERNAL_NAME = 'ZCL_ABAPGIT_GUI_HTML_PROCESSOR';
  static IMPLEMENTED_INTERFACES = ["ZIF_ABAPGIT_GUI_HTML_PROCESSOR"];
  static ATTRIBUTES = {"MT_PRESERVE_CSS": {"type": () => {return abap.types.TableFactory.construct(new abap.types.String({qualifiedName: "STRING"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"isUnique":false,"type":"STANDARD","keyFields":[],"name":"primary_key"},"secondary":[]}, "STRING_TABLE");}, "visibility": "I", "is_constant": " ", "is_class": " "},
  "MI_ASSET_MAN": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "ZIF_ABAPGIT_GUI_ASSET_MANAGER", RTTIName: "\\INTERFACE=ZIF_ABAPGIT_GUI_ASSET_MANAGER"});}, "visibility": "I", "is_constant": " ", "is_class": " "},
  "C_CSS_BUILD_NAME": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "U", "is_constant": "X", "is_class": "X"},
  "C_PREPROCESS_MARKER": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "U", "is_constant": "X", "is_class": "X"},
  "C_COMMENT_START": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "U", "is_constant": "X", "is_class": "X"},
  "C_COMMENT_END": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "U", "is_constant": "X", "is_class": "X"}};
  static METHODS = {"PATCH_HTML": {"visibility": "I", "parameters": {"IV_HTML": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "EV_HTML": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "ET_CSS_URLS": {"type": () => {return abap.types.TableFactory.construct(new abap.types.String({qualifiedName: "STRING"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"isUnique":false,"type":"STANDARD","keyFields":[],"name":"primary_key"},"secondary":[]}, "STRING_TABLE");}, "is_optional": " "}}},
  "IS_PRESERVED": {"visibility": "I", "parameters": {"RV_YES": {"type": () => {return new abap.types.Character(1, {"qualifiedName":"ABAP_BOOL","ddicName":"ABAP_BOOL"});}, "is_optional": " "}, "IV_CSS_URL": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}},
  "FIND_HEAD_OFFSET": {"visibility": "I", "parameters": {"RV_HEAD_END": {"type": () => {return new abap.types.Integer({qualifiedName: "I"});}, "is_optional": " "}, "IV_HTML": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}},
  "CONSTRUCTOR": {"visibility": "U", "parameters": {"II_ASSET_MAN": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "ZIF_ABAPGIT_GUI_ASSET_MANAGER", RTTIName: "\\INTERFACE=ZIF_ABAPGIT_GUI_ASSET_MANAGER"});}, "is_optional": " "}}},
  "PRESERVE_CSS": {"visibility": "U", "parameters": {"IV_CSS_URL": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}}};
  #mt_preserve_css;
  #mi_asset_man;
  constructor() {
    this.me = new abap.types.ABAPObject();
    this.me.set(this);
    this.INTERNAL_ID = abap.internalIdCounter++;
    this.FRIENDS_ACCESS_INSTANCE = {
      "patch_html": this.#patch_html.bind(this),
      "is_preserved": this.#is_preserved.bind(this),
      "find_head_offset": this.#find_head_offset.bind(this),
      "preserve_css": this.preserve_css.bind(this),
    };
    this.#mt_preserve_css = abap.types.TableFactory.construct(new abap.types.String({qualifiedName: "STRING"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"isUnique":false,"type":"STANDARD","keyFields":[],"name":"primary_key"},"secondary":[]}, "STRING_TABLE");
    this.FRIENDS_ACCESS_INSTANCE["mt_preserve_css"] = this.#mt_preserve_css;
    this.#mi_asset_man = new abap.types.ABAPObject({qualifiedName: "ZIF_ABAPGIT_GUI_ASSET_MANAGER", RTTIName: "\\INTERFACE=ZIF_ABAPGIT_GUI_ASSET_MANAGER"});
    this.FRIENDS_ACCESS_INSTANCE["mi_asset_man"] = this.#mi_asset_man;
    this.c_css_build_name = zcl_abapgit_gui_html_processor.c_css_build_name;
    this.c_preprocess_marker = zcl_abapgit_gui_html_processor.c_preprocess_marker;
    this.c_comment_start = zcl_abapgit_gui_html_processor.c_comment_start;
    this.c_comment_end = zcl_abapgit_gui_html_processor.c_comment_end;
  }
  async constructor_(INPUT) {
    let ii_asset_man = INPUT?.ii_asset_man;
    if (ii_asset_man?.getQualifiedName === undefined || ii_asset_man.getQualifiedName() !== "ZIF_ABAPGIT_GUI_ASSET_MANAGER") { ii_asset_man = undefined; }
    if (ii_asset_man === undefined) { ii_asset_man = new abap.types.ABAPObject({qualifiedName: "ZIF_ABAPGIT_GUI_ASSET_MANAGER", RTTIName: "\\INTERFACE=ZIF_ABAPGIT_GUI_ASSET_MANAGER"}).set(INPUT.ii_asset_man); }
    this.#mi_asset_man.set(ii_asset_man);
    return this;
  }
  async #is_preserved(INPUT) {
    let rv_yes = new abap.types.Character(1, {"qualifiedName":"ABAP_BOOL","ddicName":"ABAP_BOOL"});
    let iv_css_url = INPUT?.iv_css_url;
    if (iv_css_url?.getQualifiedName === undefined || iv_css_url.getQualifiedName() !== "STRING") { iv_css_url = undefined; }
    if (iv_css_url === undefined) { iv_css_url = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_css_url); }
    abap.statements.readTable(this.#mt_preserve_css,{withKey: (i) => {return abap.compare.eq(i.table_line, iv_css_url);},
      withKeyValue: [{key: (i) => {return i.table_line}, value: iv_css_url}],
      usesTableLine: true,
      withKeySimple: {"table_line": iv_css_url}});
    rv_yes.set(abap.builtin.boolc(abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0))));
    return rv_yes;
  }
  async #patch_html(INPUT) {
    let iv_html = INPUT?.iv_html;
    if (iv_html?.getQualifiedName === undefined || iv_html.getQualifiedName() !== "STRING") { iv_html = undefined; }
    if (iv_html === undefined) { iv_html = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_html); }
    let ev_html = INPUT?.ev_html || new abap.types.String({qualifiedName: "STRING"});
    let et_css_urls = INPUT?.et_css_urls || abap.types.TableFactory.construct(new abap.types.String({qualifiedName: "STRING"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"isUnique":false,"type":"STANDARD","keyFields":[],"name":"primary_key"},"secondary":[]}, "STRING_TABLE");
    let lc_css_re = new abap.types.String({qualifiedName: "STRING"});
    lc_css_re.set(`<link\\s+rel="stylesheet"\\s+type="text/css"\\s+href="(\\S+)">`);
    let lv_head_end = new abap.types.Integer({qualifiedName: "I"});
    let lo_css_re = new abap.types.ABAPObject({qualifiedName: "CL_ABAP_REGEX", RTTIName: "\\CLASS=CL_ABAP_REGEX"});
    let lo_matcher = new abap.types.ABAPObject({qualifiedName: "CL_ABAP_MATCHER", RTTIName: "\\CLASS=CL_ABAP_MATCHER"});
    let lv_css_path = new abap.types.String({qualifiedName: "STRING"});
    let lv_marker = new abap.types.String({qualifiedName: "STRING"});
    let lv_off = new abap.types.Integer({qualifiedName: "I"});
    let lv_len = new abap.types.Integer({qualifiedName: "I"});
    let lv_cur = new abap.types.Integer({qualifiedName: "I"});
    let lv_css_build = new abap.types.String({qualifiedName: "STRING"});
    lv_css_build.set('<link rel="stylesheet" type="text/css" href="$BUILD_NAME">');
    abap.statements.replace({target: lv_css_build, all: false, with: zcl_abapgit_gui_html_processor.c_css_build_name, of: abap.CharacterFactory.get(11, '$BUILD_NAME')});
    ev_html.clear();
    et_css_urls.clear();
    lv_head_end.set((await this.#find_head_offset({iv_html: iv_html})));
    lo_css_re.set(await (new abap.Classes['CL_ABAP_REGEX']()).constructor_({ignore_case: abap.builtin.abap_true, pattern: lc_css_re}));
    lo_matcher.set((await lo_css_re.get().create_matcher({text: abap.builtin.substring({val: iv_html, len: lv_head_end})})));
    const indexBackup1 = abap.builtin.sy.get().index.get();
    let unique683 = 1;
    while (abap.compare.eq((await lo_matcher.get().find_next()), abap.builtin.abap_true)) {
      abap.builtin.sy.get().index.set(unique683++);
      lv_css_path.set((await lo_matcher.get().get_submatch({index: abap.IntegerFactory.get(1)})));
      if (abap.compare.eq(abap.builtin.abap_false, (await this.#is_preserved({iv_css_url: lv_css_path})))) {
        lv_off.set((await lo_matcher.get().get_offset()));
        lv_len.set((await lo_matcher.get().get_length()));
        ev_html.set(abap.operators.concat(ev_html,abap.builtin.substring({val: iv_html, off: lv_cur, len: abap.operators.minus(lv_off,lv_cur)})));
        ev_html.set(abap.operators.concat(ev_html,abap.operators.concat(zcl_abapgit_gui_html_processor.c_comment_start,abap.operators.concat(abap.builtin.substring({val: iv_html, off: lv_off, len: lv_len}),zcl_abapgit_gui_html_processor.c_comment_end))));
        lv_cur.set(abap.operators.add(lv_off,lv_len));
        abap.statements.append({source: lv_css_path, target: et_css_urls});
      }
    }
    abap.builtin.sy.get().index.set(indexBackup1);
    ev_html.set(abap.operators.concat(ev_html,abap.builtin.substring({val: iv_html, off: lv_cur, len: abap.operators.minus(lv_head_end,lv_cur)})));
    if (abap.compare.gt(abap.builtin.lines({val: et_css_urls}), abap.IntegerFactory.get(0))) {
      lv_marker.set(abap.operators.concat(abap.Classes['CL_ABAP_CHAR_UTILITIES'].newline,abap.operators.concat(new abap.types.String().set(`    `),abap.operators.concat(zcl_abapgit_gui_html_processor.c_preprocess_marker,abap.operators.concat(abap.Classes['CL_ABAP_CHAR_UTILITIES'].newline,new abap.types.String().set(`    `))))));
      ev_html.set(abap.operators.concat(ev_html,abap.operators.concat(lv_marker,lv_css_build)));
    }
    ev_html.set(abap.operators.concat(ev_html,abap.builtin.substring({val: iv_html, off: lv_head_end})));
  }
  async preserve_css(INPUT) {
    let iv_css_url = INPUT?.iv_css_url;
    if (iv_css_url?.getQualifiedName === undefined || iv_css_url.getQualifiedName() !== "STRING") { iv_css_url = undefined; }
    if (iv_css_url === undefined) { iv_css_url = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_css_url); }
    abap.statements.append({source: iv_css_url, target: this.#mt_preserve_css});
  }
  async zif_abapgit_gui_html_processor$process(INPUT) {
    let rv_html = new abap.types.String({qualifiedName: "STRING"});
    let iv_html = INPUT?.iv_html;
    if (iv_html?.getQualifiedName === undefined || iv_html.getQualifiedName() !== "STRING") { iv_html = undefined; }
    if (iv_html === undefined) { iv_html = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_html); }
    let ii_gui_services = INPUT?.ii_gui_services;
    if (ii_gui_services?.getQualifiedName === undefined || ii_gui_services.getQualifiedName() !== "ZIF_ABAPGIT_GUI_SERVICES") { ii_gui_services = undefined; }
    if (ii_gui_services === undefined) { ii_gui_services = new abap.types.ABAPObject({qualifiedName: "ZIF_ABAPGIT_GUI_SERVICES", RTTIName: "\\INTERFACE=ZIF_ABAPGIT_GUI_SERVICES"}).set(INPUT.ii_gui_services); }
    let lo_css_processor = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_GUI_CSS_PROCESSOR", RTTIName: "\\CLASS=ZCL_ABAPGIT_GUI_CSS_PROCESSOR"});
    let lt_css_urls = abap.types.TableFactory.construct(new abap.types.String({qualifiedName: "STRING"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"isUnique":false,"type":"STANDARD","keyFields":[],"name":"primary_key"},"secondary":[]}, "STRING_TABLE");
    let lv_css_build = new abap.types.String({qualifiedName: "STRING"});
    let fs_lv_url_ = new abap.types.FieldSymbol(new abap.types.String({qualifiedName: "STRING"}));
    await this.#patch_html({iv_html: iv_html, ev_html: rv_html, et_css_urls: lt_css_urls});
    if (abap.compare.gt(abap.builtin.lines({val: lt_css_urls}), abap.IntegerFactory.get(0))) {
      lo_css_processor.set(await (new abap.Classes['ZCL_ABAPGIT_GUI_CSS_PROCESSOR']()).constructor_({ii_asset_manager: this.#mi_asset_man}));
      for await (const unique684 of abap.statements.loop(lt_css_urls)) {
        fs_lv_url_.assign(unique684);
        await lo_css_processor.get().add_file({iv_url: fs_lv_url_});
      }
      lv_css_build.set((await lo_css_processor.get().process()));
      await ii_gui_services.get().zif_abapgit_gui_services$cache_asset({iv_url: new abap.types.String().set(`${abap.templateFormatting(zcl_abapgit_gui_html_processor.c_css_build_name)}`), iv_type: abap.CharacterFactory.get(4, 'text'), iv_subtype: abap.CharacterFactory.get(3, 'css'), iv_text: lv_css_build});
    }
    return rv_html;
  }
  async #find_head_offset(INPUT) {
    let rv_head_end = new abap.types.Integer({qualifiedName: "I"});
    let iv_html = INPUT?.iv_html;
    if (iv_html?.getQualifiedName === undefined || iv_html.getQualifiedName() !== "STRING") { iv_html = undefined; }
    if (iv_html === undefined) { iv_html = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_html); }
    rv_head_end.set(abap.builtin.find({val: iv_html, regex: new abap.types.String().set(`${abap.templateFormatting(abap.Classes['CL_ABAP_CHAR_UTILITIES'].newline)}?\\s*</head>`), case: abap.builtin.abap_false}));
    if (abap.compare.le(rv_head_end, abap.IntegerFactory.get(0))) {
      rv_head_end.set(abap.builtin.find({val: iv_html, regex: new abap.types.String().set(`</head>`), case: abap.builtin.abap_false}));
      if (abap.compare.le(rv_head_end, abap.IntegerFactory.get(0))) {
        await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(36, 'HTML preprocessor: </head> not found')});
      }
    }
    return rv_head_end;
  }
}
abap.Classes['ZCL_ABAPGIT_GUI_HTML_PROCESSOR'] = zcl_abapgit_gui_html_processor;
zcl_abapgit_gui_html_processor.c_css_build_name = new abap.types.String({qualifiedName: "STRING"});
zcl_abapgit_gui_html_processor.c_css_build_name.set('css/bundle.css');
zcl_abapgit_gui_html_processor.c_preprocess_marker = new abap.types.String({qualifiedName: "STRING"});
zcl_abapgit_gui_html_processor.c_preprocess_marker.set(`<!-- abapGit HTML preprocessor -->`);
zcl_abapgit_gui_html_processor.c_comment_start = new abap.types.String({qualifiedName: "STRING"});
zcl_abapgit_gui_html_processor.c_comment_start.set(`<!--`);
zcl_abapgit_gui_html_processor.c_comment_end = new abap.types.String({qualifiedName: "STRING"});
zcl_abapgit_gui_html_processor.c_comment_end.set(`-->`);
export {zcl_abapgit_gui_html_processor};