Class: Banzai::RenderContext
- Inherits:
-
Object
- Object
- Banzai::RenderContext
- 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
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
Instance Method Summary collapse
-
#associate_document(document, object) ⇒ Object
Associates an HTML document with a Project.
-
#initialize(default_project = nil, current_user = nil) ⇒ RenderContext
constructor
default_project - The default project to use for all documents, if any.
- #project_for_node(node) ⇒ Object
Constructor Details
#initialize(default_project = nil, current_user = nil) ⇒ 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 |
# File 'lib/banzai/render_context.rb', line 11 def initialize(default_project = nil, current_user = nil) @current_user = current_user @projects = Hash.new(default_project) end |
Instance Attribute Details
#current_user ⇒ Object (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 |
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.
20 21 22 23 24 25 26 |
# File 'lib/banzai/render_context.rb', line 20 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
28 29 30 |
# File 'lib/banzai/render_context.rb', line 28 def project_for_node(node) @projects[node.document] end |