mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c24d3dab32 | ||
|
|
dc3162fcd2 | ||
|
|
fbe086963c | ||
|
|
378a455830 | ||
|
|
2ee44d1341 | ||
|
|
6e2939cbaf |
@@ -1,6 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# @public_docs
|
||||
# @title Case
|
||||
# @syntax The syntax
|
||||
# @summary The summary
|
||||
# @type tag
|
||||
# @description
|
||||
# Creates a switch statement to execute a particular block of code when a variable has a specified value.
|
||||
# `case` initializes the switch statement, and `when` statements define the various conditions.
|
||||
#
|
||||
# An optional `else` statement at the end of the case provides code to execute if none of the conditions are met.
|
||||
class Case < Block
|
||||
Syntax = /(#{QuotedFragment})/o
|
||||
WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# Cycle is usually used within a loop to alternate between values, like colors or DOM classes.
|
||||
#
|
||||
@@ -13,6 +14,16 @@ module Liquid
|
||||
# <div class="red"> Item four </div>
|
||||
# <div class="green"> Item five</div>
|
||||
#
|
||||
# @public_docs
|
||||
# @title Cycle
|
||||
# @syntax The syntax
|
||||
# @summary Loops through a group of strings and prints them in the order that they were passed as arguments.
|
||||
# @type tag
|
||||
# @description
|
||||
# Loops through a group of strings and prints them in the order that they were passed as arguments.
|
||||
# Each time `cycle`` is called, the next string argument is printed.
|
||||
#
|
||||
# `cycle` must be used within a `for`` loop block.
|
||||
class Cycle < Tag
|
||||
SimpleSyntax = /\A#{QuotedFragment}+/o
|
||||
NamedSyntax = /\A(#{QuotedFragment})\s*\:\s*(.*)/om
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# "For" iterates over an array or collection.
|
||||
# Several useful variables are available to you within the loop.
|
||||
@@ -45,6 +46,12 @@ module Liquid
|
||||
# forloop.last:: Returns true if the item is the last item.
|
||||
# forloop.parentloop:: Provides access to the parent loop, if present.
|
||||
#
|
||||
# @public_docs
|
||||
# @title For
|
||||
# @syntax The syntax
|
||||
# @summary Repeatedly executes a block of code.
|
||||
# @type tag
|
||||
# @description The description
|
||||
class For < Block
|
||||
Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
|
||||
|
||||
|
||||
+14
-6
@@ -1,16 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# If is the conditional block
|
||||
#
|
||||
# {% if user.admin %}
|
||||
# Admin user!
|
||||
# {% else %}
|
||||
# Not admin user
|
||||
# {% endif %}
|
||||
# @public_docs
|
||||
# @title If
|
||||
# @syntax The syntax
|
||||
# @summary Executes a block of code only if a certain condition is `true`.
|
||||
# @type tag
|
||||
# @description
|
||||
# If is the conditional block
|
||||
#
|
||||
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
||||
# {% if user.admin %}
|
||||
# Admin user!
|
||||
# {% else %}
|
||||
# Not admin user
|
||||
# {% endif %}
|
||||
#
|
||||
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
||||
class If < Block
|
||||
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
|
||||
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# @public_docs
|
||||
# @title Tablerow
|
||||
# @syntax The syntax
|
||||
# @summary Generates an HTML table.
|
||||
# @type tag
|
||||
# @description
|
||||
# Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.
|
||||
# For a full list of attributes available within a `tablerow` loop, see `tablerow` (object).
|
||||
class TableRow < Block
|
||||
Syntax = /(\w+)\s+in\s+(#{QuotedFragment}+)/o
|
||||
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
|
||||
require_relative 'if'
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# Unless is a conditional just like 'if' but works on the inverse logic.
|
||||
#
|
||||
# {% unless x < 0 %} x is greater than zero {% endunless %}
|
||||
# @public_docs
|
||||
# @title Unless
|
||||
# @syntax The syntax
|
||||
# @summary The opposite of `if`` – executes a block of code only if a certain condition is not met.
|
||||
# @type tag
|
||||
# @description
|
||||
# Unless is a conditional just like 'if' but works on the inverse logic.
|
||||
#
|
||||
# {% unless x < 0 %} x is greater than zero {% endunless %}
|
||||
class Unless < If
|
||||
def render_to_output_buffer(context, output)
|
||||
# First condition is interpreted backwards ( if not )
|
||||
|
||||
Reference in New Issue
Block a user