For example, I want <a href=''link''> rather than <a href="link"> I want to maintain consistency with style. Can this be done? Also, I am trying to use Rails 3.0. Sharkie -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-Jun-16 18:01 UTC
Re: Forcing helper like link_to to use single quotes
On 16 June 2010 18:51, Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> For example, I want <a href=''link''> rather than <a href="link"> > > I want to maintain consistency with style.You want to change the correct (according to the xhtml guidelines) double-quotes, to incorrect single quotes? Wouldn''t it be better to change the single quotes to double? (For compliance, rather than consistence). -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sharkie Landshark wrote:> > For example, I want <a href=''link''> rather than <a href="link"> > > I want to maintain consistency with style. > > Can this be done? > > Also, I am trying to use Rails 3.0. > > SharkieI would not recommend using single quotations over double. One argument against using single quotes is that you will not be able to embed ruby code into your link: "<br />A link to a #{link_to("website", "http://ruby-forum.com")}" If you want consistency, consistently use double quotations. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jun-16 19:48 UTC
Re: Forcing helper like link_to to use single quotes
Pale Horse wrote:> Sharkie Landshark wrote: >> >> For example, I want <a href=''link''> rather than <a href="link"> >> >> I want to maintain consistency with style. >> >> Can this be done? >> >> Also, I am trying to use Rails 3.0. >> >> Sharkie > > I would not recommend using single quotations over double. One argument > against using single quotes is that you will not be able to embed ruby > code into your link: > > "<br />A link to a #{link_to("website", "http://ruby-forum.com")}" >That''s not true. The OP seems to be talking about the quotation marks in the generate HTML, not in the Ruby source code.> If you want consistency, consistently use double quotations.Better yet, don''t worry about it. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser wrote:> > That''s not true. The OP seems to be talking about the quotation marks > in the generate HTML, not in the Ruby source code. > > > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.orgIt would appear I''ve been misguided. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Jun-16 20:01 UTC
Re: Re: Forcing helper like link_to to use single quotes
On Wed, Jun 16, 2010 at 2:39 PM, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> If you want consistency, consistently use double quotations.Always using double quotes causes every string to be interpolated, often when not required. Single quoted string are not interpolated, saving CPU cycles. Computer science 101. -- Greg Donald destiney.com | gregdonald.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 June 2010 21:01, Greg Donald <gdonald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Jun 16, 2010 at 2:39 PM, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> If you want consistency, consistently use double quotations. > > Always using double quotes causes every string to be interpolated, > often when not required. Single quoted string are not interpolated, > saving CPU cycles. Computer science 101.Looking at the original post it appears he is talking about single/double quotes in the html, not in Ruby code. Interpolation is therefore not occurring. Colin -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sharkie Landshark
2010-Jun-17 15:55 UTC
Re: Re: Forcing helper like link_to to use single quotes
Dear Friends, I am the original poster. I use double quote for all Ruby strings in my Ruby codes. But, I use single quotes for HTML attributes. How would I force such behavior even though it is not compliance etc. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sheesh, I don''t know... Smack yourself in the head every time you type a double-quote for an HTML attribute??? Use an IDE and re-write the syntax rules for the language recognition so it does not allow double-quotes for HTML attributes? Surely, there are more important things you could be learning in the time you are spending trying to force the code to be ''just so''. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Regardless of sharkie''s original intent, there''s a use case where forcing single quotes on an HTML attribute value, generated through a Rails helper, would be useful - namely attaching JSON to HTML elements via HTML 5 data attributes. In order for the JSON to be valid, it needs to be wrapped in single quotes so that double quotes can be utilized within the JSON itself, as required in the JSON spec. Given that single quotes on attribute values are permissible within the HTML spec, I see generating HTML through a Rails helper that uses single, rather than double, quotes as a reasonable request. Unfortunately, I have yet to figure out how. Any ideas would be greatly appreciated. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-13 22:32 UTC
Re: Forcing helper like link_to to use single quotes
Greg Leppert wrote in post #961244:> Regardless of sharkie''s original intent, there''s a use case where > forcing single quotes on an HTML attribute value, generated through a > Rails helper, would be useful - namely attaching JSON to HTML elements > via HTML 5 data attributes. In order for the JSON to be valid, it needs > to be wrapped in single quotes so that double quotes can be utilized > within the JSON itself, as required in the JSON spec. Given that single > quotes on attribute values are permissible within the HTML spec, I see > generating HTML through a Rails helper that uses single, rather than > double, quotes as a reasonable request. Unfortunately, I have yet to > figure out how. Any ideas would be greatly appreciated.I think that HTML-escaping the double quotes in the JSON (i.e. converting to ") would do the trick. Try it and see. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for the response Marnen. Unfortunately, I don''t think that''ll work. Here''s, for instance, what the Webkit Javascript console returns using the native JSON.parse method: JSON.parse("{"test":100}");> SyntaxError: Unable to parse JSON stringJSON.parse("{''test'':100}");> SyntaxError: Unable to parse JSON stringJSON.parse(''{"test":100}'');> Object-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-14 01:34 UTC
Re: Forcing helper like link_to to use single quotes
Greg Leppert wrote in post #961266:> Thanks for the response Marnen. Unfortunately, I don''t think that''ll > work. Here''s, for instance, what the Webkit Javascript console returns > using the native JSON.parse method: > > JSON.parse("{"test":100}"); >> SyntaxError: Unable to parse JSON string > > JSON.parse("{''test'':100}"); >> SyntaxError: Unable to parse JSON string > > JSON.parse(''{"test":100}''); >> ObjectThose tests are irrelevant: by the time the " gets to the JS parser, it will be a double quote, I think. The entity is only for serialization; it will be a " in the parses DOM that JS sees. If you want to test this properly, you need some actual HTML. Try that. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> by the time the " gets to the JS parser, it will be a double quote, I thinkNope, should have mentioned that in the last email. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I stand corrected. I was improperly escaping the quotes when I tested a helper method the first time around. The JSON from my previous example parses correctly when added like so: "data-mydatakey" => "{\"test\":100}" Marnen, sorry for jumping to conclusions and thanks for the help. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.