Class: Confinement::Rendering::ViewContext
- Inherits:
-
Object
- Object
- Confinement::Rendering::ViewContext
- Defined in:
- lib/confinement.rb
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#frontmatter ⇒ Object
readonly
Returns the value of attribute frontmatter.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #capture ⇒ Object
-
#initialize(routes:, layouts:, assets:, contents:, locals:, frontmatter:) ⇒ ViewContext
constructor
A new instance of ViewContext.
- #render(blob, layout: nil, &block) ⇒ Object
Constructor Details
#initialize(routes:, layouts:, assets:, contents:, locals:, frontmatter:) ⇒ ViewContext
Returns a new instance of ViewContext.
557 558 559 560 561 562 563 564 565 |
# File 'lib/confinement.rb', line 557 def initialize(routes:, layouts:, assets:, contents:, locals:, frontmatter:) @routes = routes @layouts = layouts @assets = assets @contents = contents @locals = locals @frontmatter = frontmatter end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
569 570 571 |
# File 'lib/confinement.rb', line 569 def assets @assets end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
570 571 572 |
# File 'lib/confinement.rb', line 570 def contents @contents end |
#frontmatter ⇒ Object (readonly)
Returns the value of attribute frontmatter.
572 573 574 |
# File 'lib/confinement.rb', line 572 def frontmatter @frontmatter end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
568 569 570 |
# File 'lib/confinement.rb', line 568 def layouts @layouts end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
571 572 573 |
# File 'lib/confinement.rb', line 571 def locals @locals end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
567 568 569 |
# File 'lib/confinement.rb', line 567 def routes @routes end |
Instance Method Details
#capture ⇒ Object
574 575 576 577 578 579 580 581 |
# File 'lib/confinement.rb', line 574 def capture original_buffer = @_buf @_buf = +"" yield @_buf ensure @_buf = original_buffer end |
#render(blob, layout: nil, &block) ⇒ Object
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/confinement.rb', line 583 def render(blob, layout: nil, &block) render_chain = RenderChain.new( body: blob.body, path: blob.input_path, renderers: blob.renderers, view_context: self ) rendered_body = if block_given? render_chain.call do capture { yield } end else render_chain.call end if layout layout_render_chain = RenderChain.new( body: layout.body, path: layout.input_path, renderers: layout.renderers, view_context: self ) layout_render_chain.call do rendered_body end else rendered_body end end |