liquid 5.3.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +16 -1
- data/README.md +2 -2
- data/lib/liquid/block_body.rb +4 -4
- data/lib/liquid/context.rb +6 -2
- data/lib/liquid/forloop_drop.rb +44 -1
- data/lib/liquid/locales/en.yml +6 -5
- data/lib/liquid/partial_cache.rb +3 -3
- data/lib/liquid/{static_registers.rb → registers.rb} +13 -10
- data/lib/liquid/standardfilters.rb +406 -57
- data/lib/liquid/strainer_factory.rb +4 -0
- data/lib/liquid/strainer_template.rb +4 -0
- data/lib/liquid/tablerowloop_drop.rb +58 -1
- data/lib/liquid/tags/assign.rb +12 -8
- data/lib/liquid/tags/break.rb +8 -0
- data/lib/liquid/tags/capture.rb +13 -10
- data/lib/liquid/tags/case.rb +21 -0
- data/lib/liquid/tags/comment.rb +13 -0
- data/lib/liquid/tags/continue.rb +8 -9
- data/lib/liquid/tags/cycle.rb +12 -11
- data/lib/liquid/tags/decrement.rb +16 -17
- data/lib/liquid/tags/echo.rb +16 -9
- data/lib/liquid/tags/for.rb +22 -43
- data/lib/liquid/tags/if.rb +11 -9
- data/lib/liquid/tags/include.rb +15 -13
- data/lib/liquid/tags/increment.rb +16 -14
- data/lib/liquid/tags/inline_comment.rb +43 -0
- data/lib/liquid/tags/raw.rb +11 -0
- data/lib/liquid/tags/render.rb +29 -4
- data/lib/liquid/tags/table_row.rb +22 -0
- data/lib/liquid/tags/unless.rb +15 -4
- data/lib/liquid/template.rb +2 -3
- data/lib/liquid/variable.rb +4 -4
- data/lib/liquid/variable_lookup.rb +10 -7
- data/lib/liquid/version.rb +1 -1
- data/lib/liquid.rb +2 -2
- metadata +7 -123
- data/lib/liquid/register.rb +0 -6
- data/test/fixtures/en_locale.yml +0 -9
- data/test/integration/assign_test.rb +0 -117
- data/test/integration/blank_test.rb +0 -109
- data/test/integration/block_test.rb +0 -58
- data/test/integration/capture_test.rb +0 -58
- data/test/integration/context_test.rb +0 -634
- data/test/integration/document_test.rb +0 -21
- data/test/integration/drop_test.rb +0 -257
- data/test/integration/error_handling_test.rb +0 -272
- data/test/integration/expression_test.rb +0 -46
- data/test/integration/filter_kwarg_test.rb +0 -24
- data/test/integration/filter_test.rb +0 -189
- data/test/integration/hash_ordering_test.rb +0 -25
- data/test/integration/output_test.rb +0 -125
- data/test/integration/parsing_quirks_test.rb +0 -134
- data/test/integration/profiler_test.rb +0 -240
- data/test/integration/security_test.rb +0 -89
- data/test/integration/standard_filter_test.rb +0 -925
- data/test/integration/tag/disableable_test.rb +0 -59
- data/test/integration/tag_test.rb +0 -45
- data/test/integration/tags/break_tag_test.rb +0 -17
- data/test/integration/tags/continue_tag_test.rb +0 -17
- data/test/integration/tags/echo_test.rb +0 -13
- data/test/integration/tags/for_tag_test.rb +0 -466
- data/test/integration/tags/if_else_tag_test.rb +0 -190
- data/test/integration/tags/include_tag_test.rb +0 -269
- data/test/integration/tags/increment_tag_test.rb +0 -25
- data/test/integration/tags/liquid_tag_test.rb +0 -116
- data/test/integration/tags/raw_tag_test.rb +0 -34
- data/test/integration/tags/render_tag_test.rb +0 -213
- data/test/integration/tags/standard_tag_test.rb +0 -303
- data/test/integration/tags/statements_test.rb +0 -113
- data/test/integration/tags/table_row_test.rb +0 -66
- data/test/integration/tags/unless_else_tag_test.rb +0 -28
- data/test/integration/template_test.rb +0 -340
- data/test/integration/trim_mode_test.rb +0 -563
- data/test/integration/variable_test.rb +0 -138
- data/test/test_helper.rb +0 -207
- data/test/unit/block_unit_test.rb +0 -53
- data/test/unit/condition_unit_test.rb +0 -181
- data/test/unit/file_system_unit_test.rb +0 -37
- data/test/unit/i18n_unit_test.rb +0 -39
- data/test/unit/lexer_unit_test.rb +0 -53
- data/test/unit/parse_tree_visitor_test.rb +0 -261
- data/test/unit/parser_unit_test.rb +0 -84
- data/test/unit/partial_cache_unit_test.rb +0 -128
- data/test/unit/regexp_unit_test.rb +0 -46
- data/test/unit/static_registers_unit_test.rb +0 -156
- data/test/unit/strainer_factory_unit_test.rb +0 -101
- data/test/unit/strainer_template_unit_test.rb +0 -82
- data/test/unit/tag_unit_test.rb +0 -23
- data/test/unit/tags/case_tag_unit_test.rb +0 -12
- data/test/unit/tags/for_tag_unit_test.rb +0 -15
- data/test/unit/tags/if_tag_unit_test.rb +0 -10
- data/test/unit/template_factory_unit_test.rb +0 -12
- data/test/unit/template_unit_test.rb +0 -87
- data/test/unit/tokenizer_unit_test.rb +0 -62
- data/test/unit/variable_unit_test.rb +0 -164
@@ -1,6 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type object
|
6
|
+
# @liquid_name tablerowloop
|
7
|
+
# @liquid_summary
|
8
|
+
# Information about a parent [`tablerow` loop](/api/liquid/tags#tablerow).
|
4
9
|
class TablerowloopDrop < Drop
|
5
10
|
def initialize(length, cols)
|
6
11
|
@length = length
|
@@ -10,40 +15,92 @@ module Liquid
|
|
10
15
|
@index = 0
|
11
16
|
end
|
12
17
|
|
13
|
-
|
18
|
+
# @liquid_public_docs
|
19
|
+
# @liquid_summary
|
20
|
+
# The total number of iterations in the loop.
|
21
|
+
# @liquid_return [number]
|
22
|
+
attr_reader :length
|
14
23
|
|
24
|
+
# @liquid_public_docs
|
25
|
+
# @liquid_summary
|
26
|
+
# The 1-based index of the current column.
|
27
|
+
# @liquid_return [number]
|
28
|
+
attr_reader :col
|
29
|
+
|
30
|
+
# @liquid_public_docs
|
31
|
+
# @liquid_summary
|
32
|
+
# The 1-based index of current row.
|
33
|
+
# @liquid_return [number]
|
34
|
+
attr_reader :row
|
35
|
+
|
36
|
+
# @liquid_public_docs
|
37
|
+
# @liquid_summary
|
38
|
+
# The 1-based index of the current iteration.
|
39
|
+
# @liquid_return [number]
|
15
40
|
def index
|
16
41
|
@index + 1
|
17
42
|
end
|
18
43
|
|
44
|
+
# @liquid_public_docs
|
45
|
+
# @liquid_summary
|
46
|
+
# The 0-based index of the current iteration.
|
47
|
+
# @liquid_return [number]
|
19
48
|
def index0
|
20
49
|
@index
|
21
50
|
end
|
22
51
|
|
52
|
+
# @liquid_public_docs
|
53
|
+
# @liquid_summary
|
54
|
+
# The 0-based index of the current column.
|
55
|
+
# @liquid_return [number]
|
23
56
|
def col0
|
24
57
|
@col - 1
|
25
58
|
end
|
26
59
|
|
60
|
+
# @liquid_public_docs
|
61
|
+
# @liquid_summary
|
62
|
+
# The 1-based index of the current iteration, in reverse order.
|
63
|
+
# @liquid_return [number]
|
27
64
|
def rindex
|
28
65
|
@length - @index
|
29
66
|
end
|
30
67
|
|
68
|
+
# @liquid_public_docs
|
69
|
+
# @liquid_summary
|
70
|
+
# The 0-based index of the current iteration, in reverse order.
|
71
|
+
# @liquid_return [number]
|
31
72
|
def rindex0
|
32
73
|
@length - @index - 1
|
33
74
|
end
|
34
75
|
|
76
|
+
# @liquid_public_docs
|
77
|
+
# @liquid_summary
|
78
|
+
# Returns `true` if the current iteration is the first. Returns `false` if not.
|
79
|
+
# @liquid_return [boolean]
|
35
80
|
def first
|
36
81
|
@index == 0
|
37
82
|
end
|
38
83
|
|
84
|
+
# @liquid_public_docs
|
85
|
+
# @liquid_summary
|
86
|
+
# Returns `true` if the current iteration is the last. Returns `false` if not.
|
87
|
+
# @liquid_return [boolean]
|
39
88
|
def last
|
40
89
|
@index == @length - 1
|
41
90
|
end
|
42
91
|
|
92
|
+
# @liquid_public_docs
|
93
|
+
# @liquid_summary
|
94
|
+
# Returns `true` if the current column is the first in the row. Returns `false` if not.
|
95
|
+
# @liquid_return [boolean]
|
43
96
|
def col_first
|
44
97
|
@col == 1
|
45
98
|
end
|
46
99
|
|
100
|
+
# @liquid_public_docs
|
101
|
+
# @liquid_summary
|
102
|
+
# Returns `true` if the current column is the last in the row. Returns `false` if not.
|
103
|
+
# @liquid_return [boolean]
|
47
104
|
def col_last
|
48
105
|
@col == @cols
|
49
106
|
end
|
data/lib/liquid/tags/assign.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category variable
|
7
|
+
# @liquid_name assign
|
8
|
+
# @liquid_summary
|
9
|
+
# Creates a new variable.
|
10
|
+
# @liquid_description
|
11
|
+
# You can create variables of any [basic type](/api/liquid/basics#types), [object](/api/liquid/objects), or object property.
|
12
|
+
# @liquid_syntax
|
13
|
+
# {% assign variable_name = value %}
|
14
|
+
# @liquid_syntax_keyword variable_name The name of the variable being created.
|
15
|
+
# @liquid_syntax_keyword value The value you want to assign to the variable.
|
12
16
|
class Assign < Tag
|
13
17
|
Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/om
|
14
18
|
|
data/lib/liquid/tags/break.rb
CHANGED
@@ -10,6 +10,14 @@ module Liquid
|
|
10
10
|
# {% endif %}
|
11
11
|
# {% endfor %}
|
12
12
|
#
|
13
|
+
# @liquid_public_docs
|
14
|
+
# @liquid_type tag
|
15
|
+
# @liquid_category iteration
|
16
|
+
# @liquid_name break
|
17
|
+
# @liquid_summary
|
18
|
+
# Stops a [`for` loop](/api/liquid/tags#for) from iterating.
|
19
|
+
# @liquid_syntax
|
20
|
+
# {% break %}
|
13
21
|
class Break < Tag
|
14
22
|
INTERRUPT = BreakInterrupt.new.freeze
|
15
23
|
|
data/lib/liquid/tags/capture.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category variable
|
7
|
+
# @liquid_name capture
|
8
|
+
# @liquid_summary
|
9
|
+
# Creates a new variable with a string value.
|
10
|
+
# @liquid_description
|
11
|
+
# You can create complex strings with Liquid logic and variables.
|
12
|
+
# @liquid_syntax
|
13
|
+
# {% capture variable %}
|
14
|
+
# value
|
8
15
|
# {% endcapture %}
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# Capture is useful for saving content for use later in your template, such as
|
13
|
-
# in a sidebar or footer.
|
14
|
-
#
|
16
|
+
# @liquid_syntax_keyword variable The name of the variable being created.
|
17
|
+
# @liquid_syntax_keyword value The value you want to assign to the variable.
|
15
18
|
class Capture < Block
|
16
19
|
Syntax = /(#{VariableSignature}+)/o
|
17
20
|
|
data/lib/liquid/tags/case.rb
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category conditional
|
7
|
+
# @liquid_name case
|
8
|
+
# @liquid_summary
|
9
|
+
# Renders a specific expression depending on the value of a specific variable.
|
10
|
+
# @liquid_syntax
|
11
|
+
# {% case variable %}
|
12
|
+
# {% when first_value %}
|
13
|
+
# first_expression
|
14
|
+
# {% when second_value %}
|
15
|
+
# second_expression
|
16
|
+
# {% else %}
|
17
|
+
# third_expression
|
18
|
+
# {% endcase %}
|
19
|
+
# @liquid_syntax_keyword variable The name of the variable you want to base your case statement on.
|
20
|
+
# @liquid_syntax_keyword first_value A specific value to check for.
|
21
|
+
# @liquid_syntax_keyword second_value A specific value to check for.
|
22
|
+
# @liquid_syntax_keyword first_expression An expression to be rendered when the variable's value matches `first_value`.
|
23
|
+
# @liquid_syntax_keyword second_expression An expression to be rendered when the variable's value matches `second_value`.
|
24
|
+
# @liquid_syntax_keyword third_expression An expression to be rendered when the variable's value has no match.
|
4
25
|
class Case < Block
|
5
26
|
Syntax = /(#{QuotedFragment})/o
|
6
27
|
WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
|
data/lib/liquid/tags/comment.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category syntax
|
7
|
+
# @liquid_name comment
|
8
|
+
# @liquid_summary
|
9
|
+
# Prevents an expression from being rendered or output.
|
10
|
+
# @liquid_description
|
11
|
+
# Any text inside `comment` tags won't be output, and any Liquid code won't be rendered.
|
12
|
+
# @liquid_syntax
|
13
|
+
# {% comment %}
|
14
|
+
# content
|
15
|
+
# {% endcomment %}
|
16
|
+
# @liquid_syntax_keyword content The content of the comment.
|
4
17
|
class Comment < Block
|
5
18
|
def render_to_output_buffer(_context, output)
|
6
19
|
output
|
data/lib/liquid/tags/continue.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category iteration
|
7
|
+
# @liquid_name continue
|
8
|
+
# @liquid_summary
|
9
|
+
# Causes a [`for` loop](/api/liquid/tags#for) to skip to the next iteration.
|
10
|
+
# @liquid_syntax
|
11
|
+
# {% continue %}
|
13
12
|
class Continue < Tag
|
14
13
|
INTERRUPT = ContinueInterrupt.new.freeze
|
15
14
|
|
data/lib/liquid/tags/cycle.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# <div class="blue"> Item three </div>
|
13
|
-
# <div class="red"> Item four </div>
|
14
|
-
# <div class="green"> Item five</div>
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category iteration
|
7
|
+
# @liquid_name cycle
|
8
|
+
# @liquid_summary
|
9
|
+
# Loops through a group of strings and outputs them one at a time for each iteration of a [`for` loop](/api/liquid/tags#for).
|
10
|
+
# @liquid_description
|
11
|
+
# The `cycle` tag must be used inside a `for` loop.
|
15
12
|
#
|
13
|
+
# > Tip:
|
14
|
+
# > Use the `cycle` tag to output text in a predictable pattern. For example, to apply odd/even classes to rows in a table.
|
15
|
+
# @liquid_syntax
|
16
|
+
# {% cycle string, string, ... %}
|
16
17
|
class Cycle < Tag
|
17
18
|
SimpleSyntax = /\A#{QuotedFragment}+/o
|
18
19
|
NamedSyntax = /\A(#{QuotedFragment})\s*\:\s*(.*)/om
|
@@ -1,24 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
# Hello: {% decrement variable %}
|
15
|
-
#
|
16
|
-
# gives you:
|
17
|
-
#
|
18
|
-
# Hello: -1
|
19
|
-
# Hello: -2
|
20
|
-
# Hello: -3
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category variable
|
7
|
+
# @liquid_name decrement
|
8
|
+
# @liquid_summary
|
9
|
+
# Creates a new variable, with a default value of -1, that's decreased by 1 with each subsequent call.
|
10
|
+
# @liquid_description
|
11
|
+
# Variables that are declared with `decrement` are unique to the [layout](/themes/architecture/layouts), [template](/themes/architecture/templates),
|
12
|
+
# or [section](/themes/architecture/sections) file that they're created in. However, the variable is shared across
|
13
|
+
# [snippets](/themes/architecture#snippets) included in the file.
|
21
14
|
#
|
15
|
+
# Similarly, variables that are created with `decrement` are independent from those created with [`assign`](/api/liquid/tags#assign)
|
16
|
+
# and [`capture`](/api/liquid/tags#capture). However, `decrement` and [`increment`](/api/liquid/tags#increment) share
|
17
|
+
# variables.
|
18
|
+
# @liquid_syntax
|
19
|
+
# {% decrement variable_name %}
|
20
|
+
# @liquid_syntax_keyword variable_name The name of the variable being decremented.
|
22
21
|
class Decrement < Tag
|
23
22
|
def initialize(tag_name, markup, options)
|
24
23
|
super
|
data/lib/liquid/tags/echo.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category syntax
|
7
|
+
# @liquid_name echo
|
8
|
+
# @liquid_summary
|
9
|
+
# Outputs an expression.
|
10
|
+
# @liquid_description
|
11
|
+
# Using the `echo` tag is the same as wrapping an expression in curly brackets (`{{` and `}}`). However, unlike the curly
|
12
|
+
# bracket method, you can use the `echo` tag inside [`liquid` tags](/api/liquid/tags#liquid).
|
13
13
|
#
|
14
|
+
# > Tip:
|
15
|
+
# > You can use [filters](/api/liquid/filters) on expressions inside `echo` tags.
|
16
|
+
# @liquid_syntax
|
17
|
+
# {% liquid
|
18
|
+
# echo expression
|
19
|
+
# %}
|
20
|
+
# @liquid_syntax_keyword expression The expression to be output.
|
14
21
|
class Echo < Tag
|
15
22
|
attr_reader :variable
|
16
23
|
|
data/lib/liquid/tags/for.rb
CHANGED
@@ -1,50 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# {% for item in collection %}
|
14
|
-
# <div {% if forloop.first %}class="first"{% endif %}>
|
15
|
-
# Item {{ forloop.index }}: {{ item.name }}
|
16
|
-
# </div>
|
17
|
-
# {% else %}
|
18
|
-
# There is nothing in the collection.
|
19
|
-
# {% endfor %}
|
20
|
-
#
|
21
|
-
# You can also define a limit and offset much like SQL. Remember
|
22
|
-
# that offset starts at 0 for the first item.
|
23
|
-
#
|
24
|
-
# {% for item in collection limit:5 offset:10 %}
|
25
|
-
# {{ item.name }}
|
26
|
-
# {% end %}
|
27
|
-
#
|
28
|
-
# To reverse the for loop simply use {% for item in collection reversed %} (note that the flag's spelling is different to the filter `reverse`)
|
29
|
-
#
|
30
|
-
# == Available variables:
|
31
|
-
#
|
32
|
-
# forloop.name:: 'item-collection'
|
33
|
-
# forloop.length:: Length of the loop
|
34
|
-
# forloop.index:: The current item's position in the collection;
|
35
|
-
# forloop.index starts at 1.
|
36
|
-
# This is helpful for non-programmers who start believe
|
37
|
-
# the first item in an array is 1, not 0.
|
38
|
-
# forloop.index0:: The current item's position in the collection
|
39
|
-
# where the first item is 0
|
40
|
-
# forloop.rindex:: Number of items remaining in the loop
|
41
|
-
# (length - index) where 1 is the last item.
|
42
|
-
# forloop.rindex0:: Number of items remaining in the loop
|
43
|
-
# where 0 is the last item.
|
44
|
-
# forloop.first:: Returns true if the item is the first item.
|
45
|
-
# forloop.last:: Returns true if the item is the last item.
|
46
|
-
# forloop.parentloop:: Provides access to the parent loop, if present.
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category iteration
|
7
|
+
# @liquid_name for
|
8
|
+
# @liquid_summary
|
9
|
+
# Renders an expression for every item in an array.
|
10
|
+
# @liquid_description
|
11
|
+
# You can do a maximum of 50 iterations with a `for` loop. If you need to iterate over more than 50 items, then use the
|
12
|
+
# [`paginate` tag](/api/liquid/tags#paginate) to split the items over multiple pages.
|
47
13
|
#
|
14
|
+
# > Tip:
|
15
|
+
# > Every `for` loop has an associated [`forloop` object](/api/liquid/objects#forloop) with information about the loop.
|
16
|
+
# @liquid_syntax
|
17
|
+
# {% for variable in array %}
|
18
|
+
# expression
|
19
|
+
# {% endfor %}
|
20
|
+
# @liquid_syntax_keyword variable The current item in the array.
|
21
|
+
# @liquid_syntax_keyword array The array to iterate over.
|
22
|
+
# @liquid_syntax_keyword expression The expression to render for each iteration.
|
23
|
+
# @liquid_optional_param limit [number] The number of iterations to perform.
|
24
|
+
# @liquid_optional_param offset [number] The 1-based index to start iterating at.
|
25
|
+
# @liquid_optional_param range [untyped] A custom numeric range to iterate over.
|
26
|
+
# @liquid_optional_param reversed [untyped] Iterate in reverse order.
|
48
27
|
class For < Block
|
49
28
|
Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
|
50
29
|
|
data/lib/liquid/tags/if.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category conditional
|
7
|
+
# @liquid_name if
|
8
|
+
# @liquid_summary
|
9
|
+
# Renders an expression if a specific condition is `true`.
|
10
|
+
# @liquid_syntax
|
11
|
+
# {% if condition %}
|
12
|
+
# expression
|
10
13
|
# {% endif %}
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# @liquid_syntax_keyword condition The condition to evaluate.
|
15
|
+
# @liquid_syntax_keyword expression The expression to render if the condition is met.
|
14
16
|
class If < Block
|
15
17
|
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
|
16
18
|
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o
|
data/lib/liquid/tags/include.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category theme
|
7
|
+
# @liquid_name include
|
8
|
+
# @liquid_summary
|
9
|
+
# Renders a [snippet](/themes/architecture#snippets).
|
10
|
+
# @liquid_description
|
11
|
+
# Inside the snippet, you can access and alter variables that are [created](/api/liquid/tags#variable-tags) outside of the
|
12
|
+
# snippet.
|
13
|
+
# @liquid_syntax
|
14
|
+
# {% include 'filename' %}
|
15
|
+
# @liquid_syntax_keyword filename The name of the snippet to render, without the `.liquid` extension.
|
16
|
+
# @liquid_deprecated
|
17
|
+
# Deprecated because the way that variables are handled reduces performance and makes code harder to both read and maintain.
|
17
18
|
#
|
19
|
+
# The `include` tag has been replaced by [`render`](/api/liquid/tags#render).
|
18
20
|
class Include < Tag
|
19
21
|
prepend Tag::Disableable
|
20
22
|
|
@@ -1,21 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# Hello: 0
|
16
|
-
# Hello: 1
|
17
|
-
# Hello: 2
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category variable
|
7
|
+
# @liquid_name increment
|
8
|
+
# @liquid_summary
|
9
|
+
# Creates a new variable, with a default value of 0, that's increased by 1 with each subsequent call.
|
10
|
+
# @liquid_description
|
11
|
+
# Variables that are declared with `increment` are unique to the [layout](/themes/architecture/layouts), [template](/themes/architecture/templates),
|
12
|
+
# or [section](/themes/architecture/sections) file that they're created in. However, the variable is shared across
|
13
|
+
# [snippets](/themes/architecture#snippets) included in the file.
|
18
14
|
#
|
15
|
+
# Similarly, variables that are created with `increment` are independent from those created with [`assign`](/api/liquid/tags#assign)
|
16
|
+
# and [`capture`](/api/liquid/tags#capture). However, `increment` and [`decrement`](/api/liquid/tags#decrement) share
|
17
|
+
# variables.
|
18
|
+
# @liquid_syntax
|
19
|
+
# {% increment variable_name %}
|
20
|
+
# @liquid_syntax_keyword variable_name The name of the variable being incremented.
|
19
21
|
class Increment < Tag
|
20
22
|
def initialize(tag_name, markup, options)
|
21
23
|
super
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category syntax
|
7
|
+
# @liquid_name inline_comment
|
8
|
+
# @liquid_summary
|
9
|
+
# Prevents an expression from being rendered or output.
|
10
|
+
# @liquid_description
|
11
|
+
# Any text inside an `inline_comment` tag won't be rendered or output.
|
12
|
+
#
|
13
|
+
# You can create multi-line inline comments. However, each line must begin with a `#`.
|
14
|
+
# @liquid_syntax
|
15
|
+
# {% # content %}
|
16
|
+
# @liquid_syntax_keyword content The content of the comment.
|
17
|
+
class InlineComment < Tag
|
18
|
+
def initialize(tag_name, markup, options)
|
19
|
+
super
|
20
|
+
|
21
|
+
# Semantically, a comment should only ignore everything after it on the line.
|
22
|
+
# Currently, this implementation doesn't support mixing a comment with another tag
|
23
|
+
# but we need to reserve future support for this and prevent the introduction
|
24
|
+
# of inline comments from being backward incompatible change.
|
25
|
+
#
|
26
|
+
# As such, we're forcing users to put a # symbol on every line otherwise this
|
27
|
+
# tag will throw an error.
|
28
|
+
if markup.match?(/\n\s*[^#\s]/)
|
29
|
+
raise SyntaxError, options[:locale].t("errors.syntax.inline_comment_invalid")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_to_output_buffer(_context, output)
|
34
|
+
output
|
35
|
+
end
|
36
|
+
|
37
|
+
def blank?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Template.register_tag('#', InlineComment)
|
43
|
+
end
|
data/lib/liquid/tags/raw.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Liquid
|
4
|
+
# @liquid_public_docs
|
5
|
+
# @liquid_type tag
|
6
|
+
# @liquid_category syntax
|
7
|
+
# @liquid_name raw
|
8
|
+
# @liquid_summary
|
9
|
+
# Outputs any Liquid code as text instead of rendering it.
|
10
|
+
# @liquid_syntax
|
11
|
+
# {% raw %}
|
12
|
+
# expression
|
13
|
+
# {% endraw %}
|
14
|
+
# @liquid_syntax_keyword expression The expression to be output without being rendered.
|
4
15
|
class Raw < Block
|
5
16
|
Syntax = /\A\s*\z/
|
6
17
|
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|