using Astralis; using Invercargill; using Invercargill.DataStructures; using Inversion; using Spry; /** * CardComponent: A wrapper component that accepts content via spry-content. * * The tag acts as a placeholder where parent components * can inject their own content. When a parent uses: * * * ...content here... * * * The nested content replaces the tag in the rendered output. */ class CardComponent : Component { public override string markup { get { return """
"""; }} } /** * AlertComponent: Another wrapper component styled for warnings/info. * * This demonstrates that spry-content can be used in multiple components * with different styling. The content injection works the same way - * whatever is nested inside the spry-component tag gets placed where * appears. */ class AlertComponent : Component { public override string markup { get { return """
"""; }} } /** * PageComponent: The main page layout that uses CardComponent and AlertComponent. * * This component demonstrates content injection by nesting different content * inside each wrapper component. The nested HTML (headings, paragraphs, etc.) * will be injected where appears in each child component. */ class PageComponent : Component { public override string markup { get { return """ Content Injection Example

Spry Content Injection Example

This page demonstrates the spry-content tag for injecting content into child components.

Welcome!

This content is injected into the CardComponent. The blue border and padding come from the component's styling.

Any HTML can be placed here - forms, images, other components, etc.

Notice: This is an informational alert. The yellow styling and left border come from AlertComponent.

Features

  • Components can be reused with different content
  • Styling is encapsulated in the wrapper component
  • Content is flexible and parent-controlled
Warning: This demonstrates another use of AlertComponent with completely different content. """; }} } /** * HomePageEndpoint: Serves the PageComponent. */ class HomePageEndpoint : Object, Endpoint { private PageComponent page_component = inject(); public async Astralis.HttpResult handle_request(Astralis.HttpContext http_context, Astralis.RouteContext route_context) throws Error { return yield page_component.to_result(); } } void main(string[] args) { int port = args.length > 1 ? int.parse(args[1]) : 8080; try { var application = new WebApplication(port); application.use_compression(); application.add_module(); application.add_transient(); application.add_transient(); application.add_transient(); application.add_endpoint(new EndpointRoute("/")); application.run(); } catch (Error e) { printerr("Error: %s\n", e.message); Process.exit(1); } }