This is not purely a prototype question so if anyone wants to point me to a different location (other than "Google this" cuz I already did :), feel free. I just got the new PragProg book on Prototype and coincidentally was writing a fair amount of JS. Ok, there''s a question in here somewhere: I have to parse: [q]hello[q]hello1[/q]out[/q]for good and treat the [q] blocks as quoting levels for email. That means, I''ll be substituting <div class=q1> for the first level, q2 for the second, etc. I''m hoping not to have to tokenize the whole thing. Is there a straightforward way to match and process the nestings using a function as a second argument to gsub? Thx -- View this message in context: http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13655999 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 8, 2007 2:16 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a straightforward > way to match and process the nestings using a function as a second argument > to gsub?I''m not sure this will work for what you''re doing, but using 1.6''s wrap feature sounds like it could be just the ticket. Kangax wrote a great lil'' article about it: <http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/> Hope that helps. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the pointer. It seems that wrap allows you to conditionally change existing functionality, allowing for fallback to original functionality in the default case. Good if you don''t want to edit nice, tested framework code. In my case, I want to replace tags from the outside in kind of iteratively. So, in pseudo-code: startString = ''[q]outside level[q]inner level[/q]back to outer[/q]completely outside quote block''; I''m guessing that iteration and greedy matching is the only way to do it. Am I missing something? Thanks again, Steve Dan Dorman wrote:> > > On Nov 8, 2007 2:16 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Is there a straightforward >> way to match and process the nestings using a function as a second >> argument >> to gsub? > > I''m not sure this will work for what you''re doing, but using 1.6''s > wrap feature sounds like it could be just the ticket. > > Kangax wrote a great lil'' article about it: > > <http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/> > > Hope that helps. > > :Dan Dorman > > > > >-- View this message in context: http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13656395 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
wouldn''t just replacing [q] with <div class=''padleft''> and [/q] with </div> give you that effect if the class gave some left padding? You''d end up with nested divs which each gave their own amount of padding... On Nov 9, 2007 10:43 AM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Thanks for the pointer. It seems that wrap allows you to conditionally > change > existing functionality, allowing for fallback to original functionality in > the default case. Good if you don''t want to edit nice, tested framework > code. > > In my case, I want to replace tags from the outside in kind of > iteratively. > So, in pseudo-code: > > startString = ''[q]outside level[q]inner level[/q]back to > outer[/q]completely > outside quote block''; > > I''m guessing that iteration and greedy matching is the only way to do it. > Am > I missing something? > > Thanks again, > > Steve > > > Dan Dorman wrote: > > > > > > On Nov 8, 2007 2:16 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Is there a straightforward > >> way to match and process the nestings using a function as a second > >> argument > >> to gsub? > > > > I''m not sure this will work for what you''re doing, but using 1.6''s > > wrap feature sounds like it could be just the ticket. > > > > Kangax wrote a great lil'' article about it: > > > > <http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/> > > > > Hope that helps. > > > > :Dan Dorman > > > > > > > > > > > -- > View this message in context: > http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13656395 > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah, that''s what I wound up doing. I did (at one point) want to count and style differently based on level of nesting, but prob''ly not worth the extra work. thx Gareth Evans-6 wrote:> > wouldn''t just replacing [q] with <div class=''padleft''> and [/q] with > </div> > give you that effect if the class gave some left padding? > You''d end up with nested divs which each gave their own amount of > padding... > > > On Nov 9, 2007 10:43 AM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> Thanks for the pointer. It seems that wrap allows you to conditionally >> change >> existing functionality, allowing for fallback to original functionality >> in >> the default case. Good if you don''t want to edit nice, tested framework >> code. >> >> In my case, I want to replace tags from the outside in kind of >> iteratively. >> So, in pseudo-code: >> >> startString = ''[q]outside level[q]inner level[/q]back to >> outer[/q]completely >> outside quote block''; >> >> I''m guessing that iteration and greedy matching is the only way to do it. >> Am >> I missing something? >> >> Thanks again, >> >> Steve >> >> >> Dan Dorman wrote: >> > >> > >> > On Nov 8, 2007 2:16 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Is there a straightforward >> >> way to match and process the nestings using a function as a second >> >> argument >> >> to gsub? >> > >> > I''m not sure this will work for what you''re doing, but using 1.6''s >> > wrap feature sounds like it could be just the ticket. >> > >> > Kangax wrote a great lil'' article about it: >> > >> > <http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/> >> > >> > Hope that helps. >> > >> > :Dan Dorman >> > >> > > >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13656395 >> Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. >> >> >> > >> > > > > >-- View this message in context: http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13660603 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You can still do that. If you, say used ''quote'' as your class and replaced [q] with <div class=''quote''> and [/q] with </div> then in your css you could use div.quote { padding-left:10px; } div.quote div.quote /* 2nd level */ { padding-left:20px; /* yeilds a total of 30px padding */ } div.quote div.quote div.quote /* third level */ { padding-left:30px; /* total of 60px padding */ color:#999999; } etc. You''d still need to define a fixed number of quote styles but once you get beyond, say, 4, i''d just leave them all the same. Gareth On Nov 9, 2007 3:50 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Yeah, that''s what I wound up doing. I did (at one point) want to count and > style differently based on level of nesting, but prob''ly not worth the > extra > work. > > thx > > > Gareth Evans-6 wrote: > > > > wouldn''t just replacing [q] with <div class=''padleft''> and [/q] with > > </div> > > give you that effect if the class gave some left padding? > > You''d end up with nested divs which each gave their own amount of > > padding... > > > > > > On Nov 9, 2007 10:43 AM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >> > >> > >> Thanks for the pointer. It seems that wrap allows you to conditionally > >> change > >> existing functionality, allowing for fallback to original functionality > >> in > >> the default case. Good if you don''t want to edit nice, tested framework > >> code. > >> > >> In my case, I want to replace tags from the outside in kind of > >> iteratively. > >> So, in pseudo-code: > >> > >> startString = ''[q]outside level[q]inner level[/q]back to > >> outer[/q]completely > >> outside quote block''; > >> > >> I''m guessing that iteration and greedy matching is the only way to do > it. > >> Am > >> I missing something? > >> > >> Thanks again, > >> > >> Steve > >> > >> > >> Dan Dorman wrote: > >> > > >> > > >> > On Nov 8, 2007 2:16 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> Is there a straightforward > >> >> way to match and process the nestings using a function as a second > >> >> argument > >> >> to gsub? > >> > > >> > I''m not sure this will work for what you''re doing, but using 1.6''s > >> > wrap feature sounds like it could be just the ticket. > >> > > >> > Kangax wrote a great lil'' article about it: > >> > > >> > <http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/> > >> > > >> > Hope that helps. > >> > > >> > :Dan Dorman > >> > > >> > > > >> > > >> > > >> > >> -- > >> View this message in context: > >> > http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13656395 > >> Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. > >> > >> > >> > > >> > > > > > > > > > > > -- > View this message in context: > http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13660603 > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Steve, I think this is all you need: var i = 0, reStart = /\[q\]/g, reEnd = /\[\/q\]/g, content = ''[q]hello[q]hello1[/q]out[/q]''; content.replace(reStart, ''<div class="q'' + (i++) + ''">'').replace(reEnd, ''</div>'') keep it simple ; ) best, kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
So simple it''s perfect. I overlooked the obvious... Thanks. kangax wrote:> > > Steve, > I think this is all you need: > > var i = 0, > reStart = /\[q\]/g, > reEnd = /\[\/q\]/g, > content = ''[q]hello[q]hello1[/q]out[/q]''; > > content.replace(reStart, ''<div class="q'' + (i++) + > ''">'').replace(reEnd, ''</div>'') > > keep it simple ; ) > > best, > kangax > > > > > >-- View this message in context: http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13661544 Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey kangax, isn''t using the same class name and chaining them in the css even simpler? On Nov 9, 2007 5:52 PM, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > So simple it''s perfect. I overlooked the obvious... Thanks. > > > kangax wrote: > > > > > > Steve, > > I think this is all you need: > > > > var i = 0, > > reStart = /\[q\]/g, > > reEnd = /\[\/q\]/g, > > content = ''[q]hello[q]hello1[/q]out[/q]''; > > > > content.replace(reStart, ''<div class="q'' + (i++) + > > ''">'').replace(reEnd, ''</div>'') > > > > keep it simple ; ) > > > > best, > > kangax > > > > > > > > > > > > > -- > View this message in context: > http://www.nabble.com/Help-W--gsub-on-Nested-Expression-tf4773701.html#a13661544 > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---