Skip to content

undefined method errors in custom classes with Prawn::View mixed-in #15

@giuseb

Description

@giuseb

I may have found a caveat in the gem. The currently recommended way to wrap Prawn in a custom class is to include Prawn::View, rather than inheriting from Prawn::Document, as it used to be the case.

But the following program will fail. Please let me know if it's too cryptic, I will provide more details (but see the Views page in Prawn's manual)

require 'prawn'
require 'prawn/grouping'

class MyView
  include Prawn::View

  def add_text
    lorem   'this would work'
    group do
      text  'this would work as well'
      lorem 'but this will raise undefined method'
    end
  end

  # this method is not recognized by code inside the group block
  def lorem(outcome)
    text outcome
  end
end

v = MyView.new
v.add_text
v.render_file 'out.pdf'

Ciao, Giuseppe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions