From 5e916949a25e0ac062b2f9d4691f0777b15293fc Mon Sep 17 00:00:00 2001 From: Sorokin Maksim <60688343+askonev@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:50:44 +0300 Subject: [PATCH 01/15] Update: next release dockerfile (#984) --- dockerfiles/debian-next-release/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/debian-next-release/Dockerfile b/dockerfiles/debian-next-release/Dockerfile index 102518a93..056cfbf06 100644 --- a/dockerfiles/debian-next-release/Dockerfile +++ b/dockerfiles/debian-next-release/Dockerfile @@ -1,7 +1,7 @@ FROM ruby:3.2 MAINTAINER Pavel.Lobashov "shockwavenn@gmail.com" -ENV VERSION="7.5.1" +ENV VERSION="7.6.0" ENV DIST="stable" RUN apt-get update && apt-get -y -q install git \ From 3f29b9fe822d65302755e9d473fec5409e2c2972 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:01:47 +0400 Subject: [PATCH 02/15] build(deps): bump nokogiri from 1.15.4 to 1.15.5 (#986) Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.15.4 to 1.15.5. - [Release notes](https://github.com/sparklemotion/nokogiri/releases) - [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md) - [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.15.4...v1.15.5) --- updated-dependencies: - dependency-name: nokogiri dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sorokin Maksim <60688343+askonev@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3bcfe7aaa..5d60c963e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,7 +13,7 @@ GEM jwt (2.7.1) language_server-protocol (3.17.0.3) mini_portile2 (2.8.5) - nokogiri (1.15.4) + nokogiri (1.15.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) onlyoffice_pdf_parser (0.5.0) From cd96f3aec1f252c6bcd2a2b4806eb4e6989ec27f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:14:09 +0400 Subject: [PATCH 03/15] build(deps): bump pkg-config from 1.5.5 to 1.5.6 (#987) Bumps [pkg-config](https://github.com/ruby-gnome/pkg-config) from 1.5.5 to 1.5.6. - [Changelog](https://github.com/ruby-gnome/pkg-config/blob/master/NEWS) - [Commits](https://github.com/ruby-gnome/pkg-config/compare/1.5.5...1.5.6) --- updated-dependencies: - dependency-name: pkg-config dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sorokin Maksim <60688343+askonev@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5d60c963e..330425da2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,7 +43,7 @@ GEM hashery (~> 2.0) ruby-rc4 ttfunk - pkg-config (1.5.5) + pkg-config (1.5.6) racc (1.7.3) rainbow (3.1.1) rake (13.1.0) From b0f6c029e3c833802b804fb0d747979e39dcc113 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Thu, 2 Feb 2023 21:30:28 +0400 Subject: [PATCH 04/15] Paragraph to json --- js/docx/smoke/api_paragraph/to_json.js | 19 +++++++++++++++++++ spec/docx/smoke/api_paragraph_spec.rb | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 js/docx/smoke/api_paragraph/to_json.js diff --git a/js/docx/smoke/api_paragraph/to_json.js b/js/docx/smoke/api_paragraph/to_json.js new file mode 100644 index 000000000..54bedb80c --- /dev/null +++ b/js/docx/smoke/api_paragraph/to_json.js @@ -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(); diff --git a/spec/docx/smoke/api_paragraph_spec.rb b/spec/docx/smoke/api_paragraph_spec.rb index b526111d3..019328373 100644 --- a/spec/docx/smoke/api_paragraph_spec.rb +++ b/spec/docx/smoke/api_paragraph_spec.rb @@ -261,4 +261,12 @@ docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_widow_control.js') expect(docx.elements[5].orphan_control).to be_truthy end + + it 'ApiParagraph | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_paragraph/to_json.js') + expect(docx.elements[1].nonempty_runs.first.text).to eq('This is a paragraph') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + expect(json['type']).to eq('paragraph') + expect(json['content'][1]['content'][0]).to eq('This is a paragraph') + end end From 9bf7c0b924c9b34ede0344e9cb473965602739e2 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Thu, 2 Feb 2023 21:32:34 +0400 Subject: [PATCH 05/15] Run to json --- js/docx/smoke/api_run/to_json.js | 22 ++++++++++++++++++++++ spec/docx/smoke/api_run_spec.rb | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 js/docx/smoke/api_run/to_json.js diff --git a/js/docx/smoke/api_run/to_json.js b/js/docx/smoke/api_run/to_json.js new file mode 100644 index 000000000..790fcb926 --- /dev/null +++ b/js/docx/smoke/api_run/to_json.js @@ -0,0 +1,22 @@ +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +var oRun = Api.CreateRun(); +oRun.AddText("This is a text run"); +var json = oRun.ToJSON(true); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +var json = GlobalVariable["JSON"] +var oRunFromJSON = Api.FromJSON(json); +oParagraph.AddElement(oRunFromJSON); +var oParagraph1 = Api.CreateParagraph(); +oDocument.Push(oParagraph1) +oParagraph1.AddText(json); +builder.SaveFile("docx", "RunToJSON.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_run_spec.rb b/spec/docx/smoke/api_run_spec.rb index 69a0fa13b..cf09b8a3b 100644 --- a/spec/docx/smoke/api_run_spec.rb +++ b/spec/docx/smoke/api_run_spec.rb @@ -183,4 +183,13 @@ expect(docx.elements.first.nonempty_runs[3].text).to eq('This is a text run with the text aligned above the baseline vertically.') expect(docx.elements.first.nonempty_runs[3].vertical_align).to eq(:superscript) end + + it 'ApiRun | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_run/to_json.js') + expect(docx.elements[0].nonempty_runs.first.text).to eq('This is a text run') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('run') + expect(json['rPr']['type']).to eq('textPr') + expect(json['content'][0]).to eq('This is a text run') + end end From ffc1d4a4a6a69f33eed87de5edf8ae7f0006f3bc Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Thu, 2 Feb 2023 21:39:46 +0400 Subject: [PATCH 06/15] * Hyperlink to json * Range to json --- js/docx/smoke/api_hyperlink/to_json.js | 24 +++++++++++++++++++ js/docx/smoke/api_range/to_json.js | 20 ++++++++++++++++ .../smoke/api_hyperlink/api_hyperlink_spec.rb | 15 ++++++++++++ spec/docx/smoke/api_range/api_range_spec.rb | 12 ++++++++++ 4 files changed, 71 insertions(+) create mode 100644 js/docx/smoke/api_hyperlink/to_json.js create mode 100644 js/docx/smoke/api_range/to_json.js create mode 100644 spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb create mode 100644 spec/docx/smoke/api_range/api_range_spec.rb diff --git a/js/docx/smoke/api_hyperlink/to_json.js b/js/docx/smoke/api_hyperlink/to_json.js new file mode 100644 index 000000000..f8d3a6c26 --- /dev/null +++ b/js/docx/smoke/api_hyperlink/to_json.js @@ -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(); diff --git a/js/docx/smoke/api_range/to_json.js b/js/docx/smoke/api_range/to_json.js new file mode 100644 index 000000000..16e5ee488 --- /dev/null +++ b/js/docx/smoke/api_range/to_json.js @@ -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, 9); +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(); diff --git a/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb b/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb new file mode 100644 index 000000000..8f8f08ca3 --- /dev/null +++ b/spec/docx/smoke/api_hyperlink/api_hyperlink_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' +describe 'ApiHyperlink tests' do + it 'ApiHyperlink | ToJSON methods' do + docx = builder.build_and_parse('js/docx/smoke/api_hyperlink/to_json.js') + expect(docx.elements[0].nonempty_runs.first.text).to eq('ONLYOFFICE Document Builder') + expect(docx.elements[0].nonempty_runs.first.link.url).to eq('https://api.onlyoffice.com/') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('hyperlink') + expect(json['value']).to eq('https://api.onlyoffice.com/') + expect(json['tooltip']).to eq('ONLYOFFICE for developers') + expect(json['styles']['174']['name']).to eq('Hyperlink') + end +end diff --git a/spec/docx/smoke/api_range/api_range_spec.rb b/spec/docx/smoke/api_range/api_range_spec.rb new file mode 100644 index 000000000..7e806e8c7 --- /dev/null +++ b/spec/docx/smoke/api_range/api_range_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' +describe 'ApiRange section tests' do + it 'ApiRange | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_range/to_json.js') + expect(docx.elements[1].nonempty_runs.first.text).to eq('ONLYOFFICE') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + expect(json['type']).to eq('document') + expect(json['content'][0]['content'][0]['content'][0]).to eq('ONLYOFFICE') + end +end From 16059d86f5331e0716006a3418b8f4e9233963b3 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 8 Feb 2023 18:00:41 +0400 Subject: [PATCH 07/15] * DocContent to json --- js/docx/smoke/api_document_content/to_json.js | 27 +++++++++++++++++++ spec/docx/smoke/api_document_content_spec.rb | 7 +++++ 2 files changed, 34 insertions(+) create mode 100644 js/docx/smoke/api_document_content/to_json.js diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js new file mode 100644 index 000000000..b7f806309 --- /dev/null +++ b/js/docx/smoke/api_document_content/to_json.js @@ -0,0 +1,27 @@ +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(); + oParagraph = oDocContent.GetElement(0); + oParagraph.AddText("Simple text"); + var json = oDocContent.ToJSON(true, true); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"] + var oDocContentFromJSON = Api.FromJSON(json); + Api.ReplaceDocumentContent(oDocContentFromJSON); + var oDocument = Api.GetDocument(); + var oParagraph = Api.CreateParagraph(); + oParagraph.AddText(json); + oDocument.Push(oParagraph); +builder.SaveFile("docx", "ParagraphToJSON.docx"); +builder.CloseFile(); + diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index 92290e4e3..14c0505f6 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -53,4 +53,11 @@ expect(docx.elements.first.nonempty_runs.first.alternate_content.office2010_content.graphic.data.text_body.elements[4] .nonempty_runs.first.text).to eq('We removed paragraph #3, check that out above.') end + + it 'ApiDocumentContent | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') + expect(docx.elements[0].nonempty_runs.first.text).to eq('Simple text') + json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(json['type']).to eq('docContent') + end end From db76655b2b121ee6107a5c9646d64ac969233d90 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Mon, 13 Feb 2023 18:42:06 +0400 Subject: [PATCH 08/15] * Table to json --- js/docx/smoke/api_paragraph/to_json.js | 20 ++++++++++---------- js/docx/smoke/api_table/to_json.js | 25 +++++++++++++++++++++++++ spec/docx/smoke/api_table_spec.rb | 9 +++++++++ 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 js/docx/smoke/api_table/to_json.js diff --git a/js/docx/smoke/api_paragraph/to_json.js b/js/docx/smoke/api_paragraph/to_json.js index 54bedb80c..76695af33 100644 --- a/js/docx/smoke/api_paragraph/to_json.js +++ b/js/docx/smoke/api_paragraph/to_json.js @@ -1,19 +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); + 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); + 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(); diff --git a/js/docx/smoke/api_table/to_json.js b/js/docx/smoke/api_table/to_json.js new file mode 100644 index 000000000..b1c86265d --- /dev/null +++ b/js/docx/smoke/api_table/to_json.js @@ -0,0 +1,25 @@ +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var TStyleName = "List Table 5 Dark" + // "Grid Table 1 Light" + // "List Table 1 Light" + // "Lined Accent" + // "Bordered - Accent 5" + var oTableStyle = oDocument.GetStyle(TStyleName); + var oTable = Api.CreateTable(3, 3); + oTable.SetStyle(oTableStyle); + var json = oTable.ToJSON(true, true); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var oDocument = Api.GetDocument(); + var oPar = oDocument.GetElement(0); + var json = GlobalVariable["JSON"] + oPar.AddText(json); + var oTableFromJSON = Api.FromJSON(json); + oDocument.Push(oTableFromJSON); +builder.SaveFile("docx", "TableToJSON.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_table_spec.rb b/spec/docx/smoke/api_table_spec.rb index 4654211a0..44705efbc 100644 --- a/spec/docx/smoke/api_table_spec.rb +++ b/spec/docx/smoke/api_table_spec.rb @@ -180,4 +180,13 @@ docx = builder.build_and_parse('js/docx/smoke/api_table/set_width.js') expect(docx.elements[1].properties.table_width).to eq(OoxmlParser::OoxmlSize.new(100, :percent)) end + + it 'ApiTable | ToJSON method' do + skip('bug https://bugzilla.onlyoffice.com/show_bug.cgi?id=61176') + docx = builder.build_and_parse('js/docx/smoke/api_table/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs[0].text) + expect(json['type']).to eq('Table') + expect(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 From eb680206974297ca3d5ce1512764a7695319710d Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 15 Feb 2023 21:02:46 +0400 Subject: [PATCH 09/15] [ref] ref api_hyperlink/to_json.js --- js/docx/smoke/api_document_content/to_json.js | 1 - js/docx/smoke/api_hyperlink/to_json.js | 28 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js index b7f806309..5b7f36a88 100644 --- a/js/docx/smoke/api_document_content/to_json.js +++ b/js/docx/smoke/api_document_content/to_json.js @@ -24,4 +24,3 @@ builder.CreateFile("docx"); oDocument.Push(oParagraph); builder.SaveFile("docx", "ParagraphToJSON.docx"); builder.CloseFile(); - diff --git a/js/docx/smoke/api_hyperlink/to_json.js b/js/docx/smoke/api_hyperlink/to_json.js index f8d3a6c26..0fad1f100 100644 --- a/js/docx/smoke/api_hyperlink/to_json.js +++ b/js/docx/smoke/api_hyperlink/to_json.js @@ -1,24 +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); + 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 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); + var oParagraph1 = Api.CreateParagraph(); + oDocument.Push(oParagraph1); + oParagraph1.AddText(json); builder.SaveFile("docx", "RunToJSON.docx"); builder.CloseFile(); From a8a7dfb175322c26a7f47dcc85e58c41bb422c1c Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 15 Feb 2023 21:08:07 +0400 Subject: [PATCH 10/15] * Style to json --- js/docx/smoke/api_style/to_json.js | 50 ++++++++++++++++++++++++++++++ lib/doc_builder_static_data.rb | 29 +++++++++++++++++ lib/doc_builder_testing.rb | 1 + spec/docx/smoke/api_style_spec.rb | 15 +++++++++ 4 files changed, 95 insertions(+) create mode 100644 js/docx/smoke/api_style/to_json.js create mode 100644 lib/doc_builder_static_data.rb diff --git a/js/docx/smoke/api_style/to_json.js b/js/docx/smoke/api_style/to_json.js new file mode 100644 index 000000000..aa1813917 --- /dev/null +++ b/js/docx/smoke/api_style/to_json.js @@ -0,0 +1,50 @@ +builder.CreateFile("docx"); + var odoc = Api.GetDocument(); + let arr_def_styles = ["Normal", + "No Spacing", + "Heading 1", + "Heading 2", + "Heading 3", + "Heading 4", + "Heading 5", + "Heading 6", + "Heading 7", + "Heading 8", + "Heading 9", + "Title", + "Subtitle", + "Quote", + "Intense Quote", + "List Paragraph", + "Caption", + "Header", + "Footer", + "Footnote text", + "Endnote text"] + var result_json = {} + arr_def_styles.forEach(el => { + let st = odoc.GetStyle(el); + let json = st.ToJSON() + result_json[el] = json; + }); +GlobalVariable["JSON"] = JSON.stringify(result_json); +builder.CloseFile(); + +//////////////////////// + +builder.CreateFile("docx"); + var json = GlobalVariable["JSON"] + var obj_json = JSON.parse(json) + var odoc = Api.GetDocument(); + for(let k in obj_json){ + let st = Api.FromJSON(obj_json[k]); + let opar = Api.CreateParagraph(); + opar.AddText(st.GetName()) + opar.SetStyle(st); + odoc.Push(opar) + } + let opar = Api.CreateParagraph(); + opar.AddText(json); + odoc.Push(opar) +builder.SaveFile("docx", "StyleToJSON.docx"); +builder.CloseFile(); diff --git a/lib/doc_builder_static_data.rb b/lib/doc_builder_static_data.rb new file mode 100644 index 000000000..9a41139e8 --- /dev/null +++ b/lib/doc_builder_static_data.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# module for doc builder static data +module DocBuilderStaticData + # Default style list in the CDE + DEFAULT_STYLES = [ + 'Normal', + 'No Spacing', + 'Heading 1', + 'Heading 2', + 'Heading 3', + 'Heading 4', + 'Heading 5', + 'Heading 6', + 'Heading 7', + 'Heading 8', + 'Heading 9', + 'Title', + 'Subtitle', + 'Quote', + 'Intense Quote', + 'List Paragraph', + 'Caption', + 'Header', + 'Footer', + 'Footnote text', + 'Endnote text' + ].freeze +end diff --git a/lib/doc_builder_testing.rb b/lib/doc_builder_testing.rb index a6b165d42..6bfa560d7 100644 --- a/lib/doc_builder_testing.rb +++ b/lib/doc_builder_testing.rb @@ -7,3 +7,4 @@ require_relative 'doc_builder_testing/exceptions' require_relative 'doc_builder_testing/web_doc_builder_wrapper' require_relative '../spec/test_data' +require_relative 'doc_builder_static_data' diff --git a/spec/docx/smoke/api_style_spec.rb b/spec/docx/smoke/api_style_spec.rb index 6e8681dbd..a2941de08 100644 --- a/spec/docx/smoke/api_style_spec.rb +++ b/spec/docx/smoke/api_style_spec.rb @@ -85,4 +85,19 @@ docx = builder.build_and_parse('js/docx/smoke/api_style/set_name.js') expect(docx.elements[1].properties.table_style.name).to eq('My Custom Style') end + + it 'ApiStyle | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_style/to_json.js') + json = JSON.parse(docx.elements[22].nonempty_runs[0].text) + DocBuilderStaticData::DEFAULT_STYLES.each_with_index do |style, index| + # TODO: To understand why incorrect names are recorded + next if (style == 'Header') || # in the metadata: Custom_Style 719 styleId: 42 + (style == 'Footer') || # in the metadata: Custom_Style 725 styleId: 44 + (style == 'Footnote text') || # in the metadata: Normal styleId: styleId => 599 + (style == 'Endnote text') # in the metadata: Normal styleId: styleId => 599 + + expect(docx.elements[index + 1].style.name).to eq(style) + expect(JSON.parse(json[style])['name']).to eq(style) + end + end end From 2618bb141aadb659252ff7ddeda65ee5ac17a5af Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Tue, 21 Feb 2023 18:51:56 +0400 Subject: [PATCH 11/15] [ref] DocContent to json --- js/docx/smoke/api_document_content/to_json.js | 22 ++++++++++++++++--- spec/docx/smoke/api_document_content_spec.rb | 9 ++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js index 5b7f36a88..2a9796630 100644 --- a/js/docx/smoke/api_document_content/to_json.js +++ b/js/docx/smoke/api_document_content/to_json.js @@ -6,8 +6,22 @@ builder.CreateFile("docx"); var oDrawing = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke); oParagraph.AddDrawing(oDrawing); var oDocContent = oDrawing.GetDocContent(); +// Add Hyperlink oParagraph = oDocContent.GetElement(0); - oParagraph.AddText("Simple text"); + 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); + oTable.SetWidth("percent", 100); + oTable.SetStyle(oTableStyle); + oDocContent.Push(oTable); var json = oDocContent.ToJSON(true, true); GlobalVariable["JSON"] = json; builder.CloseFile(); @@ -17,10 +31,12 @@ builder.CloseFile(); builder.CreateFile("docx"); var json = GlobalVariable["JSON"] var oDocContentFromJSON = Api.FromJSON(json); - Api.ReplaceDocumentContent(oDocContentFromJSON); var oDocument = Api.GetDocument(); + for( let el = 0; el < oDocContentFromJSON.GetElementsCount(); el++ ) { + oDocument.Push(oDocContentFromJSON.GetElement(el)) + } var oParagraph = Api.CreateParagraph(); oParagraph.AddText(json); oDocument.Push(oParagraph); -builder.SaveFile("docx", "ParagraphToJSON.docx"); +builder.SaveFile("docx", "DocContentToJSON.docx"); builder.CloseFile(); diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index 14c0505f6..e65303fe7 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -56,8 +56,13 @@ it 'ApiDocumentContent | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') - expect(docx.elements[0].nonempty_runs.first.text).to eq('Simple text') - json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(docx.elements[1].hyperlink.action.to_s).to eq('external_link') + # TODO: add block content control checking + expect(docx.elements[4].number).to eq(3) + json = JSON.parse(docx.elements[7].nonempty_runs.first.text) expect(json['type']).to eq('docContent') + expect(json['content'][0]['content'][2]['type']).to eq('hyperlink') + expect(json['content'][1]['type']).to eq('blockLvlSdt') + expect(json['content'][2]['type']).to eq('table') end end From 6ca653c02e3870fe9ae6c0fa19035b64a3a570f1 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Tue, 21 Mar 2023 20:11:25 +0300 Subject: [PATCH 12/15] [ref] DocContent. BlockLvlSdt & Table check --- js/docx/smoke/api_document_content/to_json.js | 8 ++++++-- lib/doc_builder_static_data.rb | 2 ++ spec/docx/smoke/api_document_content_spec.rb | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js index 2a9796630..ff9b2e76b 100644 --- a/js/docx/smoke/api_document_content/to_json.js +++ b/js/docx/smoke/api_document_content/to_json.js @@ -19,6 +19,8 @@ builder.CreateFile("docx"); 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); @@ -32,9 +34,11 @@ builder.CreateFile("docx"); var json = GlobalVariable["JSON"] var oDocContentFromJSON = Api.FromJSON(json); var oDocument = Api.GetDocument(); - for( let el = 0; el < oDocContentFromJSON.GetElementsCount(); el++ ) { - oDocument.Push(oDocContentFromJSON.GetElement(el)) + 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); diff --git a/lib/doc_builder_static_data.rb b/lib/doc_builder_static_data.rb index 9a41139e8..cecfe8790 100644 --- a/lib/doc_builder_static_data.rb +++ b/lib/doc_builder_static_data.rb @@ -26,4 +26,6 @@ module DocBuilderStaticData 'Footnote text', 'Endnote text' ].freeze + + TABLE_STYLE = { BorderedAccent5: '48' }.freeze end diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index e65303fe7..99b0ebe6e 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -56,10 +56,10 @@ it 'ApiDocumentContent | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') - expect(docx.elements[1].hyperlink.action.to_s).to eq('external_link') - # TODO: add block content control checking - expect(docx.elements[4].number).to eq(3) - json = JSON.parse(docx.elements[7].nonempty_runs.first.text) + expect(docx.elements[0].hyperlink.action.to_s).to eq('external_link') + expect(docx.elements[1].sdt_content.elements[1].character_style_array[0].text).to eq('oBlockLvlSdt') + expect(docx.elements[2].properties.table_style.style_id).to eq(DocBuilderStaticData::TABLE_STYLE[:BorderedAccent5]) + json = JSON.parse(docx.elements[5].nonempty_runs.first.text) expect(json['type']).to eq('docContent') expect(json['content'][0]['content'][2]['type']).to eq('hyperlink') expect(json['content'][1]['type']).to eq('blockLvlSdt') From 1672c189488881b0e7ea5642b6dc87a15834026c Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Thu, 16 Nov 2023 17:18:07 +0300 Subject: [PATCH 13/15] ref: yardoc fix rule --- lib/doc_builder_static_data.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/doc_builder_static_data.rb b/lib/doc_builder_static_data.rb index cecfe8790..de928ec2f 100644 --- a/lib/doc_builder_static_data.rb +++ b/lib/doc_builder_static_data.rb @@ -27,5 +27,6 @@ module DocBuilderStaticData 'Endnote text' ].freeze + # Default table style codes TABLE_STYLE = { BorderedAccent5: '48' }.freeze end From 50287a04ac6dc93613fcac20628bfffc767c2d44 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Tue, 28 Nov 2023 14:03:48 +0300 Subject: [PATCH 14/15] fix: unify static data for specs --- .rubocop_todo.yml | 8 ++--- lib/doc_builder_static_data.rb | 32 ------------------- lib/doc_builder_testing.rb | 6 ++-- ...est_data.rb => doc_builder_static_data.rb} | 29 ++++++++++++++++- spec/doc_builder_wrapper_spec.rb | 2 +- spec/docx/smoke/api_document_content_spec.rb | 1 + spec/docx/smoke/api_style_spec.rb | 2 +- spec/spec_helper.rb | 1 + spec/xlsx/smoke/api_range_spec.rb | 8 ++--- 9 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 lib/doc_builder_static_data.rb rename spec/{test_data.rb => doc_builder_static_data.rb} (57%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 56d4d64d8..5d0eb56ba 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,17 +1,17 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-10-24 19:07:30 UTC using RuboCop version 1.57.1. +# on 2023-11-28 10:56:01 UTC using RuboCop version 1.57.2. # 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: 121 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 21 diff --git a/lib/doc_builder_static_data.rb b/lib/doc_builder_static_data.rb deleted file mode 100644 index de928ec2f..000000000 --- a/lib/doc_builder_static_data.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# module for doc builder static data -module DocBuilderStaticData - # Default style list in the CDE - DEFAULT_STYLES = [ - 'Normal', - 'No Spacing', - 'Heading 1', - 'Heading 2', - 'Heading 3', - 'Heading 4', - 'Heading 5', - 'Heading 6', - 'Heading 7', - 'Heading 8', - 'Heading 9', - 'Title', - 'Subtitle', - 'Quote', - 'Intense Quote', - 'List Paragraph', - 'Caption', - 'Header', - 'Footer', - 'Footnote text', - 'Endnote text' - ].freeze - - # Default table style codes - TABLE_STYLE = { BorderedAccent5: '48' }.freeze -end diff --git a/lib/doc_builder_testing.rb b/lib/doc_builder_testing.rb index 6bfa560d7..5ef35c7b8 100644 --- a/lib/doc_builder_testing.rb +++ b/lib/doc_builder_testing.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true +require 'tempfile' require 'ooxml_parser' require 'onlyoffice_pdf_parser' -require 'tempfile' -require_relative 'doc_builder_testing/doc_builder_wrapper' require_relative 'doc_builder_testing/exceptions' +require_relative 'doc_builder_testing/doc_builder_wrapper' require_relative 'doc_builder_testing/web_doc_builder_wrapper' -require_relative '../spec/test_data' -require_relative 'doc_builder_static_data' diff --git a/spec/test_data.rb b/spec/doc_builder_static_data.rb similarity index 57% rename from spec/test_data.rb rename to spec/doc_builder_static_data.rb index 3b0aef339..3bcacc02b 100644 --- a/spec/test_data.rb +++ b/spec/doc_builder_static_data.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true # Test data for autotest -module TestData +module DocBuilderStaticData # CDE number formats (7.4.0) + # @return [Array] def self.number_formats ['General', '0.00', @@ -17,6 +18,32 @@ def self.number_formats '0.00E+00'].freeze end + # Default style list for CDE v7.4.1 + # @return [Array] + def self.cde_styles + ['Normal', + 'No Spacing', + 'Heading 1', + 'Heading 2', + 'Heading 3', + 'Heading 4', + 'Heading 5', + 'Heading 6', + 'Heading 7', + 'Heading 8', + 'Heading 9', + 'Title', + 'Subtitle', + 'Quote', + 'Intense Quote', + 'List Paragraph', + 'Caption', + 'Header', + 'Footer', + 'Footnote text', + 'Endnote text'].freeze + end + # @return [Array] def self.libs %w[DjVuFile.dll diff --git a/spec/doc_builder_wrapper_spec.rb b/spec/doc_builder_wrapper_spec.rb index 05d46e005..09fa8332b 100644 --- a/spec/doc_builder_wrapper_spec.rb +++ b/spec/doc_builder_wrapper_spec.rb @@ -87,7 +87,7 @@ end describe 'check windows build libs', :win do - TestData.libs.each do |lib| + DocBuilderStaticData.libs.each do |lib| it lib.to_s do skip('[WIN] check build libs') unless Gem.win_platform? expect(arr_libs).to include(lib) diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index 99b0ebe6e..afcfff15a 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# frozen_string_literal: true require 'spec_helper' describe 'ApiDocumentContent section tests' do diff --git a/spec/docx/smoke/api_style_spec.rb b/spec/docx/smoke/api_style_spec.rb index a2941de08..f2117e0a2 100644 --- a/spec/docx/smoke/api_style_spec.rb +++ b/spec/docx/smoke/api_style_spec.rb @@ -89,7 +89,7 @@ it 'ApiStyle | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_style/to_json.js') json = JSON.parse(docx.elements[22].nonempty_runs[0].text) - DocBuilderStaticData::DEFAULT_STYLES.each_with_index do |style, index| + DocBuilderStaticData.cde_styles.each_with_index do |style, index| # TODO: To understand why incorrect names are recorded next if (style == 'Header') || # in the metadata: Custom_Style 719 styleId: 42 (style == 'Footer') || # in the metadata: Custom_Style 725 styleId: 44 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c39a5335e..03d4ab1e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'bundler/setup' require 'rspec' require_relative '../lib/doc_builder_testing' +require_relative 'doc_builder_static_data' # Get either DocBuilder of WebDocBuilder # depending of env var diff --git a/spec/xlsx/smoke/api_range_spec.rb b/spec/xlsx/smoke/api_range_spec.rb index 80da0a90b..322837a66 100644 --- a/spec/xlsx/smoke/api_range_spec.rb +++ b/spec/xlsx/smoke/api_range_spec.rb @@ -2,10 +2,6 @@ require 'spec_helper' describe 'ApiRange section tests' do - before do - include TestData - end - it 'ApiRange | GetCol method' do xlsx = builder.build_and_parse('js/xlsx/smoke/api_range/get_col.js') expect(xlsx.worksheets.first.rows[1].cells.first.text).to eq('4') @@ -83,7 +79,7 @@ it 'ApiRange | NumberFormat method' do xlsx = builder.build_and_parse('js/xlsx/smoke/api_range/setter_number_format.js') - TestData.number_formats.each_with_index do |format, i| + DocBuilderStaticData.number_formats.each_with_index do |format, i| expect(xlsx.worksheets.first.rows[i + 1].cells[0].raw_text).to eq('123456') expect(xlsx.worksheets.first.rows[i + 1].cells[0].style.numerical_format).to eq(format) end @@ -92,7 +88,7 @@ it 'ApiRange | GetNumberFormat' do xlsx = builder.build_and_parse('js/xlsx/smoke/api_range/get_number_format.js') - TestData.number_formats.each_with_index do |format, i| + DocBuilderStaticData.number_formats.each_with_index do |format, i| expect(xlsx.worksheets.first.rows[i + 1].cells[2].raw_text).to eq('123456') expect(xlsx.worksheets.first.rows[i + 1].cells[2].style.numerical_format).to eq(format) end From c9b8a1d130f9443a82dff2b8c292a6f06a45d7cb Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Tue, 28 Nov 2023 14:06:15 +0300 Subject: [PATCH 15/15] fix: ApiDocumentContent.ToJSON expected custom name --- spec/docx/smoke/api_document_content_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index afcfff15a..a2acf323d 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -# frozen_string_literal: true require 'spec_helper' describe 'ApiDocumentContent section tests' do @@ -59,7 +58,7 @@ docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') expect(docx.elements[0].hyperlink.action.to_s).to eq('external_link') expect(docx.elements[1].sdt_content.elements[1].character_style_array[0].text).to eq('oBlockLvlSdt') - expect(docx.elements[2].properties.table_style.style_id).to eq(DocBuilderStaticData::TABLE_STYLE[:BorderedAccent5]) + expect(docx.elements[2].properties.table_style.name).to eq('CustomTableStyle') json = JSON.parse(docx.elements[5].nonempty_runs.first.text) expect(json['type']).to eq('docContent') expect(json['content'][0]['content'][2]['type']).to eq('hyperlink')