module

ERB::Rendering

Instance methods

__erb_esc(value : String) : Nil

Escaping append — what <%= expr %> compiles to.

Source
__erb_esc(value : SafeString) : Nil
Source
__erb_esc(value) : Nil
Source
__erb_out(value : String) : Nil

Raw append (template text, safe HTML).

Source
__erb_out(value : SafeString) : Nil
Source
__erb_render_with_content(name : String | Symbol) : ERB::SafeString

Renders a compiled template method inside a swapped buffer — used for layouts (content = view.__erb_render_action then layout's yield returns it).

Source
capture

Runs the block against a fresh buffer and returns what it wrote.

Source
content_for(key : String | Symbol, &) : Nil

content_for/provide: store a named content block for the layout.

Source
content_for(key : String | Symbol) : SafeString

yield / yield :key inside layouts.

Source
content_for?(key : String | Symbol) : Bool
Source
provide(key : String | Symbol, &) : Nil
Source

Macros

compile_layout(name, path, dedent = false)

Same, but the method takes a block: layouts use <%= yield %> / <%= yield :key %> to inject the action's content.

Source
compile_partials(partials, dedent = false)

Compiles the class's partials and generates the runtime render helpers. partials maps a partial name (as passed to render) to a definition: path — the .erb file, locals — a compile-time map of local variable name to its type:

compile_partials({ "post" => {path: "app/views/_post.html.erb", locals: {"post" => Post}}, })

dedent: true applies the compile-time dedent mode (see compile_template) to every partial in the map.

Locals become real local variables inside the compiled method, so templates reference them bare (<%= post.title %>), exactly like Rails partials. Crystal forbids Object as a generic argument, so the locals-hash value type is the union of all local types (plus Int32 for the collection counter), deduplicated by name — duplicate args inside Union(...) crash the compiler.

Source
compile_template(name, path, dedent = false)

Compiles an ERB-syntax template into a method returning SafeString. path is resolved from the compile-time working directory (like stdlib ECR). dedent: true strips leading whitespace of each line from literal text at compile time, so indented sources render flat output (see template_processor.cr).

Crystal allows redefining a method — a duplicate name would silently shadow a handwritten helper (a runtime crash later, like a nil'd accessor), so collisions fail the build instead. Methods defined AFTER this macro call are not visible to the guard ({% @type.methods %} only sees the type so far).

Source