Module: Invoicing::LedgerItem::RenderHTML

Extended by:
ActiveSupport::Concern
Defined in:
lib/invoicing/ledger_item/render_html.rb

Overview

Included into ActiveRecord model object when acts_as_ledger_item is invoked.

Defined Under Namespace

Classes: HTMLOutputBuilder

Instance Method Summary collapse

Instance Method Details

#render_html(options = {}) {|output_builder| ... } ⇒ Object

Shortcut for rendering an invoice or a credit note into a human-readable HTML format. Can be called without any arguments, in which case a general-purpose representation is produced. Can also be given options and a block for customising the output:

@invoice = Invoice.find(params[:id])
@invoice.render_html :quantity_column => false do |i|
  i.date_format "%d %B %Y"        # overwrites default "%Y-%m-%d"
  i.recipient_label "Customer"    # overwrites default "Recipient"
  i.sender_label "Supplier"       # overwrites default "Sender"
  i.description_tag do |params|
    "<p>Thank you for your order. Here is our invoice for your records.</p>\n" +
    "<p>Description: #{params[:description]}</p>\n"
  end
end

Yields:

  • (output_builder)

26
27
28
29
30
# File 'lib/invoicing/ledger_item/render_html.rb', line 26

def render_html(options={}, &block)
  output_builder = HTMLOutputBuilder.new(self, options)
  yield output_builder if block_given?
  output_builder.build
end