diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/json.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoders/core.rb | 4 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json.rb b/activesupport/lib/active_support/json.rb index 77c7225c66..943adebd35 100644 --- a/activesupport/lib/active_support/json.rb +++ b/activesupport/lib/active_support/json.rb @@ -3,7 +3,15 @@ require 'active_support/json/encoders' module ActiveSupport module JSON #:nodoc: class CircularReferenceError < StandardError; end - + # returns the literal string as its JSON encoded form. Useful for passing javascript variables into functions. + # + # page.call 'Element.show', ActiveSupport::JSON::Variable.new("$$(#items li)") + class Variable < String + def to_json + self + end + end + class << self REFERENCE_STACK_VARIABLE = :json_reference_stack diff --git a/activesupport/lib/active_support/json/encoders/core.rb b/activesupport/lib/active_support/json/encoders/core.rb index 003c938be4..d3193af555 100644 --- a/activesupport/lib/active_support/json/encoders/core.rb +++ b/activesupport/lib/active_support/json/encoders/core.rb @@ -56,6 +56,10 @@ module ActiveSupport result << '}' end end + + define_encoder Regexp do |regexp| + regexp.inspect + end end end end |