mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
wip
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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