module Can
Defined in:
can.crcan/ast.cr
can/cli/render.cr
can/codegen.cr
can/css_scope.cr
can/parser.cr
Constant Summary
-
VERSION =
"0.4.1"
Class Method Summary
-
.raw(s : String) : SafeString
Wraps content as trusted/pre-escaped.
-
.write_escaped(io : IO, value) : Nil
Runtime escape used by codegen for every non-raw
{expr}.
Macro Summary
-
template(path)
Same as
template_inline, but reads the template from a file path resolved relative to the compile-time working directory (typically the project root). -
template_inline(source)
Compiles a template literal at macro expansion time and splices the generated Crystal source in-place.
-
use(path)
Loads a
.canfile as a component library in the surrounding class/module. -
view(path)
Loads a
.canfile as the render surface for the surrounding class.
Class Method Detail
Wraps content as trusted/pre-escaped. Composes with <.raw> — both end
up writing the string verbatim.
Runtime escape used by codegen for every non-raw {expr}. Skips
HTML-escaping when the value is already a SafeString.
Macro Detail
Same as template_inline, but reads the template from a file path
resolved relative to the compile-time working directory (typically the
project root).
io = IO::Memory.new
user = current_user
Can.template "pages/home.can"
When called inside a method body, top-level <.def> blocks are lowered
to local Procs (since Crystal forbids nested defs). Slot-bearing
components must therefore be defined at class/module scope.
Compiles a template literal at macro expansion time and splices the
generated Crystal source in-place. The generated code writes HTML to a
local io (which the caller is responsible for having in scope).
io = IO::Memory.new
name = "Thomas"
Can.template_inline "<p>Hello, {name}!</p>"
io.to_s # => "<p>Hello, Thomas!</p>"
Loads a .can file as a component library in the surrounding
class/module. Top-level <.def> blocks become methods; top-level render
content is rejected so component-only files stay explicit.
module Components
Can.use "components/card.can"
end
Loads a .can file as the render surface for the surrounding class.
Top-level <.def> blocks become methods, and top-level render content is
emitted as render(io : IO).
class HomePage
Can.view "pages/home.can"
end