File: json.rb

package info (click to toggle)
ruby-rabl-rails 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 268 kB
  • ctags: 179
  • sloc: ruby: 1,480; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 594 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module RablRails
  module Renderers
    module JSON
      include Renderers::Hash
      extend self

      def format_output(hash, options = {})
        hash = { options[:root_name] => hash } if options[:root_name] && RablRails.configuration.include_json_root
        json = RablRails.configuration.json_engine.dump(hash)
        params = options.fetch(:params, {})

        RablRails.configuration.enable_jsonp_callbacks && params.has_key?(:callback) ? "#{params[:callback]}(#{json})" : json
      end

      def resolve_cache_key(key, data)
        "#{super}.json"
      end
    end
  end
end