Skip to content

Commit

Permalink
Update ExcelTemplating::Renderer#format_for to adapt for missing font
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Maravilla committed Apr 14, 2015
1 parent 421e8ff commit 38c2fcc
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/excel_templating/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ def looks_like_a_separator?(value)
end

def format_for(font)
@font_formats ||= {}
unless @font_formats.has_key?(font)
format = workbook.add_format(
{
bold: font.bold? ? 1 : 0,
italic: font.italic? ? 1 : 0,
underline: font.underline? ? 1 : 0
}.merge(default_format_styling))
@font_formats[font] = format
font_formats[font]
end

def font_formats
@font_formats ||= Hash.new do |cache, font|
template_font = font || Roo::Font.new

format_details = {
bold: template_font.bold? ? 1 : 0,
italic: template_font.italic? ? 1 : 0,
underline: template_font.underline? ? 1 : 0
}.merge(default_format_styling)

cache[font] = workbook.add_format format_details
end
@font_formats[font]
end

def mustachify(inline_template, locals: {})
Expand Down

0 comments on commit 38c2fcc

Please sign in to comment.