Class: Template
Instance Method Summary collapse
- #bold(text) ⇒ Object
- #color(text, color) ⇒ Object
- #indent(text, length = 4) ⇒ Object
-
#initialize(globals, &block) ⇒ Template
constructor
A new instance of Template.
- #print(args) ⇒ Object
- #print_each(list) ⇒ Object
Constructor Details
#initialize(globals, &block) ⇒ Template
Returns a new instance of Template.
24 25 26 27 |
# File 'lib/template.rb', line 24 def initialize(globals, &block) @color = !globals['no-color'] @block = block end |
Instance Method Details
#bold(text) ⇒ Object
39 40 41 42 |
# File 'lib/template.rb', line 39 def bold(text) return text unless @color "<%= color('#{text}', BOLD) %>" end |
#color(text, color) ⇒ Object
44 45 46 47 |
# File 'lib/template.rb', line 44 def color(text, color) return text unless @color "<%= color('#{text}', :#{color.to_s}) %>" end |
#indent(text, length = 4) ⇒ Object
49 50 51 |
# File 'lib/template.rb', line 49 def indent(text, length=4) ' '*length + wrap(text, length, 80) end |
#print(args) ⇒ Object
29 30 31 |
# File 'lib/template.rb', line 29 def print(args) say instance_exec(args, &@block) end |
#print_each(list) ⇒ Object
33 34 35 36 37 |
# File 'lib/template.rb', line 33 def print_each(list) list.each {|item| print item } end |