class Pakyow::Presenter::Composers::View
@api private
Constants
- UNRETAINED_SIGNIFICANCE
Attributes
view_path[R]
Public Class Methods
new(view_path, app:)
click to toggle source
# File lib/pakyow/presenter/composers/view.rb, line 26 def initialize(view_path, app:) @view_path = String.normalize_path(view_path) @app = app end
Public Instance Methods
key()
click to toggle source
# File lib/pakyow/presenter/composers/view.rb, line 31 def key @view_path end
view(return_cached: false)
click to toggle source
# 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