Sha256: 15e5698abb707adb9f5887a98da8a1eb887e88b7d311453a7bac8dd532854048

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

# The PathRenderer is a simple way to render a string of the contents of a view
# at the passed in path.

require 'volt/page/bindings/view_binding/view_lookup_for_path'
require 'volt/page/bindings/view_binding/controller_handler'
require 'volt/page/string_template_renderer'

module Volt
  class ViewLookupException < Exception; end
  class PathStringRenderer
    attr_reader :html
    def initialize(volt_app, path, attrs = nil, page = nil, render_from_path = nil)
      # where to do the path lookup from
      render_from_path ||= 'main/main/main/body'

      page ||= volt_app.page

      # Make path into a full path
      @view_lookup = Volt::ViewLookupForPath.new(page, render_from_path)
      full_path, controller_path = @view_lookup.path_for_template(path, nil)

      if full_path.nil?
        fail ViewLookupException, "Unable to find view at `#{path}`"
      end

      controller_class, action = ControllerHandler.get_controller_and_action(controller_path)

      controller = controller_class.new(volt_app) # (SubContext.new(attrs, nil, true))
      controller.model = SubContext.new(attrs, nil, true)

      renderer = StringTemplateRenderer.new(volt_app, controller, full_path)

      @html = renderer.html

      # remove when done
      renderer.remove
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
volt-0.9.4.pre3 lib/volt/page/path_string_renderer.rb
volt-0.9.4.pre2 lib/volt/page/path_string_renderer.rb
volt-0.9.4.pre1 lib/volt/page/path_string_renderer.rb
volt-0.9.3 lib/volt/page/path_string_renderer.rb
volt-0.9.3.pre6 lib/volt/page/path_string_renderer.rb
volt-0.9.3.pre5 lib/volt/page/path_string_renderer.rb
volt-0.9.3.pre4 lib/volt/page/path_string_renderer.rb
volt-0.9.3.pre3 lib/volt/page/path_string_renderer.rb
volt-0.9.3.pre2 lib/volt/page/path_string_renderer.rb