Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created June 8, 2010 15:17
Show Gist options
  • Select an option

  • Save practicingruby/430171 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/430171 to your computer and use it in GitHub Desktop.
module Prawn
module Chunkable
def chunk(*a, &b)
Prawn::Core::Chunk.new(*a, &b)
end
def find_chunks(params)
if params[:command]
chunks.select { |c| c.command == params[:command] }
end
end
def to_pdf
rendered = @chunks.map do |chunk|
case result = chunk.content
when Array
result.map { |sub_chunk| sub_chunk.content }.join("\n")
else
result
end
end
rendered.join("\n")
end
module ClassMethods
def chunk_methods(*names)
names.each do |name|
module_eval %{
def #{name}(*a, &b)
chunks << #{name}!(*a, &b)
end
}
end
end
end
def self.included(base)
base.extend(ClassMethods)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment