Skip to content

Commit

Permalink
ref: ApiRGBColor.ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Yar04ek committed Nov 27, 2023
1 parent e5942ff commit 9f33dc8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 74 deletions.
44 changes: 18 additions & 26 deletions js/docx/smoke/api_rgb_color/to_json.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
var oRGBColor = Api.CreateRGBColor(255, 0, 0);
var json = oRGBColor.ToJSON();
oParagraph.AddText("JSON representation of RGB color: " + json);
oDocument.Push(oParagraph);
GlobalVariable["RGBColorJSON"] = json;
builder.CloseFile()
/////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var json = GlobalVariable["RGBColorJSON"];
var oRGBColorFromJSON = Api.FromJSON(json);
oRGBColorFromJSON.SetDefaultStyle();
oParagraph.AddElement(oRGBColorFromJSON);
var oParagraph1 = Api.CreateParagraph();
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oRGBColor = Api.CreateRGBColor(255, 111, 61);
let json = oRGBColor.ToJSON();
oParagraph.AddText(json);
let oRGBColorFromJSON = Api.FromJSON(json);
let oGs1 = Api.CreateGradientStop(oRGBColor, 0);
let oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000);
let oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
let oStroke = Api.CreateStroke(0, Api.CreateNoFill());
let oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
let bWriteNumberings = false;
let bWriteStyles = true;
let sDrawingJson = oDrawing.ToJSON(bWriteNumberings, bWriteStyles);
let oParagraph1 = Api.CreateParagraph();
oParagraph1.AddText(sDrawingJson);
oDocument.Push(oParagraph1);
oParagraph1.AddText(json);
builder.SaveFile("docx", "RGBColorDocument.docx");
builder.CloseFile();





builder.SaveFile("docx", "RGBColorToJSON.docx");
builder.CloseFile();
31 changes: 0 additions & 31 deletions js/docx/smoke/api_table_row_pr/to_json.js

This file was deleted.

11 changes: 3 additions & 8 deletions spec/docx/smoke/api_rgb_color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
it 'ApiRGBColor | GetClassType method' do
docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/get_class_type.js')
expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor')

end


it 'ApiRGBColor | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js')
p docx
# expect(docx.paragraphs[0].text).to include(GlobalVariable['RGBColorJSON'])
# json = JSON.parse(docx.elements[1].nonempty_runs.first.text)
# expected_rgba = (GlobalVariable['RGBColorJSON'])['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba']
# expect(json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba']).to eq(expected_rgba)
first_paragraph_text = docx.elements[0].nonempty_runs.first.text
third_paragraph_text = docx.elements[1].nonempty_runs.first.text
expect(third_paragraph_text).to include(first_paragraph_text)
end

end
9 changes: 0 additions & 9 deletions spec/docx/smoke/api_table_row_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,4 @@
docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_table_header.js')
expect(docx.elements[1].properties.table_style.table_row_properties.table_header).to be_truthy
end

it 'ApiTableRowPr | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/to_json.js')
json_text = docx.elements[0].nonempty_runs[0].text
parsed_json = JSON.parse(json_text)
expect(parsed_json['type']).to eq('Table')
expect(parsed_json['styles']['132']['name']).to eq('List Table 5 Dark')
expect(docx.elements[1].properties.table_style.name).to eq('List Table 5 Dark')
end
end

0 comments on commit 9f33dc8

Please sign in to comment.