Class: Dry::View::Renderer Private
- Inherits:
-
Object
- Object
- Dry::View::Renderer
- Extended by:
- Core::Cache
- Defined in:
- lib/dry/view/renderer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- PARTIAL_PREFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"_"- PATH_DELIMITER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"/"- TemplateNotFoundError =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Class.new(StandardError)
Instance Attribute Summary collapse
- #engine_mapping ⇒ Object readonly private
- #format ⇒ Object readonly private
- #options ⇒ Object readonly private
- #paths ⇒ Object readonly private
Instance Method Summary collapse
- #chdir(dirname) ⇒ Object private
-
#initialize(paths, format:, engine_mapping: nil, **options) ⇒ Renderer
constructor
private
A new instance of Renderer.
- #lookup(name) ⇒ Object private
- #partial(name, scope, &block) ⇒ Object private
- #render(path, scope, &block) ⇒ Object private
- #template(name, scope, &block) ⇒ Object private
Constructor Details
#initialize(paths, format:, engine_mapping: nil, **options) ⇒ Renderer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Renderer.
22 23 24 25 26 27 |
# File 'lib/dry/view/renderer.rb', line 22 def initialize(paths, format:, engine_mapping: nil, **) @paths = paths @format = format @engine_mapping = engine_mapping || {} = end |
Instance Attribute Details
#engine_mapping ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/dry/view/renderer.rb', line 20 def engine_mapping @engine_mapping end |
#format ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/dry/view/renderer.rb', line 20 def format @format end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/dry/view/renderer.rb', line 20 def end |
#paths ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/dry/view/renderer.rb', line 20 def paths @paths end |
Instance Method Details
#chdir(dirname) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 |
# File 'lib/dry/view/renderer.rb', line 48 def chdir(dirname) new_paths = paths.map { |path| path.chdir(dirname) } self.class.new(new_paths, format: format, **) end |
#lookup(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 |
# File 'lib/dry/view/renderer.rb', line 54 def lookup(name) paths.inject(false) { |_, path| result = path.lookup(name, format, include_shared: false) break result if result } end |
#partial(name, scope, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/dry/view/renderer.rb', line 40 def partial(name, scope, &block) template(name_for_partial(name), scope, &block) end |
#render(path, scope, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/dry/view/renderer.rb', line 44 def render(path, scope, &block) tilt(path).render(scope, &block) end |
#template(name, scope, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dry/view/renderer.rb', line 29 def template(name, scope, &block) path = lookup(name) if path render(path, scope, &block) else msg = "Template #{name.inspect} could not be found in paths:\n#{paths.map { |pa| "- #{pa.to_s}" }.join("\n")}" raise TemplateNotFoundError, msg end end |