Is it possible to store a variable like in Capture but make it available everywhere in the parent scope?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
How can I create a Block tag that behaves like a Capture tag, but I want it to be available anywhere in the calling template, not ONLY after it.
For example, the Capture tag looks like:
class Capture < Block
Syntax = /(#{VariableSignature}+)/o
def initialize(tag_name, markup, options)
super
if markup =~ Syntax
@to = $1
else
raise SyntaxError.new(options[:locale].t("errors.syntax.capture"))
end
end
def render(context)
output = super
context.scopes.last[@to] = output
context.resource_limits.assign_score += output.length
''.freeze
end
def blank?
true
end
end
And it currently works like:
{% capture heading %}
Monkeys!
{% endcapture %}
<h1>{{ heading }}</h1>
If you put {{heading}} before the definition of the variable, it doesn't work. Is it possible to make it work even BEFORE the definition? Somehow put the variable in the parent scope?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a Capture implementation based on Block#render and context.scopes.last, but names no repository file or test. Start by tracing how Capture assigns its value and how template variable lookup handles scope and ordering; done requires a maintainer-approved design and coverage for the requested before-definition behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100