diff --git a/lib/notare/builder.rb b/lib/notare/builder.rb index 44d385f..35142d0 100644 --- a/lib/notare/builder.rb +++ b/lib/notare/builder.rb @@ -2,8 +2,10 @@ module Notare module Builder - def p(text = nil, style: nil, &block) - para = Nodes::Paragraph.new(style: resolve_style(style)) + def p(text = nil, style: nil, spacing_before: nil, spacing_after: nil, &block) + para = Nodes::Paragraph.new(style: resolve_style(style), + spacing_before: spacing_before, + spacing_after: spacing_after) if block with_target(para, &block) elsif text diff --git a/lib/notare/nodes/paragraph.rb b/lib/notare/nodes/paragraph.rb index ee04f47..3caef04 100644 --- a/lib/notare/nodes/paragraph.rb +++ b/lib/notare/nodes/paragraph.rb @@ -3,12 +3,14 @@ module Notare module Nodes class Paragraph < Base - attr_reader :runs, :style + attr_reader :runs, :style, :spacing_before, :spacing_after - def initialize(runs = [], style: nil) + def initialize(runs = [], style: nil, spacing_before: nil, spacing_after: nil) super() @runs = runs @style = style + @spacing_before = spacing_before + @spacing_after = spacing_after end def add_run(run) diff --git a/lib/notare/version.rb b/lib/notare/version.rb index 041d5f4..4ecec06 100644 --- a/lib/notare/version.rb +++ b/lib/notare/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Notare - VERSION = "0.0.7" + VERSION = "0.0.8" end diff --git a/lib/notare/xml/document_xml.rb b/lib/notare/xml/document_xml.rb index 5101f2b..4a3c542 100644 --- a/lib/notare/xml/document_xml.rb +++ b/lib/notare/xml/document_xml.rb @@ -52,9 +52,18 @@ module Notare def render_paragraph(xml, para) xml["w"].p do - if para.style + has_style = para.style + has_spacing = para.spacing_before || para.spacing_after + + if has_style || has_spacing xml["w"].pPr do - xml["w"].pStyle("w:val" => para.style.style_id) + xml["w"].pStyle("w:val" => para.style.style_id) if has_style + if has_spacing + spacing_attrs = {} + spacing_attrs["w:before"] = para.spacing_before.to_s if para.spacing_before + spacing_attrs["w:after"] = para.spacing_after.to_s if para.spacing_after + xml["w"].spacing(spacing_attrs) + end end end para.runs.each { |run| render_run(xml, run) }