From dbac211a7727e906fb6294e721fad053a62e0066 Mon Sep 17 00:00:00 2001 From: miko53 Date: Sat, 29 Jul 2023 18:17:04 +0200 Subject: [PATCH 1/4] fix error on properties tag, now it returns the property of paragrah --- lib/docx/containers/container.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/docx/containers/container.rb b/lib/docx/containers/container.rb index 8764d70..510bb9b 100644 --- a/lib/docx/containers/container.rb +++ b/lib/docx/containers/container.rb @@ -7,12 +7,12 @@ module Container # Relation methods # TODO: Create a properties object, include Element def properties - @node.at_xpath("./#{@properties_tag}") + @node.at_xpath("./w:#{@properties_tag}") end # Erase text within an element def blank! - @node.xpath(".//w:t").each {|t| t.content = '' } + @node.xpath('.//w:t').each { |t| t.content = '' } end def remove! From a930ea2e9bd9ae05e54b3f0b9eda8bc86783b4e8 Mon Sep 17 00:00:00 2001 From: miko53 Date: Sun, 30 Jul 2023 17:30:45 +0200 Subject: [PATCH 2/4] add method to read the paragraph style --- lib/docx/containers/paragraph.rb | 21 +++++++++++++++++++-- lib/docx/document.rb | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/docx/containers/paragraph.rb b/lib/docx/containers/paragraph.rb index 4e0338e..2fd7eec 100755 --- a/lib/docx/containers/paragraph.rb +++ b/lib/docx/containers/paragraph.rb @@ -22,6 +22,10 @@ def initialize(node, document_properties = {}) @font_size = @document_properties[:font_size] end + def document=(doc) + @document = doc + end + # Set text of paragraph def text=(content) if text_runs.size == 1 @@ -79,17 +83,30 @@ def font_size size_tag = @node.xpath('w:pPr//w:sz').first size_tag ? size_tag.attributes['val'].value.to_i / 2 : @font_size end - + + def style + return nil unless @document + + if style_property.nil? + @document.default_paragraph_style + else + @document.style_name(style_property.attributes['val'].value) + end + end + alias_method :text, :to_s private + def style_property + properties&.at_xpath('w:pStyle') + end + # Returns the alignment if any, or nil if left def alignment alignment_tag = @node.xpath('.//w:jc').first alignment_tag ? alignment_tag.attributes['val'].value : nil end - end end end diff --git a/lib/docx/document.rb b/lib/docx/document.rb index f4ae3f0..de67206 100755 --- a/lib/docx/document.rb +++ b/lib/docx/document.rb @@ -168,6 +168,18 @@ def replace_entry(entry_path, file_contents) @replace[entry_path] = file_contents end + def default_paragraph_style + s = @styles.at_xpath("w:styles/w:style[@w:type='paragraph' and @w:default='1']") + s = s.at_xpath('w:name') + s.attributes['val'].value + end + + def style_name(style_id) + s = @styles.at_xpath("w:styles/w:style[@w:styleId='#{style_id}']") + s = s.at_xpath('w:name') + s.attributes['val'].value + end + private def load_styles @@ -198,7 +210,9 @@ def update # generate Elements::Containers::Paragraph from paragraph XML node def parse_paragraph_from(p_node) - Elements::Containers::Paragraph.new(p_node, document_properties) + p = Elements::Containers::Paragraph.new(p_node, document_properties) + p.document = self + p end # generate Elements::Bookmark from bookmark XML node From 4e459b01fcdc1872ea6413316c7332d6e8477a28 Mon Sep 17 00:00:00 2001 From: miko53 Date: Sun, 30 Jul 2023 18:17:34 +0200 Subject: [PATCH 3/4] add test for style API --- spec/docx/document_spec.rb | 18 ++++++++++++++++++ spec/fixtures/test_with_style.docx | Bin 0 -> 21180 bytes 2 files changed, 18 insertions(+) create mode 100755 spec/fixtures/test_with_style.docx diff --git a/spec/docx/document_spec.rb b/spec/docx/document_spec.rb index 00bd63f..760e6a7 100755 --- a/spec/docx/document_spec.rb +++ b/spec/docx/document_spec.rb @@ -504,4 +504,22 @@ expect(doc.to_s).to be_a(String) end end + + describe 'reading style' do + before do + @doc = Docx::Document.open(@fixtures_path + '/test_with_style.docx') + end + + it 'read default style when not' do + nb = @doc.paragraphs.size + expect(nb).to eq 6 + expect(@doc.paragraphs[0].style).to eq 'Normal' + expect(@doc.paragraphs[1].style).to eq 'STYLE1' + expect(@doc.paragraphs[2].style).to eq 'heading 1' + expect(@doc.paragraphs[3].style).to eq 'Normal' + expect(@doc.paragraphs[4].style).to eq 'Normal' + expect(@doc.paragraphs[5].style).to eq 'STYLE1' + end + end + end diff --git a/spec/fixtures/test_with_style.docx b/spec/fixtures/test_with_style.docx new file mode 100755 index 0000000000000000000000000000000000000000..02edfc0690e30531b52914552a219cc542b0879d GIT binary patch literal 21180 zcmeHvWpo@#vTlo+nZaUamc`7>WHB={Gs^;tnZaUaS=CGpB}T?tLOgMC!xfi1H;Ke0J=F^KYHZcf)QARdu$&kHebdXtY3xxU7A&VwAuVg* z#PAV$y{86T=0}q1bdPy~8 z!pbefm*yrfaHI^KDe|K5AV;n2*wLe?peS1xDyT^VDc>loqB1a)vG7v9@63`&kQu1y zm1&rgxXCfoUzuT03KuoKB0OF+PxNGOh!n0wK?qYF_VQP*ni)W4pJ%q*6Rn$(FoHMq z(770rubBbY9}V@XwoD5`3;G{tZwQdCCh#?5cCA*(K2`^5U2z|Fk#=Fvo(3Om0CoL* z4k!QUc-SjI`;PlT5_07Jn9>~28B#D7&b%-?eD*qhdwWP%E@ZJ3(06j5Z6ZeUBk?Kl zN;QZ7QJN?@6!ygmSix($(77;KI!n_k^$k1Al^;Xt$T)HTDuMCPY)QzcK}G+|N5&KsMMx1*5PWvc zOq-j#dNYloI7ABq_w|DhjO6t^2N6Z#1nKMqa9^sgGRA*$THnxxH@#IHFke>&CB|xW zf&3?N87Qkw=YLm(ybu5YE&vk9)z-m?{tuZkvNd$Je%Fb=DZ_ut574_te82jC_ox2z zs7>H+8sYOJ!qC$vLhDC)X*QKYE3HQ$czk@SrJ<~k_fMJvL#P`fMxN zjZmHZ>6#Lv+YH1&L)zh*$x-d5^y~;E3`2#R(Fxt+2q9Lp$K~VHEV!pcO7odeRv6}( zrHF0hk}|piqcSC2akmn=PNUPwtp#|Kd~Q%I;d!j{v-l*u$535pBy3es zo#7{`-mC<+qrhmB1g9E5ERqs_5W)*>M9RH>y&NG2EZ5mx@g)Tw23?F?z&)|^*F&YF z3=2E?uRej6`bC;!3uSW5ia%Ec_D7wkOAzPp=3PJ=yc*jpX9QkE_<4gU`3arY>d|*W zoK?>pKTYbvP-Apw%K63#Y7R;Oiw$r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ykqNS>W=DS}Zti46W4@Y;5WMV`491e?hJ!&0EaX!#H%?_@)+j*3qq}+d3 z>ab47^`;e3NDhD;W0UZw%(ct_l?alMhSaLtW^`Zj5?Z%=7>g?|U)S(m|JZS|p~C9q z+1sp$OjVIu!YD_vSr88u143t30!##X!rofOZKnN}DATreZ8Z29FE;LBk>lF8?uFc# zA;kfvv4Un*o~ajDniw|@56zrVQGkzDaQr}#FOWBNW!lEq>chEkD%f=m zdw^%-OfOUY)`_thEzep^15(Al#3}Z$y1{yXm9WE}QCN-wzaZfyFqKsUy(){My}B5hUcV^MqNqW=Gr9HJ@+eeW!nCi!<6>g_<9kli zA50GfO#5#6|L2lzf71AmqyJFAOmRz@qbC| z{}ugf%J83PwD-`ve~tc+WbyxZG!V+)(7#7s{lBA6-}i=p8TtY#jk+~ ze|BNW@Q*J38kX=Y{8yjkpYRlxf5QLeq5Kv6>n8qBaK6Alz`tzif9>J#o7X?_0Klmr z0PyQp_E+@Z?fk!@0iu6F|I_OK75=MD^=AjO;{TYw$$R0*e_2?+;{UFy|3m`-?UH{T d{$Gk)UJC3zDDk%!9;kqy@4+KqWq$khe*ncve6s)m literal 0 HcmV?d00001 From 8245e15e64f4a4003f4495bb89447e3fce3ecfa2 Mon Sep 17 00:00:00 2001 From: miko53 Date: Sat, 14 Oct 2023 15:41:05 +0200 Subject: [PATCH 4/4] add indent in document_spec, remove document API and pass document through paragrah constructor --- lib/docx/containers/paragraph.rb | 5 +---- lib/docx/document.rb | 4 +--- spec/docx/document_spec.rb | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/docx/containers/paragraph.rb b/lib/docx/containers/paragraph.rb index 2fd7eec..34004de 100755 --- a/lib/docx/containers/paragraph.rb +++ b/lib/docx/containers/paragraph.rb @@ -15,14 +15,11 @@ def self.tag # Child elements: pPr, r, fldSimple, hlink, subDoc # http://msdn.microsoft.com/en-us/library/office/ee364458(v=office.11).aspx - def initialize(node, document_properties = {}) + def initialize(node, document_properties = {}, doc = nil) @node = node @properties_tag = 'pPr' @document_properties = document_properties @font_size = @document_properties[:font_size] - end - - def document=(doc) @document = doc end diff --git a/lib/docx/document.rb b/lib/docx/document.rb index de67206..a3e10de 100755 --- a/lib/docx/document.rb +++ b/lib/docx/document.rb @@ -210,9 +210,7 @@ def update # generate Elements::Containers::Paragraph from paragraph XML node def parse_paragraph_from(p_node) - p = Elements::Containers::Paragraph.new(p_node, document_properties) - p.document = self - p + Elements::Containers::Paragraph.new(p_node, document_properties, self) end # generate Elements::Bookmark from bookmark XML node diff --git a/spec/docx/document_spec.rb b/spec/docx/document_spec.rb index 760e6a7..28db70f 100755 --- a/spec/docx/document_spec.rb +++ b/spec/docx/document_spec.rb @@ -507,7 +507,7 @@ describe 'reading style' do before do - @doc = Docx::Document.open(@fixtures_path + '/test_with_style.docx') + @doc = Docx::Document.open(@fixtures_path + '/test_with_style.docx') end it 'read default style when not' do