Class: GnuCash::Invoice::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/gnucash/invoice/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(invoice_id, templates) ⇒ Printer

Returns a new instance of Printer.



9
10
11
12
# File 'lib/gnucash/invoice/printer.rb', line 9

def initialize invoice_id, templates
  @invoice   = Invoice.find(invoice_id)
  @templates = GnuCash.root.join(templates)
end

Instance Method Details

#embedded_asset(pathname) ⇒ Object



15
16
17
# File 'lib/gnucash/invoice/printer.rb', line 15

def embedded_asset pathname
  environment[pathname].to_s
end

#environmentObject



20
21
22
23
24
25
# File 'lib/gnucash/invoice/printer.rb', line 20

def environment
  @environment ||= Sprockets::Environment.new(@templates).tap do |env|
    env.append_path 'assets/stylesheets'
    env.css_compressor = :sass
  end
end

#renderObject



28
29
30
31
32
33
34
35
36
# File 'lib/gnucash/invoice/printer.rb', line 28

def render
  template = Slim::Template.new @templates.join('invoice.slim').to_s
  template.render(self, {
    :invoice  => @invoice,
    :entries  => @invoice.entries,
    :customer => @invoice.customer,
    :options  => Options
  })
end