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
- #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.
7 8 9 10 |
# File 'lib/jbuilder/schema/renderer.rb', line 7 def initialize(paths, default_locals = nil) @view_renderer = @@view_renderer.with_view_paths(paths) @default_locals = default_locals end |
Instance Method Details
#json ⇒ Object
16 17 18 |
# File 'lib/jbuilder/schema/renderer.rb', line 16 def json(...) normalize(render(...)).to_json end |
#render(object = nil, title: nil, description: nil, assigns: nil, **options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jbuilder/schema/renderer.rb', line 20 def render(object = nil, title: nil, description: nil, assigns: nil, **) if object partial_path = object.respond_to?(:to_partial_path_for_jbuilder_schema) ? object.to_partial_path_for_jbuilder_schema : object.to_partial_path .merge! partial: partial_path, object: object end [:locals] ||= {} [:locals].merge! @default_locals if @default_locals [:locals][:__jbuilder_schema_options] = { model: object&.class, title: title, description: description } @view_renderer.assign assigns if assigns @view_renderer.render() end |
#yaml ⇒ Object
12 13 14 |
# File 'lib/jbuilder/schema/renderer.rb', line 12 def yaml(...) normalize(render(...)).to_yaml end |