Sha256: f3d590457169e8400016b9fd56bc9b4517842cc09c79a7e289f739fc53689db2

Contents?: true

Size: 1.44 KB

Versions: 22

Compression:

Stored size: 1.44 KB

Contents

module Praxis
  module Extensions

    module Rendering
      extend ActiveSupport::Concern
      include FieldExpansion

      def render(object, include_nil: false)
        loaded = self.media_type.load(object)
        renderer = Praxis::Renderer.new(include_nil: include_nil)
        renderer.render(loaded, self.expanded_fields)
      rescue Attributor::DumpError
        if self.media_type.domain_model == Object
          warn "Detected the rendering of an object of type #{self.media_type} without having a domain object model set.\n" +
               "Did you forget to define it?"
        end
        raise
      end

      def display(object, include_nil: false, encoder: self.default_encoder )
        identifier = Praxis::MediaTypeIdentifier.load(self.media_type.identifier)
        identifier += encoder unless encoder.blank?
        response.headers['Content-Type'] = identifier.to_s
        response.body = render(object, include_nil: include_nil)
        response
      rescue Praxis::Renderer::CircularRenderingError => e
          Praxis::Application.instance.validation_handler.handle!(
          summary: "Circular Rendering Error when rendering response. " +
                   "Please especify a view to narrow the dependent fields, or narrow your field set.",
          exception: e,
          request: request,
          stage: :action,
          errors: nil
        )
      end

      def default_encoder
        ''
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.17 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.16 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.15 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.14 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.13 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.12 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.11 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.10 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.9 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.8 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.7 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.6 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.5 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.4 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.3 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.2 lib/praxis/extensions/rendering.rb
praxis-2.0.pre.1 lib/praxis/extensions/rendering.rb
praxis-0.21 lib/praxis/extensions/rendering.rb
praxis-0.20.1 lib/praxis/extensions/rendering.rb