lib/jbuilder/jbuilder_template.rb in jbuilder-1.5.1 vs lib/jbuilder/jbuilder_template.rb in jbuilder-1.5.2

- old
+ new

@@ -20,17 +20,19 @@ else # partial! 'name', foo: 'bar' options = { :partial => name_or_options, :locals => locals } as = locals.delete(:as) options[:as] = as if as.present? - options[:collection] = locals[:collection] + options[:collection] = locals[:collection] if locals.key?(:collection) end + options[:collection] ||= [] if options.key?(:collection) + _handle_partial_options options end - def array!(collection, *attributes, &block) + def array!(collection = [], *attributes, &block) options = attributes.extract_options! if options.key?(:partial) partial! options[:partial], options.merge(:collection => collection) else @@ -41,11 +43,11 @@ # Caches the json constructed within the block passed. Has the same signature as the `cache` helper # method in `ActionView::Helpers::CacheHelper` and so can be used in the same way. # # Example: # - # json.cache! ['v1', @person], :expires_in => 10.minutes do + # json.cache! ['v1', @person], expires_in: 10.minutes do # json.extract! @person, :name, :age # end def cache!(key=nil, options={}, &block) if @context.controller.perform_caching value = ::Rails.cache.fetch(_cache_key(key), options) do @@ -90,10 +92,18 @@ @context.fragment_name_with_digest(key) else ::ActiveSupport::Cache.expand_cache_key(key.is_a?(::Hash) ? url_for(key).split('://').last : key, :jbuilder) end end + + private + + def _mapable_arguments?(value, *args) + return true if super + options = args.last + ::Hash === options && options.key?(:as) + end end class JbuilderHandler cattr_accessor :default_format self.default_format = Mime::JSON @@ -103,6 +113,6 @@ %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{template.source} json.target! unless __already_defined} end end -ActionView::Template.register_template_handler :jbuilder, JbuilderHandler \ No newline at end of file +ActionView::Template.register_template_handler :jbuilder, JbuilderHandler