Class: Charming::Presentation::Markdown::RenderContext

Inherits:
Data
  • Object
show all
Defined in:
lib/charming/presentation/markdown/render_context.rb

Overview

RenderContext carries the state needed to render nested Markdown blocks: the current list nesting depth (used for indentation) and the wrap width.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#list_depthObject (readonly)

Returns the value of attribute list_depth

Returns:

  • (Object)

    the current value of list_depth



8
9
10
# File 'lib/charming/presentation/markdown/render_context.rb', line 8

def list_depth
  @list_depth
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



8
9
10
# File 'lib/charming/presentation/markdown/render_context.rb', line 8

def width
  @width
end

Class Method Details

.from(width:, list_depth: 0) ⇒ Object

Builds a new RenderContext with the given width and optional starting list_depth.



10
11
12
# File 'lib/charming/presentation/markdown/render_context.rb', line 10

def self.from(width:, list_depth: 0)
  new(list_depth: list_depth, width: width)
end

Instance Method Details

#nested(depth_increment: 0, width: self.width) ⇒ Object

Returns a derived context with the list depth incremented by depth_increment and the wrap width overridden to width (defaults to the current width).



16
17
18
# File 'lib/charming/presentation/markdown/render_context.rb', line 16

def nested(depth_increment: 0, width: self.width)
  self.class.new(list_depth: list_depth + depth_increment, width: width)
end