Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds .keep_next paragraph property. #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
3 changes: 2 additions & 1 deletion lib/caracal/core/models/paragraph_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/caracal/renderers/document_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/caracal/core/models/paragraph_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
italic false
underline true
bgcolor 'cccccc'
keep_next true
end
end

Expand All @@ -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
Expand Down Expand Up @@ -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) }

Expand Down