mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 02:10:41 -07:00
Remove {% local %} tag
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
require_relative 'assign'
|
|
||||||
|
|
||||||
module Liquid
|
|
||||||
# Local sets a variable in the current scope.
|
|
||||||
#
|
|
||||||
# {% local foo = 'monkey' %}
|
|
||||||
#
|
|
||||||
# You can then use the variable later in the scope.
|
|
||||||
#
|
|
||||||
# {% if true %}
|
|
||||||
# {% local foo = 'monkey' %}
|
|
||||||
# {{ foo }} outputs monkey
|
|
||||||
# {% endif %}
|
|
||||||
# {{ foo }} outputs nothing
|
|
||||||
#
|
|
||||||
class Local < Assign
|
|
||||||
def self.syntax_error_translation_key
|
|
||||||
"errors.syntax.local".freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def render(context)
|
|
||||||
val = @from.render(context)
|
|
||||||
context[@to] = val
|
|
||||||
context.resource_limits.assign_score += assign_score_of(val)
|
|
||||||
''.freeze
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Template.register_tag('local'.freeze, Local)
|
|
||||||
end
|
|
||||||
@@ -21,16 +21,17 @@ class LiquidTagTest < Minitest::Test
|
|||||||
-%}
|
-%}
|
||||||
LIQUID
|
LIQUID
|
||||||
|
|
||||||
assert_template_result('4 8 12', <<~LIQUID, 'array' => [1, 2, 3])
|
assert_template_result('4 8 12 6', <<~LIQUID, 'array' => [1, 2, 3])
|
||||||
{%- liquid
|
{%- liquid
|
||||||
for value in array
|
for value in array
|
||||||
local double_value = value | times: 2
|
assign double_value = value | times: 2
|
||||||
echo double_value | times: 2
|
echo double_value | times: 2
|
||||||
unless forloop.last
|
unless forloop.last
|
||||||
echo " "
|
echo " "
|
||||||
endunless
|
endunless
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
echo " "
|
||||||
echo double_value
|
echo double_value
|
||||||
-%}
|
-%}
|
||||||
LIQUID
|
LIQUID
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class LocalTest < Minitest::Test
|
|
||||||
include Liquid
|
|
||||||
|
|
||||||
def test_local_is_scope_aware
|
|
||||||
assert_template_result('value', <<~LIQUID)
|
|
||||||
{%- if true -%}
|
|
||||||
{%- local variable-name = 'value' -%}
|
|
||||||
{{- variable-name -}}
|
|
||||||
{%- endif -%}
|
|
||||||
{{- variable-name -}}
|
|
||||||
LIQUID
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user