Class: Jbuilder::Schema::Renderer
- Inherits:
-
Object
- Object
- Jbuilder::Schema::Renderer
- Defined in:
- lib/jbuilder/schema/renderer.rb
Constant Summary collapse
- @@view_renderer =
ActionView::Base.with_empty_template_cache
Instance Method Summary collapse
-
#initialize(paths, default_locals = nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #json ⇒ Object
-
#original_render(options = {}, locals = {}) ⇒ Object
Thin wrapper around the regular Jbuilder JSON output render, which also parses it into a hash.
- #render(object = nil, title: nil, description: nil, assigns: nil, **options) ⇒ Object
- #yaml ⇒ Object
Constructor Details
#initialize(paths, default_locals = nil) ⇒ Renderer
Returns a new instance of Renderer.
8 9 10 11 |
# File 'lib/jbuilder/schema/renderer.rb', line 8 def initialize(paths, default_locals = nil) @view_renderer = @@view_renderer.with_view_paths(paths) @default_locals = default_locals end |
Instance Method Details
#json ⇒ Object
17 18 19 |
# File 'lib/jbuilder/schema/renderer.rb', line 17 def json(...) normalize(render(...)).to_json end |
#original_render(options = {}, locals = {}) ⇒ Object
Thin wrapper around the regular Jbuilder JSON output render, which also parses it into a hash.
46 47 48 |
# File 'lib/jbuilder/schema/renderer.rb', line 46 def original_render( = {}, locals = {}) JSON.parse @view_renderer.render(, locals) end |
#render(object = nil, title: nil, description: nil, assigns: nil, **options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jbuilder/schema/renderer.rb', line 21 def render(object = nil, title: nil, description: nil, assigns: nil, **) @view_renderer.assign assigns if assigns partial_path = %i[to_partial_path_for_jbuilder_schema to_partial_path].map { object.public_send(_1) if object.respond_to?(_1) }.compact.first if partial_path [:partial] = partial_path [:object] = object end json = if partial_path original_render(.dup, .dup) else original_render(object || .dup, .dup) end [:locals] ||= {} [:locals].merge! @default_locals if @default_locals [:locals][:__jbuilder_schema_options] = {json: json, object: object, title: title, description: description} @view_renderer.render().then do |result| result.respond_to?(:unwrap_target!) ? result.unwrap_target! : result end end |
#yaml ⇒ Object
13 14 15 |
# File 'lib/jbuilder/schema/renderer.rb', line 13 def yaml(...) normalize(render(...)).to_yaml end |