Chris Mear
2006-Oct-23 22:39 UTC
Using ActiveSupport::JSON in PrototypeHelper, ScriptaculousHelper
Hi all, I was looking at this ticket: http://dev.rubyonrails.org/ticket/6265 and it got me thinking: is there any reason we''re not using the tasty ActiveSupport::JSON encoder to assemble options for the various helper methods in PrototypeHelper and ScriptaculousHelper? At the moment, they use options_for_javascript() in JavaScriptHelper, which is a half-hearted JSON generator that doesn''t handle strings vs. literals very well, let alone nested hashes, arrays, etc. The result is a bunch of scattered JSON-generating code in the individual helper methods (e.g. visual_effect()). It would seem logical to make use of ActiveSupport::JSON instead, and keep all that knowledge in one place. I''ve done a bit of experimenting, and it does seem to make things neater. The only problem I can think of is that options_for_javascript() currently doesn''t automatically add quotes around strings, whereas AS::JSON does. So there''s lots of code in the wild that adds the single-quotes manually for certain options: visual_effect(:highlight, "posts", :endcolor => "''#eeeeee''") We''d probably have to work around this to maintain compatibility, which might just make the code even more complicated than it is now. So maybe this is a wild goose chase. Thoughts? Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---