Skip to content

render Liquid fields by default via thread-local context - #1583

Closed
MattBudz wants to merge 3 commits into
developfrom
liquid/render-by-default-poc
Closed

render Liquid fields by default via thread-local context#1583
MattBudz wants to merge 3 commits into
developfrom
liquid/render-by-default-poc

Conversation

@MattBudz

Copy link
Copy Markdown
Contributor

Summary

This is a proof of concept for a render-by-default architecture where issue.fields, issue.title, and equivalent evidence/note accessors return Liquid-rendered values automatically in request contexts, with no view changes required.

Three moving parts, all in CE:

1. LiquidRenderContext (app/lib/liquid_render_context.rb, new)
Thread-local context holder. Controllers set a lazy evaluator (proc) before the view renders; it is cleared in an ensure block. The lazy proc defers liquid_assigns evaluation until the first field access, after all before_actions have run.

2. HasFields#dradis_has_fields_for
raw_fields contains the existing parser logic, unchanged. fields calls raw_fields, renders Liquid values when a context is present, and memoizes the result on the instance. set_field and delete_field now write through raw_fields so rendered output is never saved back to the database. title inherits rendering automatically since it delegates to fields.fetch('Title', ...).

3. LiquidEnabledResource
One around_action :with_liquid_render_context added to the concern already included by IssuesController, EvidenceController, NotesController, and others. No per-controller changes needed.

DiffedContent updated throughout to call raw_fields instead of fields so sync/diff operations always work with raw Liquid templates and cannot write rendered output back to the database.

Verified

  • Issue with {{ project.name }} in Title: index table, show heading, breadcrumb, and page <title> all render the project name
  • Edit form textarea shows the raw Liquid template (form binds to :text, not fields)
  • Background/API contexts never set a context, so fields returns raw values, unchanged behavior

Check List

  • Added a CHANGELOG entry
  • Commit message has a detailed description of what changed and why.

Introduce LiquidRenderContext, a thread-local context holder that
controllers set before the view renders and clear afterwards. HasFields
gains a raw_fields method (previous fields logic) and an updated fields
method that renders Liquid values when context is present. set_field and
delete_field now write raw_fields so rendered output is never persisted.
LiquidEnabledResource registers an around_action to set the context for
controllers that already include it (IssuesController, EvidenceController,
etc.).

This eliminates one-off Liquid rendering fixes per view. Any attribute
read via fields or title in a request context is rendered automatically.
Tighten rescue to Liquid::Error (was StandardError), add filters: []
to match the existing liquid_filter.rb options, and update DiffedContent
to call raw_fields throughout so rendered Liquid output is never written
back to record.content or used as source for field sync operations.
@caitmich caitmich closed this May 1, 2026
@caitmich
caitmich deleted the liquid/render-by-default-poc branch May 1, 2026 14:36
@caitmich

caitmich commented May 1, 2026

Copy link
Copy Markdown
Contributor

#1584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants