Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1][CDE] Export/import to json check #841

Merged
merged 38 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
18c671c
Paragraph to json
askonev Feb 2, 2023
fb5293e
Run to json
askonev Feb 2, 2023
f7e4412
* Hyperlink to json
askonev Feb 2, 2023
74ce7de
* DocContent to json
askonev Feb 8, 2023
2479f0d
* Table to json
askonev Feb 13, 2023
6122399
[ref] ref api_hyperlink/to_json.js
askonev Feb 15, 2023
d6606f2
* Style to json
askonev Feb 15, 2023
e50e776
[ref] DocContent to json
askonev Feb 21, 2023
e399c24
[ref] DocContent. BlockLvlSdt & Table check
askonev Mar 21, 2023
7f35360
ref: yardoc fix rule
askonev Nov 16, 2023
4d1a3b9
fix: unify static data for specs
askonev Nov 28, 2023
581709f
fix: ApiDocumentContent.ToJSON expected custom name
askonev Nov 28, 2023
6894cc0
[7.6.0][CDE] ApiRGBColor.ToJSON check (#997)
Yar04ek Dec 2, 2023
a23313a
feature: Fill.ToJSON (#1008)
Yar04ek Dec 5, 2023
7d0f39a
revert: TestData (#1009)
askonev Dec 8, 2023
f006554
[7.6.0][CDE] ApiUniColor.ToJSON check (#1015)
Yar04ek Dec 12, 2023
4075f6e
[7.6.0][CDE] ApiGradientStop.ToJSON check (#1014)
Yar04ek Jan 17, 2024
c9735d4
[7.6.0][CDE] ApiStroke.ToJSON check (#1010)
Yar04ek Jan 22, 2024
93c5acd
[8.0.0][CDE] Document.ToJSON
askonev Feb 27, 2024
327125f
[8.1][CDE] InlineLvlSdt.ToJSON
askonev Mar 25, 2024
0f90add
fix: 66725
askonev Mar 26, 2024
011dee0
fix: ApiTable.ToJSON
askonev Apr 9, 2024
0de5171
[8.1][CDE] BlockLvlSdt.ToJSON()
askonev Jun 11, 2024
6432e1a
[8.1][CDE] TablePr.ToJSON()
askonev Jun 11, 2024
05ed603
[8.1][CDE] TableRowPr.ToJSON()
askonev Jun 11, 2024
370a0cb
[8.1][CDE] TableCellPr.ToJSON()
askonev Jun 11, 2024
167092a
[8.1][CDE] TableStylePr.ToJSON()
askonev Jun 11, 2024
5a0a38a
[8.1][CDE] TableCell.ToJSON()
askonev Jun 13, 2024
d47d185
[8.1][CDE] TableRow.ToJSON()
askonev Jun 13, 2024
da2e1db
[8.1][CDE] Drawing.ToJSON()
askonev Jun 13, 2024
05650d3
[8.1][CDE] SchemeColor.ToJSON()
askonev Jun 13, 2024
bcad886
[8.1][CDE] ApiPresetColor.ToJSON()
askonev Jun 13, 2024
b0936b1
Revert "[8.1][CDE] BlockLvlSdt.ToJSON()"
askonev Jun 13, 2024
6a9f574
[8.1][CDE] ApiParaPr.ToJSON()
askonev Jun 13, 2024
f738112
[8.1] remove doc-builder-static-data
askonev Jun 18, 2024
360e0f2
[8.1] skip renamed CDE style
askonev Jun 18, 2024
78eebe2
ref: default_styles order & doc_builder_testing require order
askonev Jun 18, 2024
adca10f
info: coverage
askonev Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-24 19:07:30 UTC using RuboCop version 1.57.1.
# on 2024-06-18 14:03:12 UTC using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 16
Max: 21

# Offense count: 116
# Offense count: 130
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 21

# Offense count: 410
# Offense count: 411
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
61 changes: 61 additions & 0 deletions js/docx/smoke/api_document/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
builder.CreateFile("docx");
// oParagraph
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("paragraph");
oDocument.Push(oParagraph);

// oTable
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered"));
var oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTable.SetTableDescription("Empty table");
oTable.SetStyle(oTableStyle);
var oCell = oTable.GetCell(0, 0);
oCell.GetContent().GetElement(0).AddText(oTable.GetClassType());
oDocument.Push(oTable);

// oBlockLvlSdt
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.GetContent().GetElement(0).AddText(oBlockLvlSdt.GetClassType());
oParagraph = Api.CreateParagraph();
oParagraph.AddText("This is a block text content control.");
oBlockLvlSdt.Push(oParagraph);
oDocument.Push(oBlockLvlSdt)

var bWriteDefaultTextPr = false
// Specifies if the default text properties will be written to the JSON object or not.
var bWriteDefaultParaPr = false
// Specifies if the default paragraph properties will be written to the JSON object or not.
var bWriteTheme = false
// Specifies if the document theme will be written to the JSON object or not.
var bWriteSectionPr = false
// Specifies if the document section properties will be written to the JSON object or not.
var bWriteNumberings = false
// Specifies if the document numberings will be written to the JSON object or not.
var bWriteStyles = false
// Specifies if the document styles will be written to the JSON object or not.

var json = oDocument.ToJSON(bWriteDefaultTextPr,
bWriteDefaultParaPr,
bWriteTheme,
bWriteSectionPr,
bWriteNumberings,
bWriteStyles);

GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"];
var oDocumentFromJSON = Api.FromJSON(json);
var oDocument = Api.GetDocument();
oDocument.GetElement(0).AddText(json);
oDocument.Push(oDocumentFromJSON[1]);
oDocument.Push(oDocumentFromJSON[2]);
oDocument.Push(oDocumentFromJSON[4]);
builder.SaveFile("docx", "DocumentToJSON.docx");
builder.CloseFile();
46 changes: 46 additions & 0 deletions js/docx/smoke/api_document_content/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(104, 155, 104));
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke);
oParagraph.AddDrawing(oDrawing);
var oDocContent = oDrawing.GetDocContent();
// Add Hyperlink
oParagraph = oDocContent.GetElement(0);
oParagraph.AddText('Hyperlink');
var oRange = oParagraph.GetRange(0, 8);
oRange.AddHyperlink('https://api.onlyoffice.com')
// Add BlockLvlSdt
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.AddText('oBlockLvlSdt');
oDocContent.Push(oBlockLvlSdt);
// Add Table
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
var oTable = Api.CreateTable(3, 3);
var oCell = oTable.GetCell(0, 0);
oCell.GetContent().GetElement(0).AddText("Cell #1");
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oDocContent.Push(oTable);
var json = oDocContent.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocContentFromJSON = Api.FromJSON(json);
var oDocument = Api.GetDocument();
var arrElements = []
for( var i = 0; i < oDocContentFromJSON.GetElementsCount(); i++) {
arrElements.push(oDocContentFromJSON.GetElement(i));
}
oDocument.InsertContent(arrElements)
var oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "DocContentToJSON.docx");
builder.CloseFile();
25 changes: 25 additions & 0 deletions js/docx/smoke/api_drawing/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 224, 204), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000);
var oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
var json = oDrawing.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(json);
oDocument.Push(oParagraph);
var oDrawingFromJSON = Api.FromJSON(json)
oParagraph = Api.CreateParagraph();
oParagraph.AddDrawing(oDrawingFromJSON);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
29 changes: 29 additions & 0 deletions js/docx/smoke/api_fill/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 0);
let oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 100000);
let oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
let jsonFill = oFill.ToJSON();
oParagraph.AddText(jsonFill);
GlobalVariable["JSON_Fill"] = jsonFill;
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let jsonFill = GlobalVariable["JSON_Fill"];
let oFill = Api.FromJSON(jsonFill);
oParagraph.AddText(jsonFill);
oDocument.Push(oParagraph);
let oParagraph2 = Api.CreateParagraph();
let oStroke = Api.CreateStroke(0, Api.CreateNoFill());
let oDrawing = Api.CreateShape("rect", 1908000, 1404000, oFill, oStroke);
oDrawing.Fill(oFill);
let jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph2.AddText(jsonDrawing);
oDocument.Push(oParagraph2);
builder.SaveFile("docx", "FillToJson.docx");
builder.CloseFile();
28 changes: 28 additions & 0 deletions js/docx/smoke/api_gradient_stop/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
builder.CreateFile("docx");
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 100000);
GlobalVariable["json"] = {
start: oGs1.ToJSON(),
stop: oGs2.ToJSON()
};
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["json"];
var oDocument = Api.GetDocument();
for (var [key, value] of Object.entries(json)) {
var oPar = Api.CreateParagraph();
oPar.AddText(value);
oDocument.Push(oPar)
}
var oPar1 = oDocument.GetElement(0);
var oFill = Api.CreateRadialGradientFill([Api.FromJSON(json.start), Api.FromJSON(json.stop)]);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 1908000, 1404000, oFill, oStroke);
oPar1.AddDrawing(oDrawing);
oPar1.AddLineBreak();
oPar1.AddText(oDrawing.ToJSON(bWriteNumberings = false, bWriteStyles = false))
builder.SaveFile("docx", "GradientStopToJSON.docx");
builder.CloseFile();
24 changes: 24 additions & 0 deletions js/docx/smoke/api_hyperlink/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oHyperlink = Api.CreateHyperlink("https://api.onlyoffice.com/", "ONLYOFFICE Document Builder", "ONLYOFFICE for developers");
oParagraph.Push(oHyperlink)
let json = oHyperlink.ToJSON(true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var json = GlobalVariable["JSON"]
var oHyperlinkFromJSON = Api.FromJSON(json);
oHyperlinkFromJSON.SetDefaultStyle();
oParagraph.AddElement(oHyperlinkFromJSON);

var oParagraph1 = Api.CreateParagraph();
oDocument.Push(oParagraph1);
oParagraph1.AddText(json);
builder.SaveFile("docx", "RunToJSON.docx");
builder.CloseFile();
25 changes: 25 additions & 0 deletions js/docx/smoke/api_inline_lvl_sdt/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oInlineLvlSdt = Api.CreateInlineLvlSdt();
oInlineLvlSdt.SetAlias("№1");
oInlineLvlSdt.AddText(oInlineLvlSdt.GetClassType());
oParagraph.AddInlineLvlSdt(oInlineLvlSdt);
var json = oInlineLvlSdt.ToJSON(true);

GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"];
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oInlineLvlSdtFromJSON = Api.FromJSON(json);
oParagraph.AddInlineLvlSdt(oInlineLvlSdtFromJSON);
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json)
oDocument.Push(oParagraph)
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
15 changes: 15 additions & 0 deletions js/docx/smoke/api_para_pr/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oMyStyle = oDocument.CreateStyle("My document style");
var oParaPr = oMyStyle.GetParaPr();
oParaPr.SetLeftBorder("single", 24, 0, 0, 255, 0);
var json = oParaPr.ToJSON(true);
var oParaPrFromJSON = Api.FromJSON(json);
var sType = oParaPrFromJSON.GetClassType();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(sType);
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
19 changes: 19 additions & 0 deletions js/docx/smoke/api_paragraph/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("This is a paragraph");
var json = oParagraph.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var json = GlobalVariable["JSON"]
oParagraph.AddText(json);
var oParagraphFromJSON = Api.FromJSON(json);
oDocument.Push(oParagraphFromJSON);
builder.SaveFile("docx", "ParagraphToJSON.docx");
builder.CloseFile();
31 changes: 31 additions & 0 deletions js/docx/smoke/api_preset_color/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oPresetColor = Api.CreatePresetColor("peachPuff");
var json = oPresetColor.ToJSON();
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"]
var oDocument = Api.GetDocument();
var oPresetColorFromJSON = Api.FromJSON(json);
var oParagraph = oDocument.GetElement(0);
var sClassType = oPresetColorFromJSON.GetClassType();
oParagraph.AddText(sClassType);
oDocument.Push(oParagraph)
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph)
var oGs1 = Api.CreateGradientStop(oPresetColorFromJSON, 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
oParagraph = Api.CreateParagraph();
oParagraph.AddDrawing(oDrawing);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
20 changes: 20 additions & 0 deletions js/docx/smoke/api_range/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText("ONLYOFFICE Document Builder");
var oRange = Api.CreateRange(oParagraph, 0, 10);
var json = oRange.ToJSON(true, true);
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var json = GlobalVariable["JSON"]
var oRangeFromJSON = Api.FromJSON(json);
oDocument.Push(oRangeFromJSON[0]);
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(json);
builder.SaveFile("docx", "ParagraphToJSON.docx");
builder.CloseFile();
29 changes: 29 additions & 0 deletions js/docx/smoke/api_rgb_color/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oRGBColor = Api.CreateRGBColor(255, 111, 61);
let jsonRGBColor = oRGBColor.ToJSON();
oParagraph.AddText(jsonRGBColor);
GlobalVariable["JSON_RGBColor"] = jsonRGBColor;
builder.CloseFile();

/////////////////////

builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph1 = oDocument.GetElement(0);
let jsonRGBColor = GlobalVariable["JSON_RGBColor"];
let oRGBColor = Api.FromJSON(jsonRGBColor);
oParagraph1.AddText(jsonRGBColor);
oDocument.Push(oParagraph1);
let oParagraph2 = Api.CreateParagraph();
let oGs1 = Api.CreateGradientStop(oRGBColor, 0);
let oGs2 = Api.CreateGradientStop(255, 213, 191, 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 jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph2.AddText(jsonDrawing);
oDocument.Push(oParagraph2);
builder.SaveFile("docx", "RGBCoolorToJson.docx");
builder.CloseFile();
Loading