Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
$ spec spec/
Prawn specs: Running on Ruby Version: 1.9.0
.......................F.F.................................................................................................F.......................
1)
Spec::Mocks::MockExpectationError in 'When ending each page should execute the lambda specified by on_page_end'
Mock 'page_end_proc' expected :[] with (any args) 3 times, but received it 0 times
/Users/sandal/devel/prawn/spec/document_spec.rb:68:in `block (2 levels) in <top (required)>'
2)
04:27 < mindaugas> Hello, i've got problem with prawnto rails plugin, I followed carefully all the steps as described in http://cracklabs.com/prawnto/use but my controller actions still looking for erb templates... and all i get is "template is missing" error. I wonder, what i'm missing ?
04:33 < mindaugas> I'm on windows xp with rails 2.1
04:39 < yob> are you calling http://host/controller/action/id.pdf ?
04:49 < mindaugas> Thanks yob, your question just put me in the right direction, it works now, i'm still newb :)
04:51 < yob> no probs
04:51 < yob> the format stuff is black magic if you haven't used it before
require "thought"
class Thought
class SafetyFirst
def analyze(map, rover)
return unless map.threat.nonzero?
if 2 * rover.speed > rover.max_sensor or
(rover.rotation_speed and rover.speed > rover.rotation_speed)
Vote.new("b*", 99)
pdf = Prawn::Document.new(:page_size => "LEGAL") do
text "Blahdiblah"
image "my_sexy_pic.png"
end
pdf.render
Prawn::Document.generate("family_style.pdf") do
["Courier","Helvetica","Times-Roman"].each do |f|
[:bold,:bold_italic,:italic,:normal].each do |s|
font f, :style => s
text "I'm writing in #{f} (#{s})"
end
end
font "Helvetica"
file = "lazy_bounding_boxes.pdf"
Prawn::Document.generate(file, :skip_page_creation => true) do
point = [bounds.right-50, bounds.bottom + 25]
page_counter = lazy_bounding_box(point, :width => 50) do
text "Page: #{page_count}"
end
10.times do
start_new_page
text "Some text"
header margin_box.top_left do
text "Here's My Fancy Header", :size => 25, :align => :center
stroke_horizontal_rule
end
footer [margin_box.left, margin_box.bottom + 25] do
stroke_horizontal_rule
text "And here's a sexy footer", :size => 16
end
require "open-uri"
loop do
puts( open("http://finance.google.com/finance?cid=983582").read.
match(/<span class="chr" id="ref_983582_c">(-?\d+\.\d+)/m)[1] )
sleep(10)
end
require "enumerator"
# tree is represented as: [[a,b,c,d],[e,f,g],[h,i],[j]]
# (bottom up)
#
def max(tree)
bottom = tree.shift
pairs = bottom.enum_for(:each_cons, 2).to_a
update = pairs.enum_for(:each_with_index).map do |pair,i|
tree.first[i] + pair.max
Prawn::Document.generate("span.pdf") do
# Spans will typically be used outside of bounding boxes as a way to build
# single columns of flowing text that span across pages.
#
span(350, :position => :center) do
text "Here's some centered text in a 350 point column. " * 100
end
# Spans are not really compatible with bounding boxes because they break