mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-02 00:25:12 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
965ea3cfb1 |
@@ -22,7 +22,14 @@ module Liquid
|
||||
)
|
||||
STRIP_HTML_TAGS = /<.*?>/m
|
||||
|
||||
# Return the size of an array or of an string
|
||||
# @public_docs
|
||||
# @title Size
|
||||
# @syntax The syntax
|
||||
# @summary The summary
|
||||
# @type filter
|
||||
# @category My category
|
||||
# @description
|
||||
# Return the size of an array or of an string
|
||||
def size(input)
|
||||
input.respond_to?(:size) ? input.size : 0
|
||||
end
|
||||
@@ -298,12 +305,7 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @syntax {{ string | replace: string, substring }}
|
||||
# @summary Replaces all occurrences of a string with a substring.
|
||||
# @type filter
|
||||
# @category string
|
||||
# @return string
|
||||
# Replace occurrences of a string with another
|
||||
def replace(input, string, replacement = '')
|
||||
input.to_s.gsub(string.to_s, replacement.to_s)
|
||||
end
|
||||
@@ -328,22 +330,12 @@ module Liquid
|
||||
output
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @syntax {{ string | remove: string }}
|
||||
# @summary Removes a substring.
|
||||
# @type filter
|
||||
# @category string
|
||||
# @return string
|
||||
# remove a substring
|
||||
def remove(input, string)
|
||||
replace(input, string, '')
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @syntax {{ string | remove_first: string }}
|
||||
# @summary Removes the first occurrences of a substring.
|
||||
# @type filter
|
||||
# @category string
|
||||
# @return string
|
||||
# remove the first occurrences of a substring
|
||||
def remove_first(input, string)
|
||||
replace_first(input, string, '')
|
||||
end
|
||||
@@ -365,12 +357,7 @@ module Liquid
|
||||
InputIterator.new(input, context).concat(array)
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @syntax {{ string | prepend: string }}
|
||||
# @summary Prepend a string to another string.
|
||||
# @type filter
|
||||
# @category string
|
||||
# @return string
|
||||
# prepend a string to another
|
||||
def prepend(input, string)
|
||||
string.to_s + input.to_s
|
||||
end
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @public_docs
|
||||
module Liquid
|
||||
# Assign sets a variable in your template.
|
||||
# @public_docs
|
||||
# @title Assign
|
||||
# @syntax The syntax
|
||||
# @summary The summary
|
||||
# @type tag
|
||||
# @description
|
||||
# Assign sets a variable in your template.
|
||||
#
|
||||
# {% assign foo = 'monkey' %}
|
||||
# {% assign foo = 'monkey' %}
|
||||
#
|
||||
# You can then use the variable later in the page.
|
||||
#
|
||||
# {{ foo }}
|
||||
# You can then use the variable later in the page.
|
||||
#
|
||||
# {{ foo }}
|
||||
class Assign < Tag
|
||||
Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/om
|
||||
|
||||
|
||||
Reference in New Issue
Block a user