Permalink
Browse files

Truncate text in align_right that is longer than allowed width

Closes gh-147
  • Loading branch information...
1 parent 6eda815 commit f0da9cd49b2bfd902df19413426bae6dd92968d0 @cldwalker cldwalker committed with lsegal Jun 27, 2010
Showing with 13 additions and 0 deletions.
  1. +1 −0 lib/yard/templates/helpers/text_helper.rb
  2. +12 −0 spec/templates/helpers/text_helper_spec.rb
@@ -29,6 +29,7 @@ def title_align_right(text, col = 72)
end
def align_right(text, spacer = ' ', col = 72)
+ text = text[0, col - 4] + '...' if (col - 1 - text.length) < 0
spacer * (col - 1 - text.length) + " " + text
end
@@ -28,4 +28,16 @@ def signature(obj) super(obj).strip end
it_should_behave_like "signature"
end
+
+ describe '#align_right' do
+ it "should align text right" do
+ text = "Method: #some_method (SomeClass)"
+ align_right(text).should == ' ' * 40 + text
+ end
+
+ it "should truncate text that is longer than allowed width" do
+ text = "(Defined in: /home/user/.rip/.packages/some_gem-2460672e333ac07b9190ade88ec9a91c/long/path.rb)"
+ align_right(text).should == ' ' + text[0,68] + '...'
+ end
+ end
end

0 comments on commit f0da9cd

Please sign in to comment.