Class: Invoicing::LedgerItem::RenderHTML::HTMLOutputBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/invoicing/ledger_item/render_html.rb

Overview

:nodoc:

Constant Summary collapse

HTML_ESCAPE =
{ '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ledger_item, options) ⇒ HTMLOutputBuilder

Returns a new instance of HTMLOutputBuilder.



39
40
41
42
43
44
45
46
# File 'lib/invoicing/ledger_item/render_html.rb', line 39

def initialize(ledger_item, options)
  @ledger_item = ledger_item
  @options = default_options
  @options.update(options)
  @custom_fragments = {}
  total_amount = get(:total_amount)
  @factor = (total_amount && total_amount < BigDecimal('0')) ? BigDecimal('-1') : BigDecimal('1')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object

foo { block } => call block when invoking fragment foo foo “string” => return string when invoking fragment foo invoke_foo => invoke fragment foo; if none set, delegate to default_foo



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/invoicing/ledger_item/render_html.rb', line 68

def method_missing(method_id, *args, &block)
  method_id = method_id.to_sym
  if method_id.to_s =~ /^invoke_(.*)$/
    method_id = $1.to_sym
    if custom_fragments[method_id]
      return custom_fragments[method_id].call(*args, &block)
    else
      return send("default_#{method_id}", *args, &block)
    end
  end

  return super unless respond_to? "default_#{method_id}"

  if block_given? && args.empty?
    custom_fragments[method_id] = proc &block
  elsif args.length == 1
    custom_fragments[method_id] = proc{ args[0].to_s }
  else
    raise ArgumentError, "#{method_id} expects exactly one value or block argument"
  end
end

Instance Attribute Details

#current_line_itemObject (readonly)

Returns the value of attribute current_line_item.



37
38
39
# File 'lib/invoicing/ledger_item/render_html.rb', line 37

def current_line_item
  @current_line_item
end

#custom_fragmentsObject (readonly)

Returns the value of attribute custom_fragments.



37
38
39
# File 'lib/invoicing/ledger_item/render_html.rb', line 37

def custom_fragments
  @custom_fragments
end

#factorObject (readonly)

Returns the value of attribute factor.



37
38
39
# File 'lib/invoicing/ledger_item/render_html.rb', line 37

def factor
  @factor
end

#ledger_itemObject (readonly)

Returns the value of attribute ledger_item.



37
38
39
# File 'lib/invoicing/ledger_item/render_html.rb', line 37

def ledger_item
  @ledger_item
end

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/invoicing/ledger_item/render_html.rb', line 37

def options
  @options
end

Instance Method Details

#buildObject

Renders an invoice or credit note to HTML



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/invoicing/ledger_item/render_html.rb', line 125

def build
  addresses_table_deps = [:sender_label, :recipient_label, :sender_address, :recipient_address, {
    :sender_tax_number    => :tax_number_label,
    :recipient_tax_number => :tax_number_label
  }]

   = [{
    :identifier   =>  :identifier_label,
    :issue_date   => [:date_format, :issue_date_label],
    :period_start => [:date_format, :period_start_label],
    :period_end   => [:date_format, :period_end_label],
    :due_date     => [:date_format, :due_date_label]
  }]

  line_items_header_deps = [:line_tax_point_label, :line_quantity_label, :line_description_label,
    :line_net_amount_label, :line_tax_amount_label, :line_gross_amount_label]

  line_items_subtotal_deps = [:subtotal_label, :net_amount_label, :tax_amount_label,
    :gross_amount_label, {
    :net_amount => :net_amount_label,
    :tax_amount => :tax_amount_label,
    :total_amount => :gross_amount_label
  }]

  line_items_total_deps = [:total_label, :net_amount_label, :tax_amount_label,
    :gross_amount_label, {
    :net_amount => :net_amount_label,
    :tax_amount => :tax_amount_label,
    :total_amount => :gross_amount_label
  }]

  page_layout_deps = {
    :title_tag => :title,
    :addresses_table => addresses_table_deps,
    :metadata_table => ,
    :description_tag => :description,
    :line_items_table => [:line_items_list, {
      :line_items_header   => line_items_header_deps,
      :line_items_subtotal => line_items_subtotal_deps,
      :line_items_total    => line_items_total_deps
    }]
  }

  invoke_page_layout(params_hash(page_layout_deps))
end

#default_address(details) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/invoicing/ledger_item/render_html.rb', line 268

def default_address(details)
  details = details.symbolize_keys
  html =  "#{indent*3}<div class=\"fn org\">#{       h(details[:name])        }</div>\n"
  html << "#{indent*3}<div class=\"contact\">#{      h(details[:contact_name])}</div>\n"        unless details[:contact_name].blank?
  html << "#{indent*3}<div class=\"adr\">\n"
  html << "#{indent*4}<span class=\"street-address\">#{h(details[:address]).strip.gsub(/\n/, '<br />')}</span><br />\n"
  html << "#{indent*4}<span class=\"locality\">#{    h(details[:city])        }</span><br />\n" unless details[:city].blank?
  html << "#{indent*4}<span class=\"region\">#{      h(details[:state])       }</span><br />\n" unless details[:state].blank?
  html << "#{indent*4}<span class=\"postal-code\">#{ h(details[:postal_code]) }</span><br />\n" unless details[:postal_code].blank?
  html << "#{indent*4}<span class=\"country-name\">#{h(details[:country])     }</span>\n"       unless details[:country].blank?
  html << "#{indent*3}</div>\n"
end

#default_addresses_table(params) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/invoicing/ledger_item/render_html.rb', line 299

def default_addresses_table(params)
  html =  "#{indent*0}<table class=\"invoice addresses\">\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<th class=\"recipient\">#{params[:recipient_label]}</th>\n"
  html << "#{indent*2}<th class=\"sender\">#{params[:sender_label]}</th>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"recipient vcard\">\n#{params[:recipient_address]}"
  html << "#{indent*2}</td>\n"
  html << "#{indent*2}<td class=\"sender vcard\">\n#{params[:sender_address]}"
  html << "#{indent*2}</td>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"recipient\">\n"
  html << "#{indent*3}#{params[:recipient_tax_number]}\n"
  html << "#{indent*2}</td>\n"
  html << "#{indent*2}<td class=\"sender\">\n"
  html << "#{indent*3}#{params[:sender_tax_number]}\n"
  html << "#{indent*2}</td>\n"
  html << "#{indent*1}</tr>\n"
  html << "#{indent*0}</table>\n"
end

#default_credit_note_labelObject



179
180
181
# File 'lib/invoicing/ledger_item/render_html.rb', line 179

def default_credit_note_label
  "Credit Note"
end

#default_date_formatObject



171
172
173
# File 'lib/invoicing/ledger_item/render_html.rb', line 171

def default_date_format
  "%Y-%m-%d"
end

#default_descriptionObject



371
372
373
# File 'lib/invoicing/ledger_item/render_html.rb', line 371

def default_description
  h(get(:description))
end

#default_description_tag(params) ⇒ Object



375
376
377
# File 'lib/invoicing/ledger_item/render_html.rb', line 375

def default_description_tag(params)
  "<p class=\"invoice description\">#{params[:description]}</p>\n"
end

#default_due_date(params) ⇒ Object



358
359
360
361
362
363
364
# File 'lib/invoicing/ledger_item/render_html.rb', line 358

def default_due_date(params)
  if due_date = get(:due_date)
    (params, :due_date, due_date.strftime(params[:date_format]))
  else
    ""
  end
end

#default_due_date_labelObject



212
213
214
# File 'lib/invoicing/ledger_item/render_html.rb', line 212

def default_due_date_label
  "Payment due:"
end

#default_gross_amount_labelObject



256
257
258
# File 'lib/invoicing/ledger_item/render_html.rb', line 256

def default_gross_amount_label
  ""
end

#default_identifier(params) ⇒ Object



330
331
332
# File 'lib/invoicing/ledger_item/render_html.rb', line 330

def default_identifier(params)
  (params, :identifier, get(:identifier))
end

#default_identifier_labelObject



195
196
197
198
# File 'lib/invoicing/ledger_item/render_html.rb', line 195

def default_identifier_label
  label = (factor == BigDecimal('-1')) ? invoke_credit_note_label : invoke_invoice_label
  "#{label} no.:"
end

#default_invoice_labelObject



175
176
177
# File 'lib/invoicing/ledger_item/render_html.rb', line 175

def default_invoice_label
  "Invoice"
end

#default_issue_date(params) ⇒ Object



334
335
336
337
338
339
340
# File 'lib/invoicing/ledger_item/render_html.rb', line 334

def default_issue_date(params)
  if issue_date = get(:issue_date)
    (params, :issue_date, issue_date.strftime(params[:date_format]))
  else
    ""
  end
end

#default_issue_date_labelObject



200
201
202
# File 'lib/invoicing/ledger_item/render_html.rb', line 200

def default_issue_date_label
  "Issue date:"
end

#default_line_description(params) ⇒ Object



402
403
404
# File 'lib/invoicing/ledger_item/render_html.rb', line 402

def default_line_description(params)
  h(line_get(:description))
end

#default_line_description_labelObject



224
225
226
# File 'lib/invoicing/ledger_item/render_html.rb', line 224

def default_line_description_label
  "Description"
end

#default_line_gross_amount(params) ⇒ Object



422
423
424
425
426
427
428
# File 'lib/invoicing/ledger_item/render_html.rb', line 422

def default_line_gross_amount(params)
  if gross_amount = line_get(:gross_amount)
    h(current_line_item.format_currency_value(gross_amount*factor))
  else
    ""
  end
end

#default_line_gross_amount_labelObject



236
237
238
# File 'lib/invoicing/ledger_item/render_html.rb', line 236

def default_line_gross_amount_label
  "Gross price"
end

#default_line_item(params) ⇒ Object



454
455
456
457
458
459
460
461
462
463
# File 'lib/invoicing/ledger_item/render_html.rb', line 454

def default_line_item(params)
  html =  "#{indent*1}<tr>\n"
  html << "#{indent*2}<td class=\"tax-point\">#{   params[:line_tax_point]   }</td>\n" if options[:tax_point_column]
  html << "#{indent*2}<td class=\"quantity\">#{    params[:line_quantity]    }</td>\n" if options[:quantity_column]
  html << "#{indent*2}<td class=\"description\">#{ params[:line_description] }</td>\n" if options[:description_column]
  html << "#{indent*2}<td class=\"net-amount\">#{  params[:line_net_amount]  }</td>\n" if options[:net_amount_column]
  html << "#{indent*2}<td class=\"tax-amount\">#{  params[:line_tax_amount]  }</td>\n" if options[:tax_amount_column]
  html << "#{indent*2}<td class=\"gross-amount\">#{params[:line_gross_amount]}</td>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_header(params) ⇒ Object



379
380
381
382
383
384
385
386
387
388
# File 'lib/invoicing/ledger_item/render_html.rb', line 379

def default_line_items_header(params)
  html =  "#{indent*1}<tr>\n"
  html << "#{indent*2}<th class=\"tax-point\">#{   params[:line_tax_point_label]   }</th>\n" if options[:tax_point_column]
  html << "#{indent*2}<th class=\"quantity\">#{    params[:line_quantity_label]    }</th>\n" if options[:quantity_column]
  html << "#{indent*2}<th class=\"description\">#{ params[:line_description_label] }</th>\n" if options[:description_column]
  html << "#{indent*2}<th class=\"net-amount\">#{  params[:line_net_amount_label]  }</th>\n" if options[:net_amount_column]
  html << "#{indent*2}<th class=\"tax-amount\">#{  params[:line_tax_amount_label]  }</th>\n" if options[:tax_amount_column]
  html << "#{indent*2}<th class=\"gross-amount\">#{params[:line_gross_amount_label]}</th>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_listObject



465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/invoicing/ledger_item/render_html.rb', line 465

def default_line_items_list
  get(:line_items).sorted(:tax_point).map do |line_item|
    @current_line_item = line_item
    invoke_line_item(params_hash(
      :line_tax_point    => [:line_tax_point_label, :date_format],
      :line_quantity     => [:line_quantity_label],
      :line_description  => [:line_description_label],
      :line_net_amount   => [:line_net_amount_label],
      :line_tax_amount   => [:line_tax_amount_label],
      :line_gross_amount => [:line_gross_amount_label]
    ))
  end.join
end

#default_line_items_subtotal(params) ⇒ Object



479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/invoicing/ledger_item/render_html.rb', line 479

def default_line_items_subtotal(params)
  colspan = 0
  colspan += 1 if options[:tax_point_column]
  colspan += 1 if options[:quantity_column]
  colspan += 1 if options[:description_column]
  html =  "#{indent*1}<tr class=\"subtotal\">\n"
  html << "#{indent*2}<th colspan=\"#{colspan}\">#{params[:subtotal_label]}</th>\n"
  html << "#{indent*2}<td class=\"net-amount\">#{params[:net_amount_label]}#{params[:net_amount]}</td>\n" if options[:net_amount_column]
  html << "#{indent*2}<td class=\"tax-amount\">#{params[:tax_amount_label]}#{params[:tax_amount]}</td>\n" if options[:tax_amount_column]
  html << "#{indent*2}<td class=\"gross-amount\"></td>\n" if options[:gross_amount_column]
  html << "#{indent*1}</tr>\n"
end

#default_line_items_table(params) ⇒ Object



506
507
508
509
510
511
# File 'lib/invoicing/ledger_item/render_html.rb', line 506

def default_line_items_table(params)
  html =  "<table class=\"invoice line-items\">\n"
  html << params[:line_items_header] + params[:line_items_list]
  html << params[:line_items_subtotal] if options[:subtotal]
  html << params[:line_items_total] + "</table>\n"
end

#default_line_items_total(params) ⇒ Object



492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/invoicing/ledger_item/render_html.rb', line 492

def default_line_items_total(params)
  colspan = -1
  colspan += 1 if options[:tax_point_column]
  colspan += 1 if options[:quantity_column]
  colspan += 1 if options[:description_column]
  colspan += 1 if options[:net_amount_column]
  colspan += 1 if options[:tax_amount_column]
  colspan += 1 if options[:gross_amount_column]
  html =  "#{indent*1}<tr class=\"total\">\n"
  html << "#{indent*2}<th colspan=\"#{colspan}\">#{params[:total_label]}</th>\n"
  html << "#{indent*2}<td class=\"total-amount\">#{params[:gross_amount_label]}#{params[:total_amount]}</td>\n"
  html << "#{indent*1}</tr>\n"
end

#default_line_net_amount(params) ⇒ Object



406
407
408
409
410
411
412
# File 'lib/invoicing/ledger_item/render_html.rb', line 406

def default_line_net_amount(params)
  if net_amount = line_get(:net_amount)
    h(current_line_item.format_currency_value(net_amount*factor))
  else
    ""
  end
end

#default_line_net_amount_labelObject



228
229
230
# File 'lib/invoicing/ledger_item/render_html.rb', line 228

def default_line_net_amount_label
  "Net price"
end

#default_line_quantity(params) ⇒ Object



398
399
400
# File 'lib/invoicing/ledger_item/render_html.rb', line 398

def default_line_quantity(params)
  h(line_get(:quantity).to_s)
end

#default_line_quantity_labelObject



220
221
222
# File 'lib/invoicing/ledger_item/render_html.rb', line 220

def default_line_quantity_label
  "Quantity"
end

#default_line_tax_amount(params) ⇒ Object



414
415
416
417
418
419
420
# File 'lib/invoicing/ledger_item/render_html.rb', line 414

def default_line_tax_amount(params)
  if tax_amount = line_get(:tax_amount)
    h(current_line_item.format_currency_value(tax_amount*factor))
  else
    ""
  end
end

#default_line_tax_amount_labelObject



232
233
234
# File 'lib/invoicing/ledger_item/render_html.rb', line 232

def default_line_tax_amount_label
  "VAT"
end

#default_line_tax_point(params) ⇒ Object



390
391
392
393
394
395
396
# File 'lib/invoicing/ledger_item/render_html.rb', line 390

def default_line_tax_point(params)
  if tax_point = line_get(:tax_point)
    h(tax_point.strftime(params[:date_format]))
  else
    ""
  end
end

#default_line_tax_point_labelObject



216
217
218
# File 'lib/invoicing/ledger_item/render_html.rb', line 216

def default_line_tax_point_label
  "Tax point"
end

#default_metadata_item(params, key, value) ⇒ Object



322
323
324
325
326
327
328
# File 'lib/invoicing/ledger_item/render_html.rb', line 322

def (params, key, value)
  label = params["#{key}_label".to_sym]
  html =  "#{indent*1}<tr class=\"#{key.to_s.gsub(/_/, '-')}\">\n"
  html << "#{indent*2}<th>#{label}</th>\n"
  html << "#{indent*2}<td>#{h(value)}</td>\n"
  html << "#{indent*1}</tr>\n"
end

#default_metadata_table(params) ⇒ Object



366
367
368
369
# File 'lib/invoicing/ledger_item/render_html.rb', line 366

def (params)
  "<table class=\"invoice metadata\">\n" + params[:identifier] + params[:issue_date] +
    params[:period_start] + params[:period_end] + params[:due_date] + "#{indent*0}</table>\n"
end

#default_net_amount(params) ⇒ Object



430
431
432
433
434
435
436
# File 'lib/invoicing/ledger_item/render_html.rb', line 430

def default_net_amount(params)
  if net_amount = get(:net_amount)
    h(ledger_item.format_currency_value(net_amount*factor))
  else
    ""
  end
end

#default_net_amount_labelObject



248
249
250
# File 'lib/invoicing/ledger_item/render_html.rb', line 248

def default_net_amount_label
  "Net: "
end

#default_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/invoicing/ledger_item/render_html.rb', line 48

def default_options
  line_items = get(:line_items)
  {
    :tax_point_column    => line_items.map{|i| line_get(:tax_point,  i) }.compact != [],
    :quantity_column     => line_items.map{|i| line_get(:quantity,   i) }.compact != [],
    :description_column  => true,
    :net_amount_column   => true,
    :tax_amount_column   => line_items.map{|i| line_get(:tax_amount, i) }.compact != [],
    :gross_amount_column => false,
    :subtotal            => true
  }
end

#default_page_layout(params) ⇒ Object



513
514
515
516
# File 'lib/invoicing/ledger_item/render_html.rb', line 513

def default_page_layout(params)
  params[:title_tag] + params[:addresses_table] + params[:metadata_table] +
  params[:description_tag] + params[:line_items_table]
end

#default_period_end(params) ⇒ Object



350
351
352
353
354
355
356
# File 'lib/invoicing/ledger_item/render_html.rb', line 350

def default_period_end(params)
  if period_end = get(:period_end)
    (params, :period_end, period_end.strftime(params[:date_format]))
  else
    ""
  end
end

#default_period_end_labelObject



208
209
210
# File 'lib/invoicing/ledger_item/render_html.rb', line 208

def default_period_end_label
  "Period until:"
end

#default_period_start(params) ⇒ Object



342
343
344
345
346
347
348
# File 'lib/invoicing/ledger_item/render_html.rb', line 342

def default_period_start(params)
  if period_start = get(:period_start)
    (params, :period_start, period_start.strftime(params[:date_format]))
  else
    ""
  end
end

#default_period_start_labelObject



204
205
206
# File 'lib/invoicing/ledger_item/render_html.rb', line 204

def default_period_start_label
  "Period from:"
end

#default_recipient_addressObject



285
286
287
# File 'lib/invoicing/ledger_item/render_html.rb', line 285

def default_recipient_address
  invoke_address(get(:recipient_details))
end

#default_recipient_labelObject



183
184
185
# File 'lib/invoicing/ledger_item/render_html.rb', line 183

def default_recipient_label
  "Recipient"
end

#default_recipient_tax_number(params) ⇒ Object



294
295
296
297
# File 'lib/invoicing/ledger_item/render_html.rb', line 294

def default_recipient_tax_number(params)
  recipient_tax_number = get(:recipient_details).symbolize_keys[:tax_number]
  "#{params[:tax_number_label]}<span class=\"tax-number\">#{h(recipient_tax_number)}</span>"
end

#default_sender_addressObject



281
282
283
# File 'lib/invoicing/ledger_item/render_html.rb', line 281

def default_sender_address
  invoke_address(get(:sender_details))
end

#default_sender_labelObject



187
188
189
# File 'lib/invoicing/ledger_item/render_html.rb', line 187

def default_sender_label
  "Sender"
end

#default_sender_tax_number(params) ⇒ Object



289
290
291
292
# File 'lib/invoicing/ledger_item/render_html.rb', line 289

def default_sender_tax_number(params)
  sender_tax_number = get(:sender_details).symbolize_keys[:tax_number]
  "#{params[:tax_number_label]}<span class=\"tax-number\">#{h(sender_tax_number)}</span>"
end

#default_subtotal_labelObject



240
241
242
# File 'lib/invoicing/ledger_item/render_html.rb', line 240

def default_subtotal_label
  "Subtotal"
end

#default_tax_amount(params) ⇒ Object



438
439
440
441
442
443
444
# File 'lib/invoicing/ledger_item/render_html.rb', line 438

def default_tax_amount(params)
  if tax_amount = get(:tax_amount)
    h(ledger_item.format_currency_value(tax_amount*factor))
  else
    ""
  end
end

#default_tax_amount_labelObject



252
253
254
# File 'lib/invoicing/ledger_item/render_html.rb', line 252

def default_tax_amount_label
  "VAT: "
end

#default_tax_number_labelObject



191
192
193
# File 'lib/invoicing/ledger_item/render_html.rb', line 191

def default_tax_number_label
  "VAT number:<br />"
end

#default_titleObject



260
261
262
# File 'lib/invoicing/ledger_item/render_html.rb', line 260

def default_title
  (factor == BigDecimal('-1')) ? invoke_credit_note_label : invoke_invoice_label
end

#default_title_tag(params) ⇒ Object



264
265
266
# File 'lib/invoicing/ledger_item/render_html.rb', line 264

def default_title_tag(params)
  "<h1 class=\"invoice\">#{params[:title]}</h1>\n"
end

#default_total_amount(params) ⇒ Object



446
447
448
449
450
451
452
# File 'lib/invoicing/ledger_item/render_html.rb', line 446

def default_total_amount(params)
  if total_amount = get(:total_amount)
    h(ledger_item.format_currency_value(total_amount*factor))
  else
    ""
  end
end

#default_total_labelObject



244
245
246
# File 'lib/invoicing/ledger_item/render_html.rb', line 244

def default_total_label
  "Total"
end

#get(method_id) ⇒ Object

Returns the value of a (potentially renamed) method on the ledger item



91
92
93
# File 'lib/invoicing/ledger_item/render_html.rb', line 91

def get(method_id)
  ledger_item.send(:ledger_item_class_info).get(ledger_item, method_id)
end

#h(s) ⇒ Object



61
62
63
# File 'lib/invoicing/ledger_item/render_html.rb', line 61

def h(s)
  s.to_s.gsub(/[#{HTML_ESCAPE.keys.join}]/) { |char| HTML_ESCAPE[char] }
end

#indentObject

String for one level of indentation



101
102
103
# File 'lib/invoicing/ledger_item/render_html.rb', line 101

def indent
  '    '
end

#line_get(method_id, line_item = current_line_item) ⇒ Object

Returns the value of a (potentially renamed) method on a line item



96
97
98
# File 'lib/invoicing/ledger_item/render_html.rb', line 96

def line_get(method_id, line_item = current_line_item)
  line_item.send(:line_item_class_info).get(line_item, method_id)
end

#params_hash(*param_names) ⇒ Object

This is quite meta. :)

params_hash(:sender_label, :sender_tax_number => :tax_number_label)
  # => {:sender_label => invoke_sender_label,
  #     :sender_tax_number => invoke_sender_tax_number(params_hash(:tax_number_label))}


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/invoicing/ledger_item/render_html.rb', line 110

def params_hash(*param_names)
  result = {}
  param_names.flatten!
  options = param_names.extract_options!

  param_names.each{|param| result[param.to_sym] = send("invoke_#{param}") }

  options.each_pair do |key, value|
    result[key.to_sym] = send("invoke_#{key}", params_hash(value))
  end

  result
end