crumble-cookie-consent

crumble-cookie-consent

Cookie-consent support for Crumble.

Requiring this shard keeps Crumble's essential session cookie scoped to the current browser session until the user gives consent. After consent, the same cookie is reissued with the lifetime configured by the application. Applications can use ctx.cookie_consented? to guard optional cookie-dependent features.

Installation

Add the dependency to your shard.yml:

dependencies:
  crumble-cookie-consent:
    github: sbsoftware/crumble-cookie-consent

Then run shards install and require the shard from your application:

require "crumble-cookie-consent"

Usage

Render the fixed consent banner in the application layout:

ToHtml.class_template do
  html do
    body do
      yield
      Crumble::Cookie::Consent::Action.new(ctx).action_template.to_html
    end
  end
end

The banner submits through crumble-turbo, records consent in the session, and removes itself after a successful submission. The typed CSS class Crumble::Cookie::Consent::Banner is applied to its outer element for application styling. A default banner style is added to the layout automatically inside the crumble-cookie-consent cascade layer. Normal, unlayered application rules targeting Crumble::Cookie::Consent::Banner take precedence over these defaults without requiring additional selector specificity.

Configure the post-consent lifetime through Crumble's existing request-context method:

class Crumble::Server::RequestContext
  def session_cookie_max_age
    365.days
  end
end

Without consent, this configured value is intentionally ignored and new session cookies have no Max-Age. If the method returns nil, the cookie remains scoped to the browser session after consent as well.

Guard optional behavior wherever a request context is available:

if ctx.cookie_consented?
  enable_optional_cookie_feature
else
  show_cookie_consent_hint
end

The shard does not block application behavior automatically. It remains the application's responsibility to guard any feature that requires consent.

Development

shards install
crystal tool format --check src spec
crystal spec

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Add focused specs for the changed behavior.
  4. Run formatting and the full spec suite.
  5. Open a pull request.

Contributors

Repository

crumble-cookie-consent

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 2
  • about 7 hours ago
  • September 14, 2026
License

MIT License

Links
Synced at

Mon, 14 Sep 2026 19:14:20 GMT

Languages