Module: PrettyComment
- Defined in:
- lib/PrettyComment.rb
Overview
#
Defined Under Namespace
Classes: Box
Constant Summary collapse
- @@width =
TermInfo.screen_size[1]
- @@styles =
{ 'default' => { :left => '#', :right => '#' }, 'c++' => { :left => '//', :right => '//'}, 'latex' => { :left => '%', :right => '%'} }
Class Method Summary collapse
-
.comment(comment) ⇒ Object
———————————————————————————————————————-#.
-
.format_line(text, prefix, only_first_line_prefix = false, suffix = '', alternate_prefix = '', width = @@width) ⇒ Object
———————————————————————————————————————-#.
-
.h1(a_text) ⇒ Object
———————————————————————————————————————-#.
-
.h2(a_text) ⇒ Object
———————————————————————————————————————-#.
-
.h3(a_text) ⇒ Object
———————————————————————————————————————-#.
-
.heading(a_text, a_delimiter = '=') ⇒ Object
———————————————————————————————————————-#.
-
.pad_string(a_string, a_suffix, a_width) ⇒ Object
———————————————————————————————————————-#.
-
.separator(char = '=', left = '#', right = '#', width = @@width) ⇒ Object
———————————————————————————————————————-#.
-
.small_separator ⇒ Object
———————————————————————————————————————-#.
-
.styles ⇒ Object
———————————————————————————————————————-#.
-
.sub_heading(comment) ⇒ Object
———————————————————————————————————————-#.
-
.terminal_width ⇒ Object
———————————————————————————————————————-#.
-
.width ⇒ Object
#.
-
.width=(a_width) ⇒ Object
———————————————————————————————————————-#.
Class Method Details
.comment(comment) ⇒ Object
———————————————————————————————————————-#
59 60 61 |
# File 'lib/PrettyComment.rb', line 59 def self.comment(comment) pad_string("\# #{comment}", "#", width) end |
.format_line(text, prefix, only_first_line_prefix = false, suffix = '', alternate_prefix = '', width = @@width) ⇒ Object
———————————————————————————————————————-#
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/PrettyComment.rb', line 80 def self.format_line(text, prefix, only_first_line_prefix=false, suffix='', alternate_prefix='', width=@@width) the_suffix = suffix.length ? " " + suffix : "" text_width = width - 1 - the_suffix.length title_array = text.split(" ") result = [] current_line = prefix.dup current_prefix = only_first_line_prefix \ ? alternate_prefix + " " * (prefix.length - alternate_prefix.length) \ : prefix.dup title_array.each do |w| (current_line.length + w.length + 1 > text_width) \ && result << pad_string(current_line, suffix, width) \ && current_line = current_prefix.dup current_line << " " << w end current_line.length > current_prefix.length && result << pad_string(current_line, suffix, width) result.join("\n") end |
.h1(a_text) ⇒ Object
———————————————————————————————————————-#
112 113 114 |
# File 'lib/PrettyComment.rb', line 112 def self.h1(a_text) self.heading(a_text, '#') end |
.h2(a_text) ⇒ Object
———————————————————————————————————————-#
119 120 121 |
# File 'lib/PrettyComment.rb', line 119 def self.h2(a_text) self.heading(a_text, '=') end |
.h3(a_text) ⇒ Object
———————————————————————————————————————-#
126 127 128 |
# File 'lib/PrettyComment.rb', line 126 def self.h3(a_text) self.heading(a_text, '-') end |
.heading(a_text, a_delimiter = '=') ⇒ Object
———————————————————————————————————————-#
105 106 107 |
# File 'lib/PrettyComment.rb', line 105 def self.heading(a_text, a_delimiter = '=') Box.new { self.top = self.bottom = a_delimiter; para a_text}.to_s end |
.pad_string(a_string, a_suffix, a_width) ⇒ Object
———————————————————————————————————————-#
73 74 75 |
# File 'lib/PrettyComment.rb', line 73 def self.pad_string(a_string, a_suffix, a_width) a_suffix.length ? a_string + " " * (a_width - a_string.length - a_suffix.length) + a_suffix : a_string.dup end |
.separator(char = '=', left = '#', right = '#', width = @@width) ⇒ Object
———————————————————————————————————————-#
45 46 47 |
# File 'lib/PrettyComment.rb', line 45 def self.separator(char='=', left='#', right='#', width=@@width) left + (char * (width - left.length - right.length)) + right end |
.small_separator ⇒ Object
———————————————————————————————————————-#
52 53 54 |
# File 'lib/PrettyComment.rb', line 52 def self.small_separator separator ('-') end |
.styles ⇒ Object
———————————————————————————————————————-#
31 32 33 |
# File 'lib/PrettyComment.rb', line 31 def self.styles @@styles end |
.sub_heading(comment) ⇒ Object
———————————————————————————————————————-#
66 67 68 |
# File 'lib/PrettyComment.rb', line 66 def self.sub_heading(comment) [comment(""), small_separator, comment(comment), small_separator].join("\n") end |
.terminal_width ⇒ Object
———————————————————————————————————————-#
38 39 40 |
# File 'lib/PrettyComment.rb', line 38 def self.terminal_width TermInfo.screen_size[1] end |
.width ⇒ Object
#
17 18 19 |
# File 'lib/PrettyComment.rb', line 17 def self.width @@width end |
.width=(a_width) ⇒ Object
———————————————————————————————————————-#
24 25 26 |
# File 'lib/PrettyComment.rb', line 24 def self.width=(a_width) @@width = a_width end |