Syntax issue

Hello guys,
I have hard time using Prawn (PDF library).

I need to add to number_pages the font size

def number_pages(string, position)
 page_count.times do |i|
  go_to_page(i)
  str = string.gsub("<page>","#{i+1}").gsub("<total>","#{page_count}")
  text str, :at => position
 end
end

so I tried number_pages(" / ", [0, 0]), :size => 10 but
i get syntax error, unexpected ‘,’, expecting kEND

However text “str”, :at => [0, 0], :size => 10 works fine.

Can anyone please let me know the difference between the 2 lines above?

Thanks, I appreciate your help.

Sig

Sig Dx wrote:

so I tried number_pages(" / ", [0, 0]), :size => 10 but
i get syntax error, unexpected ‘,’, expecting kEND

However text “str”, :at => [0, 0], :size => 10 works fine.

Can anyone please let me know the difference between the 2 lines above?

I’ve never used prawn, but I notice parenthesis. Why are those there ?

On 2009-12-10, Sig Dx [email protected] wrote:

so I tried number_pages(“ / ”, [0, 0]), :size => 10 but
i get syntax error, unexpected ‘,’, expecting kEND

Maybe you should have the hash INSIDE the parentheses, if you need them
at all?

The hash is just another argument to number_pages. That means that,
if you’re using ()s around the arguments, it needs to be inside them.

-s

Thanks for your replies.

I guess you mean something like

number_pages(" / ", [0,0], :size => 10)

but that doesn’t work for sure; with that code I get wrong number of
arguments (3 for 2) since number_pages requires 2 arguments and with
everything inside the parenthesis the arguments are 3.

If I’m wrong and you mean something different, can you please write down
a snippet for me?

THANKS AGAIN

Sig

On Fri, Dec 11, 2009 at 2:07 AM, Sig Dx [email protected] wrote:

text str, :at => position

the difference is the “:at => [0,0]”
so i think i should be number_pages(“ / ”,:at => [0, 0],
:size
=> 10)
the first argument is “ / ”, the second argument is { :at
=>
[0, 0], :size => 10}

Thanks for your replies, specially David for the exhaustive explanation.

I asked the Prawn people and this was the answer:

"We make it very clear that Prawn is not for beginning Rubyists. If you
seriously don’t know what a syntax error is and how to debug it, please
do not post on this list. "

Have a nice day.

On Thursday 10 December 2009 03:31:14 pm Sig Dx wrote:

I guess you mean something like

number_pages(“ / ”, [0,0], :size => 10)

Yes, that’s the only way that statement makes any sense, and that’s why
everyone assumed that’s what you meant.

but that doesn’t work for sure; with that code I get wrong number of
arguments (3 for 2) since number_pages requires 2 arguments and with
everything inside the parenthesis the arguments are 3.

Just so. You’ll still need to either find a way to change what
number_pages
does, or you’ll need to do it yourself.

But this isn’t a syntax issue, it’s an issue of the library not already
doing
what you want. For example, the following statement is syntactically
correct:

Bank.open(‘Federal Reserve’).transfer! 1000000000, :to => cayman_account

But, chances are, you don’t have access to a library which can actually
do
what that’s asking for. On the other hand, the following is quite
possible to
do, but syntactically broken:

has_many(:comments) :through => :posts

You see, the options hash gets turned into an argument. If you have
parentheses, that means it has to go inside the parentheses. If that
gives you
an error, it’s possible the function just doesn’t support what you want!

So, define your own number_pages method, and if you find a good way to
do it
generically, send it to the Prawn people.

Here’s what I came up with:

