diff --git a/README.md b/README.md index 56f19204..c95c16fb 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,7 @@ docx.p 'Sample text.' do bgcolor 'cccccc' # sets the background color. highlight_color 'yellow' # sets the highlight color. only accepts OOXML enumerations. see http://www.datypic.com/sc/ooxml/t-w_ST_HighlightColor.html. vertical_align 'superscript' # sets the vertical alignment. + keep_next false # sets whether or not to keep this paragraph with the next paragraph when separated by page break. end ``` diff --git a/lib/caracal/core/models/paragraph_model.rb b/lib/caracal/core/models/paragraph_model.rb index 5eef1254..3b319e03 100644 --- a/lib/caracal/core/models/paragraph_model.rb +++ b/lib/caracal/core/models/paragraph_model.rb @@ -27,6 +27,7 @@ class ParagraphModel < BaseModel attr_reader :paragraph_italic attr_reader :paragraph_underline attr_reader :paragraph_bgcolor + attr_reader :paragraph_keep_next # initialization def initialize(options={}, &block) @@ -63,7 +64,7 @@ def run_attributes #========== SETTERS =============================== # booleans - [:bold, :italic, :underline].each do |m| + [:bold, :italic, :keep_next, :underline].each do |m| define_method "#{ m }" do |value| instance_variable_set("@paragraph_#{ m }", !!value) end diff --git a/lib/caracal/renderers/document_renderer.rb b/lib/caracal/renderers/document_renderer.rb index 5b14b3fb..7948427a 100644 --- a/lib/caracal/renderers/document_renderer.rb +++ b/lib/caracal/renderers/document_renderer.rb @@ -275,6 +275,7 @@ def render_paragraph(xml, model) xml['w'].pStyle({ 'w:val' => model.paragraph_style }) unless model.paragraph_style.nil? xml['w'].contextualSpacing({ 'w:val' => '0' }) xml['w'].jc({ 'w:val' => model.paragraph_align }) unless model.paragraph_align.nil? + xml['w'].keepNext if model.paragraph_keep_next == true render_run_attributes(xml, model, true) end model.runs.each do |run| diff --git a/spec/lib/caracal/core/models/paragraph_model_spec.rb b/spec/lib/caracal/core/models/paragraph_model_spec.rb index c70f803e..ba90a680 100644 --- a/spec/lib/caracal/core/models/paragraph_model_spec.rb +++ b/spec/lib/caracal/core/models/paragraph_model_spec.rb @@ -11,6 +11,7 @@ italic false underline true bgcolor 'cccccc' + keep_next true end end @@ -31,6 +32,7 @@ it { expect(subject.paragraph_italic).to eq false } it { expect(subject.paragraph_underline).to eq true } it { expect(subject.paragraph_bgcolor).to eq 'cccccc' } + it { expect(subject.paragraph_keep_next).to eq true } end end @@ -70,6 +72,11 @@ it { expect(subject.paragraph_italic).to eq true } end + describe '.keep_next' do + before { subject.keep_next(true) } + + it { expect(subject.paragraph_keep_next).to eq true } + end describe '.underline' do before { subject.underline(true) }