Syntax issue

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

I need to add to number_pages the font size

[code]
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
[/code]

so I tried number_pages("<page> / <total>", [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

···

--
Posted via http://www.ruby-forum.com/.

Sig Dx wrote:

so I tried number_pages("<page> / <total>", [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 ?

···

--
Posted via http://www.ruby-forum.com/\.

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

···

On 2009-12-10, Sig Dx <sigbackup@gmail.com> wrote:

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

--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

so i think i should be number_pages("<page> / <total>",:at => [0, 0], :size
=> 10)
the first argument is "<page> / <total>", the second argument is { :at =>
[0, 0], :size => 10}

···

On Fri, Dec 11, 2009 at 2:07 AM, Sig Dx <sigbackup@gmail.com> wrote:

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

I need to add to number_pages the font size

[code]
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
[/code]

so I tried number_pages("<page> / <total>", [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
--
Posted via http://www.ruby-forum.com/\.

the difference is the ":at => [0,0]"

Thanks for your replies.

I guess you mean something like

number_pages("<page> / <total>", [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

···

--
Posted via http://www.ruby-forum.com/.

I guess you mean something like

number_pages("<page> / <total>", [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("<page>","#{i+1}").gsub("<total>","#{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 Thursday 10 December 2009 03:31:14 pm Sig Dx 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. "

Have a nice day.

···

--
Posted via http://www.ruby-forum.com/.

Seems like a reasonable patch. We'll look into it if someone drops a
ticket into github.com/sandal/prawn/issues

···

On Fri, Dec 11, 2009 at 4:18 AM, David Masover <ninja@slaphack.com> wrote:

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("<page>","#{i+1}").gsub("<total>","#{page_count}")
text str, {:at => position}.merge!(options)
end
end

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 1:30 PM, Sig Dx <sigbackup@gmail.com> 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. "

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 Brown wrote:

···

On Fri, Dec 11, 2009 at 4:18 AM, David Masover <ninja@slaphack.com> > wrote:

�end
end

Seems like a reasonable patch. We'll look into it if someone drops a
ticket into github.com/sandal/prawn/issues

--
Posted via http://www.ruby-forum.com/\.

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

···

On 2009-12-11, Sig Dx <sigbackup@gmail.com> 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. "

--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

Seebs 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,

···

On 2009-12-11, Sig Dx <sigbackup@gmail.com> wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

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

-greg

···

On Fri, Dec 11, 2009 at 2:09 PM, Sig Dx <sigbackup@gmail.com> 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?

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 Fri, Dec 11, 2009 at 5:52 PM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

Seebs wrote:

On 2009-12-11, Sig Dx <sigbackup@gmail.com> 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.

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 2009-12-12, Gregory Brown <gregory.t.brown@gmail.com> wrote:
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

Gregory Brown 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,

···

On Fri, Dec 11, 2009 at 5:52 PM, Marnen Laibow-Koser <marnen@marnen.org> > wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

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

···

On Sat, Dec 12, 2009 at 11:09 AM, Marnen Laibow-Koser <marnen@marnen.org> 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.