Class: Choosy::Printing::ERBPrinter

Inherits:
HelpPrinter show all
Defined in:
lib/choosy/printing/erb_printer.rb

Constant Summary

Constants included from Terminal

Terminal::DEFAULT_COLUMN_COUNT, Terminal::DEFAULT_LINE_COUNT

Instance Attribute Summary collapse

Attributes inherited from HelpPrinter

#buffer, #line_count, #usage

Attributes inherited from BasePrinter

#formatting_options, #heading_styles, #indent, #offset, #option_styles

Attributes included from Terminal

#columns, #lines

Instance Method Summary collapse

Methods inherited from HelpPrinter

#format_command, #format_element, #format_epilogue, #format_header, #format_option, #format_prologue

Methods inherited from BasePrinter

#command_name, #format!, #format_command, #format_element, #format_epilogue, #format_option, #format_prologue, #line_count, #regular_option, #usage_option, #usage_wrapped

Methods included from Terminal

#color, #command_exists?, die, #die, #page, #pager, #pager?, #pipe_in, #pipe_out, #stdin?, #unformatted

Constructor Details

#initialize(options) ⇒ ERBPrinter

Returns a new instance of ERBPrinter.



7
8
9
10
11
12
13
14
15
# File 'lib/choosy/printing/erb_printer.rb', line 7

def initialize(options)
  super(options)
  if options[:template].nil?
    raise Choosy::ConfigurationError.new("no template file given to ERBPrinter")
  elsif !File.file?(options[:template])
    raise Choosy::ConfigurationError.new("the template file doesn't exist: #{options[:template]}")
  end
  @template = options[:template]
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/choosy/printing/erb_printer.rb', line 5

def command
  @command
end

#templateObject (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/choosy/printing/erb_printer.rb', line 5

def template
  @template
end

Instance Method Details

#erb_bindingObject



26
27
28
# File 'lib/choosy/printing/erb_printer.rb', line 26

def erb_binding
  binding
end

#print!(command) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/choosy/printing/erb_printer.rb', line 17

def print!(command)
  @command = command
  contents = nil
  File.open(template, 'r') {|f| contents = f.read }
  erb = ERB.new contents

  erb.result(self)
end