prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 98 forks source link

How to create a custom cell type? #146

Open ferdynator opened 2 years ago

ferdynator commented 2 years ago

I would like to use this library in combination with prawn-html, but I am unsure how to render HTML into a table cell.

My current approach is to create a custom cell class:

class HtmlCell < Prawn::Table::Cell
  def draw_content
    PrawnHtml.append_html(self, content)
  end
end

and use it as such:

class PrintView
  include Prawn::View

  def print_section_x
    table [["header"], [HtmlCell.make(self, "<p>Test</p>")]]
  end
end

but unfortunately the draw_content method is never called. The code clearly states that the Cell type can be extended:

https://github.com/prawnpdf/prawn-table/blob/38b5bdb5dd95237646675c968091706f57a7a641/lib/prawn/table/cell.rb#L48-L50

but I can't find any examples. Is this currently possible?