mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
wip
This commit is contained in:
@@ -1,6 +1,19 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# @public_docs
|
||||||
module Liquid
|
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
|
class Case < Block
|
||||||
Syntax = /(#{QuotedFragment})/o
|
Syntax = /(#{QuotedFragment})/o
|
||||||
WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
|
WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
|
||||||
|
|||||||
+14
-8
@@ -1,16 +1,22 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# @public_docs
|
||||||
module Liquid
|
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 %}
|
# {% if user.admin %}
|
||||||
# Admin user!
|
# Admin user!
|
||||||
# {% else %}
|
# {% else %}
|
||||||
# Not admin user
|
# Not admin user
|
||||||
# {% endif %}
|
# {% endif %}
|
||||||
#
|
|
||||||
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
|
||||||
#
|
#
|
||||||
|
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
||||||
class If < Block
|
class If < Block
|
||||||
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
|
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
|
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o
|
||||||
|
|||||||
@@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
require_relative 'if'
|
require_relative 'if'
|
||||||
|
|
||||||
|
# @public_docs
|
||||||
module Liquid
|
module Liquid
|
||||||
# Unless is a conditional just like 'if' but works on the inverse logic.
|
# @public_docs
|
||||||
#
|
# @title Unless
|
||||||
# {% unless x < 0 %} x is greater than zero {% endunless %}
|
# @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
|
class Unless < If
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
# First condition is interpreted backwards ( if not )
|
# First condition is interpreted backwards ( if not )
|
||||||
|
|||||||
Reference in New Issue
Block a user