lib/jsonr/generator.rb in jsonr-0.0.2 vs lib/jsonr/generator.rb in jsonr-0.1.0

- old
+ new

@@ -1,7 +1,10 @@ # Jsonr +require 'active_support/ordered_hash' +require 'active_support/json' + module Jsonr class Generator def initialize(&block) @@ -9,11 +12,11 @@ block.call(self) if block_given? end # Convert to a JSON string representation. def to_s - @commands.to_json + ActiveSupport::JSON.encode(@commands) end # Replaces a content of an element with given selector with given value. # # Example: @@ -91,11 +94,11 @@ # # # Show a flash message notice # page.flash :notice, "A person detail's were updated." # def flash(severity, message) - @commands[:flash] ||= {} + @commands[:flash] ||= ActiveSupport::OrderedHash.new @commands[:flash][severity] = message end # Hides elements with given +selectors+. # @@ -142,9 +145,14 @@ def remove(*selectors) @commands[:remove] ||= [] @commands[:remove].push *selectors end + # Sets given +key+ to a given +value+. Useful for passing custom objects. + # + # Example: + # + # page.data :person, @person def data(key, value) @commands[key] = value end end \ No newline at end of file