From 83c118e3679426f8743838bd1e87e927f6d18370 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:00:52 +0300 Subject: [PATCH 01/19] add RGB color test --- spec/docx/smoke/api_rgb_color_spec.rb | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index d2bf39a1..d576f13d 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -1,9 +1,42 @@ # frozen_string_literal: true require 'spec_helper' + describe 'ApiRGBColor section tests' do 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') + + + actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase.gsub(' ', '').gsub('=', '') + + + class_type_prefix = 'class type = ' + actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase + actual_class_type.slice!(class_type_prefix) if actual_class_type.start_with?(class_type_prefix) + + + expected_class_type = 'rgbcolor' + expect(actual_class_type).to eq(expected_class_type) + + + json_text = docx.elements[0].nonempty_runs.last.text.strip + + if json_text.start_with?('{') + begin + json = JSON.parse(json_text) + color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] + + + expected_color = [255, 164, 101] + + expect(color_from_json).to eq(expected_color) + rescue JSON::ParserError => e + puts "Error parsing JSON: #{e.message}" + end + else + puts 'Invalid JSON format' + end end end + From c9f3dcb9bbd17ae99bb00bdcfe4073f09b843003 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:07:55 +0300 Subject: [PATCH 02/19] Revert "add RGB color test" This reverts commit 83c118e3679426f8743838bd1e87e927f6d18370. --- spec/docx/smoke/api_rgb_color_spec.rb | 35 +-------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index d576f13d..d2bf39a1 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -1,42 +1,9 @@ # frozen_string_literal: true require 'spec_helper' - describe 'ApiRGBColor section tests' do it 'ApiRGBColor | GetClassType method' do - docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/get_class_type.js') - - - actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase.gsub(' ', '').gsub('=', '') - - - class_type_prefix = 'class type = ' - actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase - actual_class_type.slice!(class_type_prefix) if actual_class_type.start_with?(class_type_prefix) - - - expected_class_type = 'rgbcolor' - expect(actual_class_type).to eq(expected_class_type) - - - json_text = docx.elements[0].nonempty_runs.last.text.strip - - if json_text.start_with?('{') - begin - json = JSON.parse(json_text) - color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] - - - expected_color = [255, 164, 101] - - expect(color_from_json).to eq(expected_color) - rescue JSON::ParserError => e - puts "Error parsing JSON: #{e.message}" - end - else - puts 'Invalid JSON format' - end + expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor') end end - From 729cee2d2c24635e7129abb08baaa9e20a10bf08 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:15:19 +0300 Subject: [PATCH 03/19] Add RGB color tests --- spec/docx/smoke/api_rgb_color_spec.rb | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index d2bf39a1..52140512 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -1,9 +1,43 @@ # frozen_string_literal: true require 'spec_helper' + describe 'ApiRGBColor section tests' do 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') + + + actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase.gsub(' ', '').gsub('=', '') + + + class_type_prefix = 'class type = ' + actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase + actual_class_type.slice!(class_type_prefix) if actual_class_type.start_with?(class_type_prefix) + + + expected_class_type = 'rgbcolor' + expect(actual_class_type).to eq(expected_class_type) + + + json_text = docx.elements[0].nonempty_runs.last.text.strip + + if json_text.start_with?('{') + begin + json = JSON.parse(json_text) + color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] + + + expected_color = [255, 164, 101] + + expect(color_from_json).to eq(expected_color) + rescue JSON::ParserError => e + puts "Error parsing JSON: #{e.message}" + end + else + puts 'Invalid JSON format' + end end end + + From 09996aee1e9692eea345c7a482a469d9f1ef87b2 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:32:51 +0300 Subject: [PATCH 04/19] Add Api Table row pr test --- .../smoke/api_table_row_properties_spec.rb | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b455dc31..b2803f5a 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -2,18 +2,38 @@ require 'spec_helper' describe 'ApiTableRowPr section tests' do - it 'ApiTableRowPr | GetClassType method' do - docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/get_class_type.js') - expect(docx.elements.first.nonempty_runs.first.text).to eq('Class Type = tableRowPr') + it 'ApiTableRowPr | SetHeight method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') + + expected_height = OoxmlParser::OoxmlSize.new(720, :twip) + actual_height = docx.elements[1].properties.table_style.table_row_properties.height.value + + expect(actual_height).to eq(expected_height) end + it 'ApiTableRowPr | SetHeight method' do docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') - expect(docx.elements[1].properties.table_style.table_row_properties.height.value).to eq(OoxmlParser::OoxmlSize.new(720, :twip)) + expect(docx.elements[0].nonempty_runs[0].text).to eq('We create a 3x3 table and set the height of half an inch to all the rows:') + table_row_pr = docx.elements[1].properties.table_style.table_row_properties + expect(table_row_pr.height.value).to eq(OoxmlParser::OoxmlSize.new(720, :twip)) end it 'ApiTableRowPr | SetTableHeader method' do + # Build and parse the document 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 + + # Check the content of the first paragraph + expected_text = 'We create a 3x3 table and set all table rows as the table headers:' + actual_text = docx.elements.first.nonempty_runs.first.text + expect(actual_text).to eq(expected_text) + + # Check if the table has the correct style + table_style = docx.elements[1].properties.table_style + expect(table_style).to_not be_nil + expect(table_style.table_row_properties).to_not be_nil + + # Check if the table header property is set to true + expect(table_style.table_row_properties.table_header).to eq(true) end -end +end \ No newline at end of file From 4a55c5ad0fb8d869880e9e456074abbe90d7a70d Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:03:13 +0300 Subject: [PATCH 05/19] code correction with Rubokop --- spec/docx/smoke/api_rgb_color_spec.rb | 17 +---------------- .../smoke/api_table_row_properties_spec.rb | 18 ++++++------------ 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 52140512..a4bd40ac 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -4,32 +4,19 @@ describe 'ApiRGBColor section tests' do it 'ApiRGBColor | GetClassType method' do - docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/get_class_type.js') - - - actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase.gsub(' ', '').gsub('=', '') - - + docx.elements[1].nonempty_runs[0].text.downcase.delete(' ').delete('=') class_type_prefix = 'class type = ' actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase actual_class_type.slice!(class_type_prefix) if actual_class_type.start_with?(class_type_prefix) - - expected_class_type = 'rgbcolor' expect(actual_class_type).to eq(expected_class_type) - - json_text = docx.elements[0].nonempty_runs.last.text.strip - if json_text.start_with?('{') begin json = JSON.parse(json_text) color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] - - expected_color = [255, 164, 101] - expect(color_from_json).to eq(expected_color) rescue JSON::ParserError => e puts "Error parsing JSON: #{e.message}" @@ -39,5 +26,3 @@ end end end - - diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b2803f5a..ba162264 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -1,17 +1,14 @@ # frozen_string_literal: true require 'spec_helper' -describe 'ApiTableRowPr section tests' do - it 'ApiTableRowPr | SetHeight method' do +describe('ApiTableRowPr section tests') do + it 'ApiTableRowPr | GetClassType method' do docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') - expected_height = OoxmlParser::OoxmlSize.new(720, :twip) actual_height = docx.elements[1].properties.table_style.table_row_properties.height.value - expect(actual_height).to eq(expected_height) end - it 'ApiTableRowPr | SetHeight method' do docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') expect(docx.elements[0].nonempty_runs[0].text).to eq('We create a 3x3 table and set the height of half an inch to all the rows:') @@ -22,18 +19,15 @@ it 'ApiTableRowPr | SetTableHeader method' do # Build and parse the document docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_table_header.js') - # Check the content of the first paragraph expected_text = 'We create a 3x3 table and set all table rows as the table headers:' actual_text = docx.elements.first.nonempty_runs.first.text expect(actual_text).to eq(expected_text) - # Check if the table has the correct style table_style = docx.elements[1].properties.table_style - expect(table_style).to_not be_nil - expect(table_style.table_row_properties).to_not be_nil - + expect(table_style).not_to be_nil + expect(table_style.table_row_properties).not_to be_nil # Check if the table header property is set to true - expect(table_style.table_row_properties.table_header).to eq(true) + expect(table_style.table_row_properties.table_header).to be(true) end -end \ No newline at end of file +end From 4a2c1bdb83479578fae44f6ed2205fff93fa8a0e Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:36:21 +0100 Subject: [PATCH 06/19] add JSON test for RGB color --- js/docx/smoke/api_rgb_color/to_json.js | 46 ++++++++++++++++++++++++++ spec/docx/smoke/api_rgb_color_spec.rb | 31 ++++++----------- 2 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 js/docx/smoke/api_rgb_color/to_json.js diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js new file mode 100644 index 00000000..61bb1493 --- /dev/null +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -0,0 +1,46 @@ +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); +var oParagraph = oDocument.GetElement(0); +// Создаем градиентный цвет +var oRGBColor = Api.CreateRGBColor(255, 164, 101); +var oGs1 = Api.CreateGradientStop(Api.CreatePresetColor("lightYellow"), 0); +var oGs2 = Api.CreateGradientStop(oRGBColor, 100000); +var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]); +var oStroke = Api.CreateStroke(0, Api.CreateNoFill()); +var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); +// Добавляем прямоугольную форму в параграф +oParagraph.AddDrawing(oDrawing); +// Получаем тип класса цвета +var oClassType = oRGBColor.GetClassType(); +// Создаем новый параграф и добавляем в него информацию о классе цвета +var oNewParagraph = Api.CreateParagraph(); +oNewParagraph.AddText("Class Type = " + oClassType); +// Добавляем новый параграф в документ +oDocument.Push(oNewParagraph); +// Преобразуем в JSON +var json = oDocument.ToJSON(false, false, false, false, false, false); +GlobalVariable["JSON"] = json; +builder.CloseFile(); + + +///////////////////////// + +builder.CreateFile("docx"); +var oDocument = Api.GetDocument(); + +// Получаем JSON из глобальной переменной +var json = GlobalVariable["JSON"]; + +// Создаем первый параграф и добавляем текст из JSON в него +var oFirstParagraph = Api.CreateParagraph(); +oFirstParagraph.AddText(json); +// Добавляем первый параграф в документ +oDocument.Push(oFirstParagraph); +// Создаем новый параграф из JSON +var oParagraphFromJSON = Api.CreateParagraph(); +oParagraphFromJSON.FromJSON(json); +// Добавляем новый параграф с текстом из JSON в документ +oDocument.Push(oParagraphFromJSON); +// Сохраняем результат в файл +builder.SaveFile("docx", "RGBToJSON.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index a4bd40ac..7d64755b 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -1,28 +1,19 @@ # frozen_string_literal: true require 'spec_helper' - describe 'ApiRGBColor section tests' do it 'ApiRGBColor | GetClassType method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/get_class_type.js') - docx.elements[1].nonempty_runs[0].text.downcase.delete(' ').delete('=') - class_type_prefix = 'class type = ' - actual_class_type = docx.elements[1].nonempty_runs[0].text.downcase - actual_class_type.slice!(class_type_prefix) if actual_class_type.start_with?(class_type_prefix) - expected_class_type = 'rgbcolor' - expect(actual_class_type).to eq(expected_class_type) - json_text = docx.elements[0].nonempty_runs.last.text.strip - if json_text.start_with?('{') - begin - json = JSON.parse(json_text) - color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] - expected_color = [255, 164, 101] - expect(color_from_json).to eq(expected_color) - rescue JSON::ParserError => e - puts "Error parsing JSON: #{e.message}" - end - else - puts 'Invalid JSON format' - end + 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') + expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] + expected_color = [255, 164, 101] # Укажите ожидаемый цвет в формате RGBA + expect(color_from_json).to eq(expected_color) end end From edb5490110de76f64f58fa602b3be563ee84b6d1 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:42:03 +0100 Subject: [PATCH 07/19] add JSON test to table row pr --- js/docx/smoke/api_table_row_pr/to_json.js | 31 +++++++++++++++++ .../smoke/api_table_row_properties_spec.rb | 33 ++++++++----------- 2 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 js/docx/smoke/api_table_row_pr/to_json.js diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js new file mode 100644 index 00000000..a5e2fc51 --- /dev/null +++ b/js/docx/smoke/api_table_row_pr/to_json.js @@ -0,0 +1,31 @@ +builder.CreateFile("docx"); +var oDocument = Api.CreateDocument(); +var oParagraph = Api.CreateParagraph(); +oParagraph.AddText("We create a 3x3 table and set the height of half an inch to all the rows:"); +oDocument.Push(oParagraph); +var oTableStyle = Api.CreateTableStyle("CustomTableStyle", "table"); +oTableStyle.SetBasedOn(Api.GetStyle("Bordered - Accent 5")); +var oTable = Api.CreateTable(3, 3); +oTable.SetWidth("percent", 100); +oTable.SetTableLook(true, true, true, true, false, false); +var oTableRowPr = oTableStyle.GetTableRowPr(); +oTableRowPr.SetHeight("atLeast", 720); +oTable.SetStyle(oTableStyle); +oDocument.Push(oTable); +builder.SaveFile("docx", "SetHeight.docx"); +builder.CloseFile(); + + + +////////////// + + +builder.CreateFile("docx"); +var newDocument = Api.CreateDocument(); +var newParagraph = newDocument.GetElement(0); +var tableJSONFromGlobal = GlobalVariable["TableJSON"]; +var tableFromJSON = Api.FromJSON(tableJSONFromGlobal); +newParagraph.AddElement(tableFromJSON); +newDocument.Push(newParagraph); +builder.SaveFile("docx", "TableFromJSON.docx"); +builder.CloseFile(); \ No newline at end of file diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index ba162264..6c44abfa 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -1,33 +1,28 @@ # frozen_string_literal: true require 'spec_helper' -describe('ApiTableRowPr section tests') do +describe 'ApiTableRowPr section tests' do it 'ApiTableRowPr | GetClassType method' do - docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') - expected_height = OoxmlParser::OoxmlSize.new(720, :twip) - actual_height = docx.elements[1].properties.table_style.table_row_properties.height.value - expect(actual_height).to eq(expected_height) + docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/get_class_type.js') + expect(docx.elements.first.nonempty_runs.first.text).to eq('Class Type = tableRowPr') end it 'ApiTableRowPr | SetHeight method' do docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_height.js') - expect(docx.elements[0].nonempty_runs[0].text).to eq('We create a 3x3 table and set the height of half an inch to all the rows:') - table_row_pr = docx.elements[1].properties.table_style.table_row_properties - expect(table_row_pr.height.value).to eq(OoxmlParser::OoxmlSize.new(720, :twip)) + expect(docx.elements[1].properties.table_style.table_row_properties.height.value).to eq(OoxmlParser::OoxmlSize.new(720, :twip)) end it 'ApiTableRowPr | SetTableHeader method' do - # Build and parse the document docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_table_header.js') - # Check the content of the first paragraph - expected_text = 'We create a 3x3 table and set all table rows as the table headers:' - actual_text = docx.elements.first.nonempty_runs.first.text - expect(actual_text).to eq(expected_text) - # Check if the table has the correct style - table_style = docx.elements[1].properties.table_style - expect(table_style).not_to be_nil - expect(table_style.table_row_properties).not_to be_nil - # Check if the table header property is set to true - expect(table_style.table_row_properties.table_header).to be(true) + 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 From e5942ff9527e182f7fcd786f41d4756a07d94af5 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:34:19 +0100 Subject: [PATCH 08/19] ref: ApiRGBColor.ToJSON --- Gemfile.lock | 32 ++++++--------- js/docx/smoke/api_rgb_color/to_json.js | 56 +++++++++----------------- spec/docx/smoke/api_rgb_color_spec.rb | 12 +++--- spec/spec_helper.rb | 7 +++- 4 files changed, 44 insertions(+), 63 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3bcfe7aa..dcd9a753 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,10 +11,9 @@ GEM iniparse (1.5.0) json (2.6.3) jwt (2.7.1) - language_server-protocol (3.17.0.3) - mini_portile2 (2.8.5) - nokogiri (1.15.4) - mini_portile2 (~> 2.8.2) + nokogiri (1.15.5-arm64-darwin) + racc (~> 1.4) + nokogiri (1.15.5-x86_64-darwin) racc (~> 1.4) onlyoffice_pdf_parser (0.5.0) image_size (>= 2, < 4) @@ -23,7 +22,7 @@ GEM ooxml_decrypt (1.0.0) nokogiri (~> 1.10) ruby-ole (~> 1.2) - ooxml_parser (0.37.1) + ooxml_parser (0.34.2) nokogiri (~> 1) ooxml_decrypt (~> 1) rubyzip (~> 2) @@ -32,7 +31,7 @@ GEM iniparse (~> 1.4) rexml (~> 3.2) parallel (1.23.0) - parallel_tests (4.3.0) + parallel_tests (3.13.0) parallel parser (3.2.2.4) ast (~> 2.4.1) @@ -64,32 +63,25 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) - rubocop (1.57.2) + rubocop (1.50.2) json (~> 2.3) - language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-capybara (2.19.0) - rubocop (~> 1.41) - rubocop-factory_bot (2.24.0) - rubocop (~> 1.33) - rubocop-performance (1.19.1) + rubocop-performance (1.17.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.25.0) - rubocop (~> 1.40) - rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) + rubocop-rspec (2.17.1) + rubocop (~> 1.33) ruby-ole (1.2.12.2) ruby-progressbar (1.13.0) ruby-rc4 (0.1.5) @@ -100,7 +92,7 @@ GEM yard (0.9.34) PLATFORMS - ruby + universal-darwin-23 DEPENDENCIES jwt diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 61bb1493..5d843737 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -1,46 +1,28 @@ +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 oRGBColor = Api.CreateRGBColor(255, 164, 101); -var oGs1 = Api.CreateGradientStop(Api.CreatePresetColor("lightYellow"), 0); -var oGs2 = Api.CreateGradientStop(oRGBColor, 100000); -var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]); -var oStroke = Api.CreateStroke(0, Api.CreateNoFill()); -var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); -// Добавляем прямоугольную форму в параграф -oParagraph.AddDrawing(oDrawing); -// Получаем тип класса цвета -var oClassType = oRGBColor.GetClassType(); -// Создаем новый параграф и добавляем в него информацию о классе цвета -var oNewParagraph = Api.CreateParagraph(); -oNewParagraph.AddText("Class Type = " + oClassType); -// Добавляем новый параграф в документ -oDocument.Push(oNewParagraph); -// Преобразуем в JSON -var json = oDocument.ToJSON(false, false, false, false, false, false); -GlobalVariable["JSON"] = json; +var json = GlobalVariable["RGBColorJSON"]; +var oRGBColorFromJSON = Api.FromJSON(json); +oRGBColorFromJSON.SetDefaultStyle(); +oParagraph.AddElement(oRGBColorFromJSON); +var oParagraph1 = Api.CreateParagraph(); +oDocument.Push(oParagraph1); +oParagraph1.AddText(json); +builder.SaveFile("docx", "RGBColorDocument.docx"); builder.CloseFile(); -///////////////////////// -builder.CreateFile("docx"); -var oDocument = Api.GetDocument(); -// Получаем JSON из глобальной переменной -var json = GlobalVariable["JSON"]; -// Создаем первый параграф и добавляем текст из JSON в него -var oFirstParagraph = Api.CreateParagraph(); -oFirstParagraph.AddText(json); -// Добавляем первый параграф в документ -oDocument.Push(oFirstParagraph); -// Создаем новый параграф из JSON -var oParagraphFromJSON = Api.CreateParagraph(); -oParagraphFromJSON.FromJSON(json); -// Добавляем новый параграф с текстом из JSON в документ -oDocument.Push(oParagraphFromJSON); -// Сохраняем результат в файл -builder.SaveFile("docx", "RGBToJSON.docx"); -builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 7d64755b..ea24149b 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -8,12 +8,14 @@ end + it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor') - json = JSON.parse(docx.elements[0].nonempty_runs.first.text) - color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] - expected_color = [255, 164, 101] # Укажите ожидаемый цвет в формате RGBA - expect(color_from_json).to eq(expected_color) + 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) end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c39a5335..d6f40ff7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,12 +10,17 @@ # @return [WebDocBuilderWrapper, DocBuilderWrapper] def builder @builder ||= if web_builder? - WebDocBuilderWrapper.new + WebDocBuilderWrapper.new( + jwt_key: 'h6DwLNlgK0ALVDvW8V8FfNJK8NSH6AiZ', + jwt_header: 'Authorization', + documentserver_path: 'http://192.168.100.2' + ) else DocBuilderWrapper.new end end + # @return [String] which platform is used to run builder tests def builder_platform ENV.fetch('BUILDER_PLATFORM', 'DESKTOP') From 7a96616c5b22550ec417f90dee28a7d6f5c79758 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Fri, 24 Nov 2023 11:56:28 +0100 Subject: [PATCH 09/19] ref: ApiRGBColor.ToJSON --- js/docx/smoke/api_rgb_color/to_json.js | 56 +++++++++----------------- spec/docx/smoke/api_rgb_color_spec.rb | 12 +++--- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 61bb1493..5d843737 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -1,46 +1,28 @@ +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 oRGBColor = Api.CreateRGBColor(255, 164, 101); -var oGs1 = Api.CreateGradientStop(Api.CreatePresetColor("lightYellow"), 0); -var oGs2 = Api.CreateGradientStop(oRGBColor, 100000); -var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]); -var oStroke = Api.CreateStroke(0, Api.CreateNoFill()); -var oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); -// Добавляем прямоугольную форму в параграф -oParagraph.AddDrawing(oDrawing); -// Получаем тип класса цвета -var oClassType = oRGBColor.GetClassType(); -// Создаем новый параграф и добавляем в него информацию о классе цвета -var oNewParagraph = Api.CreateParagraph(); -oNewParagraph.AddText("Class Type = " + oClassType); -// Добавляем новый параграф в документ -oDocument.Push(oNewParagraph); -// Преобразуем в JSON -var json = oDocument.ToJSON(false, false, false, false, false, false); -GlobalVariable["JSON"] = json; +var json = GlobalVariable["RGBColorJSON"]; +var oRGBColorFromJSON = Api.FromJSON(json); +oRGBColorFromJSON.SetDefaultStyle(); +oParagraph.AddElement(oRGBColorFromJSON); +var oParagraph1 = Api.CreateParagraph(); +oDocument.Push(oParagraph1); +oParagraph1.AddText(json); +builder.SaveFile("docx", "RGBColorDocument.docx"); builder.CloseFile(); -///////////////////////// -builder.CreateFile("docx"); -var oDocument = Api.GetDocument(); -// Получаем JSON из глобальной переменной -var json = GlobalVariable["JSON"]; -// Создаем первый параграф и добавляем текст из JSON в него -var oFirstParagraph = Api.CreateParagraph(); -oFirstParagraph.AddText(json); -// Добавляем первый параграф в документ -oDocument.Push(oFirstParagraph); -// Создаем новый параграф из JSON -var oParagraphFromJSON = Api.CreateParagraph(); -oParagraphFromJSON.FromJSON(json); -// Добавляем новый параграф с текстом из JSON в документ -oDocument.Push(oParagraphFromJSON); -// Сохраняем результат в файл -builder.SaveFile("docx", "RGBToJSON.docx"); -builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 7d64755b..ea24149b 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -8,12 +8,14 @@ end + it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = rgbColor') - json = JSON.parse(docx.elements[0].nonempty_runs.first.text) - color_from_json = json['graphic']['spPr']['fill']['fill']['gsLst'][1]['color']['color']['rgba'] - expected_color = [255, 164, 101] # Укажите ожидаемый цвет в формате RGBA - expect(color_from_json).to eq(expected_color) + 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) end + end From 82aab4542c2c0051dfa3fb4fce8d778fdb6606fc Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 08:52:23 +0100 Subject: [PATCH 10/19] Revert "Merge branch 'fork/all_object_to_json' of https://github.com/ONLYOFFICE/doc-builder-testing into fork/all_object_to_json" This reverts commit f79d965598ccfa93ae2dac37ed08baa74266780a, reversing changes made to 7a96616c5b22550ec417f90dee28a7d6f5c79758. --- Gemfile.lock | 32 ++++++++++++++++++++------------ spec/spec_helper.rb | 7 +------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index dcd9a753..3bcfe7aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,9 +11,10 @@ GEM iniparse (1.5.0) json (2.6.3) jwt (2.7.1) - nokogiri (1.15.5-arm64-darwin) - racc (~> 1.4) - nokogiri (1.15.5-x86_64-darwin) + language_server-protocol (3.17.0.3) + mini_portile2 (2.8.5) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) racc (~> 1.4) onlyoffice_pdf_parser (0.5.0) image_size (>= 2, < 4) @@ -22,7 +23,7 @@ GEM ooxml_decrypt (1.0.0) nokogiri (~> 1.10) ruby-ole (~> 1.2) - ooxml_parser (0.34.2) + ooxml_parser (0.37.1) nokogiri (~> 1) ooxml_decrypt (~> 1) rubyzip (~> 2) @@ -31,7 +32,7 @@ GEM iniparse (~> 1.4) rexml (~> 3.2) parallel (1.23.0) - parallel_tests (3.13.0) + parallel_tests (4.3.0) parallel parser (3.2.2.4) ast (~> 2.4.1) @@ -63,25 +64,32 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) - rubocop (1.50.2) + rubocop (1.57.2) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-performance (1.17.1) + rubocop-capybara (2.19.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.24.0) + rubocop (~> 1.33) + rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.17.1) - rubocop (~> 1.33) + rubocop-rspec (2.25.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) ruby-ole (1.2.12.2) ruby-progressbar (1.13.0) ruby-rc4 (0.1.5) @@ -92,7 +100,7 @@ GEM yard (0.9.34) PLATFORMS - universal-darwin-23 + ruby DEPENDENCIES jwt diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d6f40ff7..c39a5335 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,17 +10,12 @@ # @return [WebDocBuilderWrapper, DocBuilderWrapper] def builder @builder ||= if web_builder? - WebDocBuilderWrapper.new( - jwt_key: 'h6DwLNlgK0ALVDvW8V8FfNJK8NSH6AiZ', - jwt_header: 'Authorization', - documentserver_path: 'http://192.168.100.2' - ) + WebDocBuilderWrapper.new else DocBuilderWrapper.new end end - # @return [String] which platform is used to run builder tests def builder_platform ENV.fetch('BUILDER_PLATFORM', 'DESKTOP') From 4aa605288bb989983e3d3bc8500b1bd6f4b09455 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 08:54:30 +0100 Subject: [PATCH 11/19] ref: ApiRGBColor.ToJSON --- js/docx/smoke/api_rgb_color/to_json.js | 44 +++++++++++--------------- spec/docx/smoke/api_rgb_color_spec.rb | 8 ++--- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 5d843737..1b99c9e2 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -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(); \ No newline at end of file diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index ea24149b..0fea5cdb 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -11,11 +11,9 @@ 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 From 9f33dc808211597393b5b6709f36768adc10a627 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 09:55:55 +0100 Subject: [PATCH 12/19] ref: ApiRGBColor.ToJSON --- js/docx/smoke/api_rgb_color/to_json.js | 44 ++++++++----------- js/docx/smoke/api_table_row_pr/to_json.js | 31 ------------- spec/docx/smoke/api_rgb_color_spec.rb | 11 ++--- .../smoke/api_table_row_properties_spec.rb | 9 ---- 4 files changed, 21 insertions(+), 74 deletions(-) delete mode 100644 js/docx/smoke/api_table_row_pr/to_json.js diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 5d843737..1b99c9e2 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -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(); \ No newline at end of file diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js deleted file mode 100644 index a5e2fc51..00000000 --- a/js/docx/smoke/api_table_row_pr/to_json.js +++ /dev/null @@ -1,31 +0,0 @@ -builder.CreateFile("docx"); -var oDocument = Api.CreateDocument(); -var oParagraph = Api.CreateParagraph(); -oParagraph.AddText("We create a 3x3 table and set the height of half an inch to all the rows:"); -oDocument.Push(oParagraph); -var oTableStyle = Api.CreateTableStyle("CustomTableStyle", "table"); -oTableStyle.SetBasedOn(Api.GetStyle("Bordered - Accent 5")); -var oTable = Api.CreateTable(3, 3); -oTable.SetWidth("percent", 100); -oTable.SetTableLook(true, true, true, true, false, false); -var oTableRowPr = oTableStyle.GetTableRowPr(); -oTableRowPr.SetHeight("atLeast", 720); -oTable.SetStyle(oTableStyle); -oDocument.Push(oTable); -builder.SaveFile("docx", "SetHeight.docx"); -builder.CloseFile(); - - - -////////////// - - -builder.CreateFile("docx"); -var newDocument = Api.CreateDocument(); -var newParagraph = newDocument.GetElement(0); -var tableJSONFromGlobal = GlobalVariable["TableJSON"]; -var tableFromJSON = Api.FromJSON(tableJSONFromGlobal); -newParagraph.AddElement(tableFromJSON); -newDocument.Push(newParagraph); -builder.SaveFile("docx", "TableFromJSON.docx"); -builder.CloseFile(); \ No newline at end of file diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index ea24149b..71a40a12 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -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 diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index 6c44abfa..b455dc31 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -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 From 31a9f5a65ca3cd605de6a9d8b43f7ea9f860df62 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 13:42:59 +0100 Subject: [PATCH 13/19] Added: creation of GlobalVariable document and rewritten test --- js/docx/smoke/api_rgb_color/to_json.js | 38 ++++++++++++++++++++------ spec/docx/smoke/api_rgb_color_spec.rb | 6 ++-- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 1b99c9e2..a46cbce7 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -2,9 +2,8 @@ builder.CreateFile("docx"); 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 jsonRGBColor = oRGBColor.ToJSON(); +oParagraph.AddText(jsonRGBColor); let oGs1 = Api.CreateGradientStop(oRGBColor, 0); let oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000); let oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000); @@ -12,9 +11,32 @@ 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); +let jsonDrawing = oDrawing.ToJSON(bWriteNumberings, bWriteStyles); +GlobalVariable["JSON_RGBColor"] = jsonRGBColor; +GlobalVariable["JSON_Drawing"] = jsonDrawing; +builder.CloseFile(); + + +///////////////////// + + +builder.CreateFile("docx"); +let oNewDocument = Api.GetDocument(); +let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; +let jsonDrawing = GlobalVariable["JSON_Drawing"]; +let oParagraphDrawing = Api.CreateParagraph(); +oParagraphDrawing.AddText(jsonDrawing); +oNewDocument.Push(oParagraphDrawing); +let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); +let oParagraphRGBColorObject = Api.CreateParagraph(); +oParagraphRGBColorObject.AddDrawing(oRGBColorFromJSON); +oNewDocument.Push(oParagraphRGBColorObject); +let oParagraphRGBColor = Api.CreateParagraph(); +oParagraphRGBColor.AddText(jsonRGBColor); +oNewDocument.Push(oParagraphRGBColor); +let oDrawingFromJSON = Api.FromJSON(jsonDrawing); +let oParagraphDrawingObject = Api.CreateParagraph(); +oParagraphDrawingObject.AddDrawing(oDrawingFromJSON); +oNewDocument.Push(oParagraphDrawingObject); builder.SaveFile("docx", "RGBColorToJSON.docx"); -builder.CloseFile(); \ No newline at end of file +builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 71a40a12..664c3a53 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -9,8 +9,8 @@ it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - 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) + first_paragraph_text = '{"rgba":{"red":0,"green":0,"blue":0,"alpha":255},"color":{"rgba":{"red":255,"green":111,"blue":61,"alpha":255},"type":"srgb"},"type":"uniColor"}' + second_paragraph_text = docx.elements[1].nonempty_runs.first.text + expect(second_paragraph_text).to include(first_paragraph_text) end end From 3d2553b1c13847c6d109ccfb87f266ab42ace443 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 13:42:59 +0100 Subject: [PATCH 14/19] creation of GlobalVariable document and rewritten test --- js/docx/smoke/api_rgb_color/to_json.js | 38 ++++++++++++++++++++------ spec/docx/smoke/api_rgb_color_spec.rb | 6 ++-- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 1b99c9e2..a46cbce7 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -2,9 +2,8 @@ builder.CreateFile("docx"); 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 jsonRGBColor = oRGBColor.ToJSON(); +oParagraph.AddText(jsonRGBColor); let oGs1 = Api.CreateGradientStop(oRGBColor, 0); let oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000); let oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000); @@ -12,9 +11,32 @@ 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); +let jsonDrawing = oDrawing.ToJSON(bWriteNumberings, bWriteStyles); +GlobalVariable["JSON_RGBColor"] = jsonRGBColor; +GlobalVariable["JSON_Drawing"] = jsonDrawing; +builder.CloseFile(); + + +///////////////////// + + +builder.CreateFile("docx"); +let oNewDocument = Api.GetDocument(); +let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; +let jsonDrawing = GlobalVariable["JSON_Drawing"]; +let oParagraphDrawing = Api.CreateParagraph(); +oParagraphDrawing.AddText(jsonDrawing); +oNewDocument.Push(oParagraphDrawing); +let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); +let oParagraphRGBColorObject = Api.CreateParagraph(); +oParagraphRGBColorObject.AddDrawing(oRGBColorFromJSON); +oNewDocument.Push(oParagraphRGBColorObject); +let oParagraphRGBColor = Api.CreateParagraph(); +oParagraphRGBColor.AddText(jsonRGBColor); +oNewDocument.Push(oParagraphRGBColor); +let oDrawingFromJSON = Api.FromJSON(jsonDrawing); +let oParagraphDrawingObject = Api.CreateParagraph(); +oParagraphDrawingObject.AddDrawing(oDrawingFromJSON); +oNewDocument.Push(oParagraphDrawingObject); builder.SaveFile("docx", "RGBColorToJSON.docx"); -builder.CloseFile(); \ No newline at end of file +builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 71a40a12..664c3a53 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -9,8 +9,8 @@ it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - 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) + first_paragraph_text = '{"rgba":{"red":0,"green":0,"blue":0,"alpha":255},"color":{"rgba":{"red":255,"green":111,"blue":61,"alpha":255},"type":"srgb"},"type":"uniColor"}' + second_paragraph_text = docx.elements[1].nonempty_runs.first.text + expect(second_paragraph_text).to include(first_paragraph_text) end end From f22a1610f4819d454c10be2bf531279ab776ac79 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 14:32:28 +0100 Subject: [PATCH 15/19] fix to_json --- js/docx/smoke/api_rgb_color/to_json.js | 38 ++++++++++++++------------ spec/docx/smoke/api_rgb_color_spec.rb | 4 +-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index a46cbce7..d72fa7ec 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -4,16 +4,7 @@ let oParagraph = oDocument.GetElement(0); let oRGBColor = Api.CreateRGBColor(255, 111, 61); let jsonRGBColor = oRGBColor.ToJSON(); oParagraph.AddText(jsonRGBColor); -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 jsonDrawing = oDrawing.ToJSON(bWriteNumberings, bWriteStyles); GlobalVariable["JSON_RGBColor"] = jsonRGBColor; -GlobalVariable["JSON_Drawing"] = jsonDrawing; builder.CloseFile(); @@ -23,20 +14,31 @@ builder.CloseFile(); builder.CreateFile("docx"); let oNewDocument = Api.GetDocument(); let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; -let jsonDrawing = GlobalVariable["JSON_Drawing"]; -let oParagraphDrawing = Api.CreateParagraph(); -oParagraphDrawing.AddText(jsonDrawing); -oNewDocument.Push(oParagraphDrawing); +let oParagraphRGBColor = oNewDocument.GetElement(0); +oParagraphRGBColor.AddText(jsonRGBColor); + let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); let oParagraphRGBColorObject = Api.CreateParagraph(); oParagraphRGBColorObject.AddDrawing(oRGBColorFromJSON); oNewDocument.Push(oParagraphRGBColorObject); -let oParagraphRGBColor = Api.CreateParagraph(); -oParagraphRGBColor.AddText(jsonRGBColor); -oNewDocument.Push(oParagraphRGBColor); -let oDrawingFromJSON = Api.FromJSON(jsonDrawing); + +let oGs1 = Api.CreateGradientStop(oRGBColorFromJSON, 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 oDrawingFromJSON = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); +let bWriteNumberings = false; +let bWriteStyles = true; +let jsonDrawingFromJSON = oDrawingFromJSON.ToJSON(bWriteNumberings, bWriteStyles); + +let oParagraphDrawing = Api.CreateParagraph(); +oParagraphDrawing.AddText(jsonDrawingFromJSON); +oNewDocument.Push(oParagraphDrawing); + +let oDrawingFromJSONObj = Api.FromJSON(jsonDrawingFromJSON); let oParagraphDrawingObject = Api.CreateParagraph(); -oParagraphDrawingObject.AddDrawing(oDrawingFromJSON); +oParagraphDrawingObject.AddDrawing(oDrawingFromJSONObj); oNewDocument.Push(oParagraphDrawingObject); + builder.SaveFile("docx", "RGBColorToJSON.docx"); builder.CloseFile(); diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index 664c3a53..da64bd20 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -10,7 +10,7 @@ it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') first_paragraph_text = '{"rgba":{"red":0,"green":0,"blue":0,"alpha":255},"color":{"rgba":{"red":255,"green":111,"blue":61,"alpha":255},"type":"srgb"},"type":"uniColor"}' - second_paragraph_text = docx.elements[1].nonempty_runs.first.text - expect(second_paragraph_text).to include(first_paragraph_text) + third_paragraph_text = docx.elements[2].nonempty_runs.first.text + expect(third_paragraph_text).to include(first_paragraph_text) end end From 9244aa2c68c42e3821d9f5c18d21b7ed1a122192 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Mon, 27 Nov 2023 15:22:23 +0100 Subject: [PATCH 16/19] fix to_json --- js/docx/smoke/api_rgb_color/to_json.js | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index d72fa7ec..8d5d80d8 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -1,9 +1,9 @@ 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); + 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(); @@ -12,33 +12,33 @@ builder.CloseFile(); builder.CreateFile("docx"); -let oNewDocument = Api.GetDocument(); -let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; -let oParagraphRGBColor = oNewDocument.GetElement(0); -oParagraphRGBColor.AddText(jsonRGBColor); - -let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); -let oParagraphRGBColorObject = Api.CreateParagraph(); -oParagraphRGBColorObject.AddDrawing(oRGBColorFromJSON); -oNewDocument.Push(oParagraphRGBColorObject); - -let oGs1 = Api.CreateGradientStop(oRGBColorFromJSON, 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 oDrawingFromJSON = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); -let bWriteNumberings = false; -let bWriteStyles = true; -let jsonDrawingFromJSON = oDrawingFromJSON.ToJSON(bWriteNumberings, bWriteStyles); - -let oParagraphDrawing = Api.CreateParagraph(); -oParagraphDrawing.AddText(jsonDrawingFromJSON); -oNewDocument.Push(oParagraphDrawing); - -let oDrawingFromJSONObj = Api.FromJSON(jsonDrawingFromJSON); -let oParagraphDrawingObject = Api.CreateParagraph(); -oParagraphDrawingObject.AddDrawing(oDrawingFromJSONObj); -oNewDocument.Push(oParagraphDrawingObject); + let oNewDocument = Api.GetDocument(); + let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; + let oParagraphRGBColor = oNewDocument.GetElement(0); + oParagraphRGBColor.AddText(jsonRGBColor); + + let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); + let oParagraphRGBColorObject = Api.CreateParagraph(); + oParagraphRGBColorObject.AddDrawing(oRGBColorFromJSON); + oNewDocument.Push(oParagraphRGBColorObject); + + let oGs1 = Api.CreateGradientStop(oRGBColorFromJSON, 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 oDrawingFromJSON = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); + let bWriteNumberings = false; + let bWriteStyles = true; + let jsonDrawingFromJSON = oDrawingFromJSON.ToJSON(bWriteNumberings, bWriteStyles); + + let oParagraphDrawing = Api.CreateParagraph(); + oParagraphDrawing.AddText(jsonDrawingFromJSON); + oNewDocument.Push(oParagraphDrawing); + + let oDrawingFromJSONObj = Api.FromJSON(jsonDrawingFromJSON); + let oParagraphDrawingObject = Api.CreateParagraph(); + oParagraphDrawingObject.AddDrawing(oDrawingFromJSONObj); + oNewDocument.Push(oParagraphDrawingObject); builder.SaveFile("docx", "RGBColorToJSON.docx"); builder.CloseFile(); From 6ae2b432d46fea2ef33b0e1dcf2346cbf1a0c7e7 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Tue, 28 Nov 2023 10:25:14 +0100 Subject: [PATCH 17/19] feature: ApiTableRowPr.ToJSON --- js/docx/smoke/api_table_row_pr/to_json.js | 38 +++++++++++++++++++ .../smoke/api_table_row_properties_spec.rb | 9 +++++ 2 files changed, 47 insertions(+) create mode 100644 js/docx/smoke/api_table_row_pr/to_json.js diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js new file mode 100644 index 00000000..ab28378f --- /dev/null +++ b/js/docx/smoke/api_table_row_pr/to_json.js @@ -0,0 +1,38 @@ +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetName("My Custom Table Style"); + let oTableRowPr = oTableStyle.GetTableRowPr(); + oTableRowPr.SetHeight("atLeast", 720); + let jsonTableStyle = oTableStyle.ToJSON(); + GlobalVariable["JSON_TableStyle"] = jsonTableStyle; + oParagraph.AddText(jsonTableStyle); +builder.CloseFile(); + + +///////////////// + + +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let jsonTableStyle = GlobalVariable["JSON_TableStyle"]; + oParagraph.AddText(jsonTableStyle); + let oTableStyleFromJSON = Api.FromJSON(jsonTableStyle); + oDocument.Push(oTableStyleFromJSON); + let oParagraph2 = Api.CreateParagraph(); + oDocument.Push(oParagraph2); + let oTableStyle = oDocument.GetStyle("My Custom Table Style"); + let oTable = Api.CreateTable(3, 3); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + let jsonTable = oTableStyle.ToJSON(); + let oParagraph3 = Api.CreateParagraph(); + oDocument.Push(oParagraph3); + oParagraph3.AddText(jsonTable); + oParagraph2.AddText(jsonTable); +builder.SaveFile("docx", "TableStyleToJSON.docx"); +builder.CloseFile(); + + + diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b455dc31..803ab264 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -16,4 +16,13 @@ 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 = docx.elements[1].nonempty_runs.map(&:text).join + parsed_json = JSON.parse(json) + expect(parsed_json).to include('name' => 'My Custom Table Style') + end + + end From 3cd6c5bbf62e7594f95d43b334d5bfd3c85dbf53 Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Tue, 28 Nov 2023 10:25:14 +0100 Subject: [PATCH 18/19] feature: ApiTableRowPr.ToJSON --- js/docx/smoke/api_table_row_pr/to_json.js | 36 +++++++++++++++++++ .../smoke/api_table_row_properties_spec.rb | 7 ++++ 2 files changed, 43 insertions(+) create mode 100644 js/docx/smoke/api_table_row_pr/to_json.js diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js new file mode 100644 index 00000000..b4aa8166 --- /dev/null +++ b/js/docx/smoke/api_table_row_pr/to_json.js @@ -0,0 +1,36 @@ +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetName("My Custom Table Style"); + let oTableRowPr = oTableStyle.GetTableRowPr(); + oTableRowPr.SetHeight("atLeast", 720); + let jsonTableStyle = oTableStyle.ToJSON(); + GlobalVariable["JSON_TableStyle"] = jsonTableStyle; + oParagraph.AddText(jsonTableStyle); +builder.CloseFile(); + + +///////////////// + + +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let jsonTableStyle = GlobalVariable["JSON_TableStyle"]; + oParagraph.AddText(jsonTableStyle); + let oTableStyleFromJSON = Api.FromJSON(jsonTableStyle); + oDocument.Push(oTableStyleFromJSON); + let oParagraph2 = Api.CreateParagraph(); + oDocument.Push(oParagraph2); + let oTableStyle = oDocument.GetStyle("My Custom Table Style"); + let oTable = Api.CreateTable(3, 3); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + let jsonTable = oTableStyle.ToJSON(); + let oParagraph3 = Api.CreateParagraph(); + oDocument.Push(oParagraph3); + oParagraph3.AddText(jsonTable); + oParagraph2.AddText(jsonTable); +builder.SaveFile("docx", "TableStyleToJSON.docx"); +builder.CloseFile(); \ No newline at end of file diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b455dc31..6bfe1754 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -16,4 +16,11 @@ 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 = docx.elements[1].nonempty_runs.map(&:text).join + parsed_json = JSON.parse(json) + expect(parsed_json).to include('name' => 'My Custom Table Style') + end end From ad1d4e0cf9af5feec598b5b77f3477049774747b Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Tue, 28 Nov 2023 11:54:41 +0100 Subject: [PATCH 19/19] ref: ApiTableRowPr.ToJSON --- spec/docx/smoke/api_table_row_properties_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b29541cc..6bfe1754 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -22,5 +22,5 @@ json = docx.elements[1].nonempty_runs.map(&:text).join parsed_json = JSON.parse(json) expect(parsed_json).to include('name' => 'My Custom Table Style') - end + end end