Class: Pakyow::Presenter::Composers::View Private
- Inherits:
-
Object
- Object
- Pakyow::Presenter::Composers::View
- Extended by:
- Support::ClassState
- Defined in:
- lib/pakyow/presenter/composers/view.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.
Direct Known Subclasses
Constant Summary collapse
- UNRETAINED_SIGNIFICANCE =
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.
%i(container partial template).freeze
Instance Attribute Summary collapse
- #view_path ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(view_path, app:) ⇒ View
constructor
private
A new instance of View.
- #key ⇒ Object private
- #view(return_cached: false) ⇒ Object private
Constructor Details
#initialize(view_path, app:) ⇒ View
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 View.
26 27 28 29 |
# File 'lib/pakyow/presenter/composers/view.rb', line 26 def initialize(view_path, app:) @view_path = String.normalize_path(view_path) @app = app end |
Instance Attribute Details
#view_path ⇒ 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.
22 23 24 |
# File 'lib/pakyow/presenter/composers/view.rb', line 22 def view_path @view_path end |
Instance Method Details
#key ⇒ 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.
31 32 33 |
# File 'lib/pakyow/presenter/composers/view.rb', line 31 def key @view_path end |
#view(return_cached: false) ⇒ 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pakyow/presenter/composers/view.rb', line 35 def view(return_cached: false) cache_key = :"#{@app.config.name}__#{@view_path}" unless view = View.__cache[cache_key] unless info = @app.view_info_for_path(@view_path) error = UnknownPage.new("No view at path `#{@view_path}'") error.context = @view_path raise error end info = info.deep_dup view = info[:layout].build(info[:page]).tap { |view_without_partials| view_without_partials.mixin(info[:partials]) } # We collapse built views down to significance that is considered "renderable". This is # mostly an optimization, since it lets us collapse some nodes into single strings and # reduce the number of operations needed for a render. # # FIXME: This breaks when a collapsed string doc is transformed. Once that's fixed, we # can enable this code again. It's pretty low-priority and not worth fixing right now. # # view.object.collapse( # *(StringDoc.significant_types.keys - UNRETAINED_SIGNIFICANCE) # ) # Empty nodes are removed as another render-time optimization leading to fewer operations. # view.object.remove_empty_nodes View.__cache[cache_key] = view end if return_cached view else view.dup end end |