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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#associate_document(document, object) ⇒ Object
Associates an HTML document with a Project.
-
#initialize(default_project = nil, current_user = nil, options: {}) ⇒ 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, 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 = 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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/banzai/render_context.rb', line 7 def @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 |