This commit is contained in:
Andy Waite
2022-03-14 12:41:37 -04:00
parent 7357dcf185
commit 6e2939cbaf
3 changed files with 36 additions and 11 deletions
+13
View File
@@ -1,6 +1,19 @@
# 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.
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
+14 -8
View File
@@ -1,16 +1,22 @@
# frozen_string_literal: true
# @public_docs
module Liquid
# If is the conditional block
# @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
#
# {% if user.admin %}
# Admin user!
# {% else %}
# Not admin user
# {% endif %}
#
# 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
+9 -3
View File
@@ -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 )