Class: Banzai::RenderContext

Inherits:
Object
  • Object
show all
Defined in:
lib/banzai/render_context.rb

Overview

Object storing the current user, project, and other details used when parsing Markdown references.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_project = nil, current_user = nil, options: {}) ⇒ RenderContext

default_project - The default project to use for all documents, if any. current_user - The user viewing the document, if any.



11
12
13
14
15
# File 'lib/banzai/render_context.rb', line 11

def initialize(default_project = nil, current_user = nil, options: {})
  @current_user = current_user
  @projects = Hash.new(default_project)
  @options = options
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



7
8
9
# File 'lib/banzai/render_context.rb', line 7

def current_user
  @current_user
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/banzai/render_context.rb', line 7

def options
  @options
end

Instance Method Details

#associate_document(document, object) ⇒ Object

Associates an HTML document with a Project.

document - The HTML document to map to a Project. object - The object that produced the HTML document.



21
22
23
24
25
26
27
# File 'lib/banzai/render_context.rb', line 21

def associate_document(document, object)
  # XML nodes respond to "document" but will return a Document instance,
  # even when they belong to a DocumentFragment.
  document = document.document if document.fragment?

  @projects[document] = object.project if object.respond_to?(:project)
end

#project_for_node(node) ⇒ Object



29
30
31
# File 'lib/banzai/render_context.rb', line 29

def project_for_node(node)
  @projects[node.document]
end