mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-01 16:15:14 -07:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8af0b06b9 | ||
|
|
faf208ad65 |
@@ -35,6 +35,18 @@ module Liquid
|
||||
super
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type tag
|
||||
# @category theme
|
||||
# @title liquid
|
||||
# @summary
|
||||
# Allows you to write multiple tags within one set of delimiters.
|
||||
# @description
|
||||
# Use the [`echo`](/api/liquid/tags/theme-tags#echo) tag to output an expression within a `liquid` tag.
|
||||
# @syntax
|
||||
# {% liquid
|
||||
# statement
|
||||
# %}
|
||||
private def parse_for_liquid_tag(tokenizer, parse_context)
|
||||
while (token = tokenizer.shift)
|
||||
unless token.empty? || token =~ WhitespaceOrNothing
|
||||
|
||||
@@ -95,32 +95,7 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Truncates a string down to a specified number of characters.
|
||||
# @description
|
||||
# Truncates a string down to a specified number of characters. By default, an ellipsis (`...`)
|
||||
# is appended to the truncated string.
|
||||
#
|
||||
# > Tip:
|
||||
# > The number of characters in both default and custom ellipses is included in the
|
||||
# > character count for the truncated string. For example, if you want to truncate a string
|
||||
# > down to ten characters and use the default ellipsis (`...`), then you should set the
|
||||
# > character count parameter to `13`.
|
||||
#
|
||||
# ### Custom ellipsis
|
||||
#
|
||||
# The `truncate` filter accepts an optional parameter to specify a custom ellipsis to be
|
||||
# appended to the truncated string.
|
||||
#
|
||||
# ### No ellipsis
|
||||
#
|
||||
# If you don't want an ellipsis appended to your truncated string, then you can set the
|
||||
# ellipsis parameter to a blank string (`''`).
|
||||
# @syntax {{ string | truncate: character_count, ellipsis }}
|
||||
# @return string
|
||||
# Truncate a string down to x characters
|
||||
def truncate(input, length = 50, truncate_string = "...")
|
||||
return if input.nil?
|
||||
input_str = input.to_s
|
||||
@@ -134,26 +109,6 @@ module Liquid
|
||||
input_str.length > length ? input_str[0...l].concat(truncate_string_str) : input_str
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Truncates a string down to a specified number of words.
|
||||
# @description
|
||||
# Truncates a string down to a specified number of words. By default, an ellipsis (`...`)
|
||||
# is appended to the truncated string.
|
||||
#
|
||||
# ### Custom ellipsis
|
||||
#
|
||||
# The `truncate` filter accepts an optional parameter to specify a custom ellipsis to be
|
||||
# appended to the truncated string.
|
||||
#
|
||||
# ### No ellipsis
|
||||
#
|
||||
# If you don't want an ellipsis appended to your truncated string, then you can set the
|
||||
# ellipsis parameter to a blank string (`''`).
|
||||
# @syntax {{ string | truncatewords: word_count, ellipsis }}
|
||||
# @return string
|
||||
def truncatewords(input, words = 15, truncate_string = "...")
|
||||
return if input.nil?
|
||||
input = input.to_s
|
||||
@@ -182,54 +137,18 @@ module Liquid
|
||||
input.to_s.split(pattern.to_s)
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the left and right sides of a string.
|
||||
# @description
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the left and right sides of a string.
|
||||
# @syntax {{ string | strip }}
|
||||
# @return string
|
||||
def strip(input)
|
||||
input.to_s.strip
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the left side of a string.
|
||||
# @description
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the left side of a string.
|
||||
# @syntax {{ string | lstrip }}
|
||||
# @return string
|
||||
def lstrip(input)
|
||||
input.to_s.lstrip
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the right side of a string.
|
||||
# @description
|
||||
# Strips all whitespace, such as tabs, spaces, and newlines, from the right side of a string.
|
||||
# @syntax {{ string | rstrip }}
|
||||
# @return string
|
||||
def rstrip(input)
|
||||
input.to_s.rstrip
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Strips all HTML tags from a string.
|
||||
# @description
|
||||
# Strips all HTML tags from a string.
|
||||
# @syntax {{ string | strip_html }}
|
||||
# @return string
|
||||
def strip_html(input)
|
||||
empty = ''
|
||||
result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty)
|
||||
@@ -237,15 +156,7 @@ module Liquid
|
||||
result
|
||||
end
|
||||
|
||||
# @public_docs
|
||||
# @type filter
|
||||
# @category string
|
||||
# @summary
|
||||
# Strips all line breaks and newlines from a string.
|
||||
# @description
|
||||
# Strips all line breaks and newlines from a string.
|
||||
# @syntax {{ string | strip_newlines }}
|
||||
# @return string
|
||||
# Remove all newlines from the string
|
||||
def strip_newlines(input)
|
||||
input.to_s.gsub(/\r?\n/, '')
|
||||
end
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
# @public_docs
|
||||
# @type tag
|
||||
# @category theme
|
||||
# @title comment
|
||||
# @summary
|
||||
# Allows you to comment out parts of a Liquid file.
|
||||
# Any text within the opening and closing `comment` blocks won't be output,
|
||||
# and any Liquid code won't be executed.
|
||||
# @syntax
|
||||
# {% comment %}
|
||||
# statement
|
||||
# {% endcomment %}
|
||||
class Comment < Block
|
||||
def render_to_output_buffer(_context, output)
|
||||
output
|
||||
|
||||
+10
-10
@@ -1,16 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
# Echo outputs an expression
|
||||
#
|
||||
# {% echo monkey %}
|
||||
# {% echo user.name %}
|
||||
#
|
||||
# This is identical to variable output syntax, like {{ foo }}, but works
|
||||
# inside {% liquid %} tags. The full syntax is supported, including filters:
|
||||
#
|
||||
# {% echo user | link %}
|
||||
#
|
||||
# @public_docs
|
||||
# @type tag
|
||||
# @category theme
|
||||
# @title echo
|
||||
# @summary
|
||||
# Outputs an expression, or Liquid object, in the rendered HTML.
|
||||
# Works the same as wrapping an expression in double curly brace delimiters `{{ }}`.
|
||||
# Works inside the [`liquid`](/api/liquid/tags/theme-tags#liquid) tag and supports [filters](/api/liquid/filters).
|
||||
# @syntax
|
||||
# {% echo 'string' %}
|
||||
class Echo < Tag
|
||||
attr_reader :variable
|
||||
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
# @public_docs
|
||||
# @type tag
|
||||
# @category theme
|
||||
# @title raw
|
||||
# @summary
|
||||
# Allows you to output Liquid code on a page without it being parsed.
|
||||
# @syntax
|
||||
# {% raw %}
|
||||
# liquid
|
||||
# {% endraw %}
|
||||
class Raw < Block
|
||||
Syntax = /\A\s*\z/
|
||||
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
# @public_docs
|
||||
# @type tag
|
||||
# @category theme
|
||||
# @title render
|
||||
# @summary
|
||||
# Renders a snippet from the **snippets** folder of a theme, or [code for an app block](/themes/architecture/sections/section-schema#render-app-blocks).
|
||||
# You don't need to write the file's `.liquid` extension.
|
||||
# @description
|
||||
# When a snippet is rendered, the code inside it doesn't automatically have access to the variables assigned
|
||||
# using [variable tags](/api/liquid/tags/variable-tags) within the snippet's parent template.
|
||||
# Similarly, variables assigned within the snippet can't be accessed by the code outside of the snippet.
|
||||
# This encapsulation increases performance and helps make theme code easier to understand and maintain.
|
||||
#
|
||||
# You can't use an [`include`](/api/liquid/tags/theme-tags#include) tag inside of a snippet rendered using the `render` tag.
|
||||
#
|
||||
# > Tip:
|
||||
# > This tag replaces the deprecated [`include`](/api/liquid/tags/theme-tags#include) tag.
|
||||
# @syntax
|
||||
# {% render reference %}
|
||||
# @optional_param with [string] Pass an object to use in the snippet. Use with the `as` parameter.
|
||||
# @optional_param for [string] Render the snippet once for each value of an enumerable object. Use with the `as` parameter. When using the `for` parameter, the [`forloop`](/api/liquid/objects/for-loops) object is accessible within the snippet.
|
||||
# @optional_param as [string] The variable that the object referenced by a `with` or `for` parameter represents within the snippet.
|
||||
class Render < Tag
|
||||
FOR = 'for'
|
||||
SYNTAX = /(#{QuotedString}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||
|
||||
Reference in New Issue
Block a user