def number_pages(string, position, options={})
page_count.times do |i|
go_to_page(i)
str = string.gsub(“”,“#{i+1}”).gsub(“”,“#{page_count}”)
text str, {:at => position}.merge!(options)
end
end

I’m not sure it’s a good idea for it to work that way, though.
Ask the Prawn people:

http://groups.google.com/group/prawn-ruby

On Fri, Dec 11, 2009 at 1:30 PM, Sig Dx [email protected] wrote:

Thanks for your replies, specially David for the exhaustive explanation.

I asked the Prawn people and this was the answer:

"We make it very clear that Prawn is not for beginning Rubyists. If you
seriously don’t know what a syntax error is and how to debug it, please
do not post on this list. "

To clarify, what Sig asked us was why a line of code he cargoculted
was generating a syntax error. He was not asking us to review a patch
or anything similar. Maybe I’m off base, but I don’t consider the
Prawn mailing list the best place to answer questions about Ruby
syntax, and I’m glad this thread ended up in a more appropriate place.

-greg

On Fri, Dec 11, 2009 at 4:18 AM, David M. [email protected]
wrote:

end
end

Seems like a reasonable patch. We’ll look into it if someone drops a
ticket into Pull requests · practicingruby/prawn · GitHub

On 2009-12-11, Sig Dx [email protected] wrote:

"We make it very clear that Prawn is not for beginning Rubyists. If you
seriously don’t know what a syntax error is and how to debug it, please
do not post on this list. "

This may sound rude, but really, it’s not – it’s useful, accurate,
advice.
Prawn is experimental/alpha-grade. I’ve done some messing with it, and
I
love it, but it is NOT yet something that you should be picking up and
messing with if you can’t comfortably debug other people’s code.

-s

Hi Gregory,
I have just created it.

Before posting the error I asked an other question and the error came
for my interpretation of the answer. By the way Can you please let me
know if with Prawn 0.6.3 I can use the size attribute with number_pages?

Thanks and have a nice day

Sig

Gregory B. wrote:

On Fri, Dec 11, 2009 at 4:18 AM, David M. [email protected]
wrote:

�end
end

Seems like a reasonable patch. We’ll look into it if someone drops a
ticket into Pull requests · practicingruby/prawn · GitHub

Seebs wrote:

On 2009-12-11, Sig Dx [email protected] wrote:

"We make it very clear that Prawn is not for beginning Rubyists. If you
seriously don’t know what a syntax error is and how to debug it, please
do not post on this list. "

This may sound rude, but really, it’s not – it’s useful, accurate,
advice.
Prawn is experimental/alpha-grade.

No it’s not. I’m using it in production quite happily, and have been
for some time.

I’ve done some messing with it, and
I
love it, but it is NOT yet something that you should be picking up and
messing with if you can’t comfortably debug other people’s code.

Or rather, if you can’t debug simple mistakes in your own code.

-s

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Fri, Dec 11, 2009 at 5:52 PM, Marnen Laibow-Koser [email protected]
wrote:

No it’s not. I’m using it in production quite happily, and have been
for some time.

Peter is just quoting our own statements about support level. We
consider Prawn to be alpha-level software, edging towards beta. Not
because large parts of it aren’t good (much of core Prawn is possibly
suitable for production), but because things are still very much up in
the air between now and 1.0. We’re generally quick about fixing bugs
and we don’t go around making API changes for the fun of it, but at
the same time, we don’t want to give anyone a false sense of security.

One thing is for sure, to use Prawn effectively, until we get close to
1.0, you need to be able to read source and possibly patch it.
That’s why it’s not particularly suitable for beginners.

-greg

On 2009-12-12, Gregory B. [email protected] wrote:

Peter is just quoting our own statements about support level.

And going from my own experience messing with it. I have what will
probably become a bug report someday about table grid controls, but
I haven’t figured out what it would be.

One thing is for sure, to use Prawn effectively, until we get close to
1.0, you need to be able to read source and possibly patch it.
That’s why it’s not particularly suitable for beginners.

Exactly. It’s not that it’s unreliable (although Prawn::Format is
pretty
out of sync right now, and needs a maintainer… and no, I’m not
volunteering), it’s just that it might be reliable in a different way in
two
weeks…

-s

On Fri, Dec 11, 2009 at 2:09 PM, Sig Dx [email protected] wrote:

Hi Gregory,
I have just created it.

Before posting the error I asked an other question and the error came
for my interpretation of the answer. By the way Can you please let me
know if with Prawn 0.6.3 I can use the size attribute with number_pages?

gem unpack prawn can tell you that if you know how to use it.

-greg

Gregory B. wrote:

On Fri, Dec 11, 2009 at 5:52 PM, Marnen Laibow-Koser [email protected]
wrote:

No it’s not. �I’m using it in production quite happily, and have been
for some time.

Peter is just quoting our own statements about support level. We
consider Prawn to be alpha-level software, edging towards beta. Not
because large parts of it aren’t good (much of core Prawn is possibly
suitable for production), but because things are still very much up in
the air between now and 1.0. We’re generally quick about fixing bugs
and we don’t go around making API changes for the fun of it, but at
the same time, we don’t want to give anyone a false sense of security.

Hey, Rails changes its API all the time, and it’s not even a beta! :smiley:

One thing is for sure, to use Prawn effectively, until we get close to
1.0, you need to be able to read source and possibly patch it.

I’ve never really had to do that to use Prawn; granted, I’m using it for
fairly simple stuff. I ran into one rendering bug, which I tried (and
failed) to fix myself, but other than that, it Just Works.

That’s why it’s not particularly suitable for beginners.

I actually don’t agree that it isn’t. However, I do agree that the
project mailing list is not the place for basic Ruby syntax questions.

-greg

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Sat, Dec 12, 2009 at 11:09 AM, Marnen Laibow-Koser
[email protected] wrote:

That’s why it’s not particularly suitable for beginners.

I actually don’t agree that it isn’t. However, I do agree that the
project mailing list is not the place for basic Ruby syntax questions.

Well that’s re-assuring to hear, but at the same time, if you don’t
trust me about this, swim at your own risk :slight_smile:

-greg