render Liquid fields by default via thread-local context - #1583
Closed
MattBudz wants to merge 3 commits into
Closed
Conversation
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.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ensureblock. The lazy proc defersliquid_assignsevaluation until the first field access, after allbefore_actionshave run.2.
HasFields#dradis_has_fields_forraw_fieldscontains the existing parser logic, unchanged.fieldscallsraw_fields, renders Liquid values when a context is present, and memoizes the result on the instance.set_fieldanddelete_fieldnow write throughraw_fieldsso rendered output is never saved back to the database.titleinherits rendering automatically since it delegates tofields.fetch('Title', ...).3.
LiquidEnabledResourceOne
around_action :with_liquid_render_contextadded to the concern already included byIssuesController,EvidenceController,NotesController, and others. No per-controller changes needed.DiffedContentupdated throughout to callraw_fieldsinstead offieldsso sync/diff operations always work with raw Liquid templates and cannot write rendered output back to the database.Verified
{{ project.name }}in Title: index table, show heading, breadcrumb, and page<title>all render the project name:text, notfields)fieldsreturns raw values, unchanged behaviorCheck List