Frederick Cheung wrote:

>> Did your method work for you, or what?
> 
> yeah i left out that bit by accident. you should do that (ie output <<
> render(...)) after I set previous_end at the end of the loop

Okay, thanks!

>> What is "off by 1 errors"?
> 
> some of the offsets might be off by 1 (eg someplaces where it says
> pointer it might need to be s.pointer-1 etc..). More generally I just
> bashed that out in Mail so I expect that   there's the odd mistake
> like that in there.

All right, with my new knowledge I've changed your method a little bit 
and it works perfectly well.

So this is the new final version of the method:

==========
def dropify(content)
  s = StringScanner.new(content)
  output = ""
  previous_end = 0
  while s.scan_until(/\{/)
    output << content[previous_end, s.pointer - previous_end - 1]
    partial =  s.scan(/\w+/)
    s.skip /\s+/
    arguments = {}
    while argument = s.scan(/\w+:\w+/)
      name, value = argument.split(/:/)
      arguments[name.to_sym] = value
      s.skip /\s+/
    end
    s.skip_until /\}/
    previous_end = s.pointer
    output << render(:partial => "drops/#{partial}", :locals => 
arguments)
  end
  output << content[s.pointer, content.length - s.pointer]
end
==========

Notice that in the 6th line i subtract s.pointer-previous_end by 1 and 
that's what made it work.

Thanks for your help, Fred!
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to