Skip to content

Commit

Permalink
remove trailing linefeed from wordwrap filter
Browse files Browse the repository at this point in the history
  • Loading branch information
whoward committed Dec 15, 2012
1 parent d061a5d commit a24b9c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/cadenza/filters/standard_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
define_filter :wordwrap do |input, params|
length = params[0]
linefeed = params[1] || "\n"
input.gsub(/(.{1,#{length}})(\s+|\Z)/, "\\1#{linefeed}")
input.gsub(/(.{1,#{length}})(\s+|\Z)/, "\\1\n").strip.gsub(/\n/, linefeed)
end

# returns the string or array reversed
Expand Down
4 changes: 2 additions & 2 deletions spec/filters/standard_filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@
it "should return the string with the words wrapped at the given column" do
wrapped = subject.evaluate_filter(:wordwrap, "This text is not too short to be wrapped.", [20])

wrapped.should == "This text is not too\nshort to be wrapped.\n"
wrapped.should == "This text is not too\nshort to be wrapped."
end

it "should allow specifying the character(s) used for line endings" do
wrapped = subject.evaluate_filter(:wordwrap, "This text is not too short to be wrapped.", [20, "<br/>"])

wrapped.should == "This text is not too<br/>short to be wrapped.<br/>"
wrapped.should == "This text is not too<br/>short to be wrapped."
end
end

Expand Down

0 comments on commit a24b9c3

Please sign in to comment.