Frederick Cheung wrote:

>> That's seems a little complicated (and I don't see the flexibility of
>> it, either) but now I'm using the String#insert and at the end I do a
>> String#gsub to remove the {some_partial foo:bar}'s.
>>
> 
> It avoids the need to maintain the drop array (and also means that you
> don't need a gsub that as is i believe will remove the wrong content
> if there are more than one partial (because the * is greedy)

I admit the gsub was an emergency solution, and yes, there are a risk 
that it will strip the wrong content.

> you could have something like
> 
> def dropify(content)
>   s = StringScanner.new(content)
>   output = ""
>   previous_end = 0
>   while s.scan_until(/\{/)
>     output << content[previous_end, s.pointer - previous_end]
>     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
>   end
>   output << content[s.pointer, content.length - s.pointer]
> end

I've been taking a look at your code and it looks interesting. But the 
only thing I can't figure out is where (and how) you'ld render the 
partial in the code above.

I've been testing your method and something is wrong. E.g. if you have 
this content:

----------
{test}

Lorem ipsum dolor sit amet.

{test}

Lorem ipsum dolor sit amet.
----------

you'll get absolutely nothing back. I tried changing the 6th line to 
this:

output << content[previous_end, s.pointer]

Still wrong:

----------
{

Lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet.

{test}

Lorem ipsum dolor sit amet.
----------

Did your method work for you, or what?

> which is marginally simpler (the above could contain off by 1 errors
> in the various offsets).

What is "off by 1 errors"?
-- 
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