class TemplateScope

Provides the scope for XRB template rendering.

Templates selectively extract placeholders with self.extract(name) and render the remainder with self.document.

Definitions

def initialize(slide)

Initialize a new template scope for the given slide.

Signature

parameter slide Slide

The slide being rendered.

Implementation

def initialize(slide)
	@slide = slide
	@document = slide.document.dup
	@heading = @document.extract_heading(1)
	@extracted = {}
end

attr :slide

Signature

attribute Slide

The slide being rendered.

def document

Render the slide body after title and placeholder extraction.

Signature

returns XRB::MarkupString

The remaining document as HTML.

Implementation

def document
	markup(@document)
end

def extract(name)

Extract and render a named H2 placeholder from this render's document.

Extraction is cached so a template can reference a placeholder more than once without mutating the document repeatedly.

Signature

parameter name String

The heading name to extract.

returns XRB::MarkupString | Nil

The extracted HTML, or nil when absent.

Implementation

def extract(name)
	fragment = extract_fragment(name)
	return unless fragment && !fragment.empty?
	
	markup(fragment)
end

def slide_header

Render the slide header using semantic markup.

Signature

returns XRB::MarkupString

The rendered header, or an empty string when no metadata is present.

Implementation

def slide_header
	section = @slide.section
	
	return XRB::MarkupString.raw("") unless present?(section) || @heading
	
	builder = XRB::Builder.new
	builder.tag(:header, class: "slide-header") do
		if present?(section)
			builder.tag(:div, class: "slide-section-heading") do
				builder.text(section.to_s)
			end
		end
		
		builder.raw(@heading.to_html) if @heading
	end
	
	XRB::MarkupString.raw(builder.to_s)
end