mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 00:35:40 +03:00
Compare commits
13 Commits
ruby-3-ci
...
fix/echo-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c270a6f378 | ||
|
|
4fba61a802 | ||
|
|
6b6baece25 | ||
|
|
15b2d193ec | ||
|
|
fd712d134a | ||
|
|
0c2db998cf | ||
|
|
9dac68cce1 | ||
|
|
c50509b741 | ||
|
|
cd66572514 | ||
|
|
dcb5a67089 | ||
|
|
efe44a7e6a | ||
|
|
8625e66453 | ||
|
|
3cae09b968 |
5
.github/workflows/liquid.yml
vendored
5
.github/workflows/liquid.yml
vendored
@@ -6,9 +6,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
entry:
|
entry:
|
||||||
- { ruby: 2.5, allowed-failure: false }
|
- { ruby: 2.5, allowed-failure: false } # minimum supported
|
||||||
- { ruby: 2.6, allowed-failure: false }
|
- { ruby: 3.0, allowed-failure: false } # latest
|
||||||
- { ruby: 2.7, allowed-failure: false }
|
|
||||||
- { ruby: ruby-head, allowed-failure: true }
|
- { ruby: ruby-head, allowed-failure: true }
|
||||||
name: test (${{ matrix.entry.ruby }})
|
name: test (${{ matrix.entry.ruby }})
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,7 @@
|
|||||||
|
inherit_gem:
|
||||||
|
rubocop-shopify: rubocop.yml
|
||||||
|
|
||||||
inherit_from:
|
inherit_from:
|
||||||
- 'https://shopify.github.io/ruby-style-guide/rubocop.yml'
|
|
||||||
- .rubocop_todo.yml
|
- .rubocop_todo.yml
|
||||||
|
|
||||||
require: rubocop-performance
|
require: rubocop-performance
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Bugfixes
|
* Bugfixes
|
||||||
* Performance improvements
|
* Performance improvements
|
||||||
* Features that are likely to be useful to the majority of Liquid users
|
* Features that are likely to be useful to the majority of Liquid users
|
||||||
|
* Documentation updates that are concise and likely to be useful to the majority of Liquid users
|
||||||
|
|
||||||
## Things we won't merge
|
## Things we won't merge
|
||||||
|
|
||||||
@@ -14,12 +15,14 @@
|
|||||||
* Features that can easily be implemented on top of Liquid (for example as a custom filter or custom filesystem)
|
* Features that can easily be implemented on top of Liquid (for example as a custom filter or custom filesystem)
|
||||||
* Code that does not include tests
|
* Code that does not include tests
|
||||||
* Code that breaks existing tests
|
* Code that breaks existing tests
|
||||||
|
* Documentation changes that are verbose, incorrect or not important to most people (we want to keep it simple and easy to understand)
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
|
* [Sign the CLA](https://cla.shopify.com/) if you haven't already
|
||||||
* Fork the Liquid repository
|
* Fork the Liquid repository
|
||||||
* Create a new branch in your fork
|
* Create a new branch in your fork
|
||||||
|
* For updating [Liquid documentation](https://shopify.github.io/liquid/), create it from `gh-pages` branch. (You can skip tests.)
|
||||||
* If it makes sense, add tests for your code and/or run a performance benchmark
|
* If it makes sense, add tests for your code and/or run a performance benchmark
|
||||||
* Make sure all tests pass (`bundle exec rake`)
|
* Make sure all tests pass (`bundle exec rake`)
|
||||||
* Create a pull request
|
* Create a pull request
|
||||||
|
|
||||||
|
|||||||
1
Gemfile
1
Gemfile
@@ -19,6 +19,7 @@ end
|
|||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rubocop', '~> 1.4', require: false
|
gem 'rubocop', '~> 1.4', require: false
|
||||||
|
gem 'rubocop-shopify', '~> 1.0.7', require: false
|
||||||
gem 'rubocop-performance', require: false
|
gem 'rubocop-performance', require: false
|
||||||
|
|
||||||
platform :mri, :truffleruby do
|
platform :mri, :truffleruby do
|
||||||
|
|||||||
@@ -89,13 +89,15 @@ module Liquid
|
|||||||
|
|
||||||
def truncatewords(input, words = 15, truncate_string = "...")
|
def truncatewords(input, words = 15, truncate_string = "...")
|
||||||
return if input.nil?
|
return if input.nil?
|
||||||
wordlist = input.to_s.split
|
input = input.to_s
|
||||||
words = Utils.to_integer(words)
|
words = Utils.to_integer(words)
|
||||||
|
words = 1 if words <= 0
|
||||||
|
|
||||||
l = words - 1
|
wordlist = input.split(" ", words + 1)
|
||||||
l = 0 if l < 0
|
return input if wordlist.length <= words
|
||||||
|
|
||||||
wordlist.length > l ? wordlist[0..l].join(" ").concat(truncate_string.to_s) : input
|
wordlist.pop
|
||||||
|
wordlist.join(" ").concat(truncate_string.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Split input string into an array of substrings separated by given pattern.
|
# Split input string into an array of substrings separated by given pattern.
|
||||||
@@ -295,7 +297,7 @@ module Liquid
|
|||||||
|
|
||||||
# Add <br /> tags in front of all newlines in input string
|
# Add <br /> tags in front of all newlines in input string
|
||||||
def newline_to_br(input)
|
def newline_to_br(input)
|
||||||
input.to_s.gsub(/\n/, "<br />\n")
|
input.to_s.gsub(/\r?\n/, "<br />\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reformat a date using Ruby's core Time#strftime( string ) -> string
|
# Reformat a date using Ruby's core Time#strftime( string ) -> string
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ module Liquid
|
|||||||
# {% echo user | link %}
|
# {% echo user | link %}
|
||||||
#
|
#
|
||||||
class Echo < Tag
|
class Echo < Tag
|
||||||
|
attr_reader :variable
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
def initialize(tag_name, markup, parse_context)
|
||||||
super
|
super
|
||||||
@variable = Variable.new(markup, parse_context)
|
@variable = Variable.new(markup, parse_context)
|
||||||
@@ -20,6 +22,12 @@ module Liquid
|
|||||||
def render(context)
|
def render(context)
|
||||||
@variable.render_to_output_buffer(context, +'')
|
@variable.render_to_output_buffer(context, +'')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ParseTreeVisitor < Liquid::ParseTreeVisitor
|
||||||
|
def children
|
||||||
|
[@node.variable]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Template.register_tag('echo', Echo)
|
Template.register_tag('echo', Echo)
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ class ContextTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_interrupt_avoids_object_allocations
|
def test_interrupt_avoids_object_allocations
|
||||||
|
@context.interrupt? # ruby 3.0.0 allocates on the first call
|
||||||
assert_no_object_allocations do
|
assert_no_object_allocations do
|
||||||
@context.interrupt?
|
@context.interrupt?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -171,10 +171,13 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_equal('one two three', @filters.truncatewords('one two three'))
|
assert_equal('one two three', @filters.truncatewords('one two three'))
|
||||||
assert_equal(
|
assert_equal(
|
||||||
'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...',
|
'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...',
|
||||||
@filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15)
|
@filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15)
|
||||||
)
|
)
|
||||||
assert_equal("测试测试测试测试", @filters.truncatewords('测试测试测试测试', 5))
|
assert_equal("测试测试测试测试", @filters.truncatewords('测试测试测试测试', 5))
|
||||||
assert_equal('one two1', @filters.truncatewords("one two three", 2, 1))
|
assert_equal('one two1', @filters.truncatewords("one two three", 2, 1))
|
||||||
|
assert_equal('one two three...', @filters.truncatewords("one two\tthree\nfour", 3))
|
||||||
|
assert_equal('one two...', @filters.truncatewords("one two three four", 2))
|
||||||
|
assert_equal('one...', @filters.truncatewords("one two three four", 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_strip_html
|
def test_strip_html
|
||||||
@@ -539,6 +542,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
|
|
||||||
def test_newlines_to_br
|
def test_newlines_to_br
|
||||||
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc")
|
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc")
|
||||||
|
assert_template_result("a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\r\nb\nc")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_plus
|
def test_plus
|
||||||
|
|||||||
@@ -96,12 +96,12 @@ class IncludeTagTest < Minitest::Test
|
|||||||
|
|
||||||
def test_include_tag_with_alias
|
def test_include_tag_with_alias
|
||||||
assert_template_result("Product: Draft 151cm ",
|
assert_template_result("Product: Draft 151cm ",
|
||||||
"{% include 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% include 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_include_tag_for_alias
|
def test_include_tag_for_alias
|
||||||
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
"{% include 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% include 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_include_tag_with_default_name
|
def test_include_tag_with_default_name
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("Product: Draft 151cm ",
|
assert_template_result("Product: Draft 151cm ",
|
||||||
"{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_with_alias
|
def test_render_tag_with_alias
|
||||||
@@ -161,7 +161,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("Product: Draft 151cm ",
|
assert_template_result("Product: Draft 151cm ",
|
||||||
"{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_for_alias
|
def test_render_tag_for_alias
|
||||||
@@ -171,7 +171,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
"{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_for
|
def test_render_tag_for
|
||||||
@@ -181,7 +181,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_forloop
|
def test_render_tag_forloop
|
||||||
@@ -190,7 +190,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ",
|
assert_template_result("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ",
|
||||||
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_for_drop
|
def test_render_tag_for_drop
|
||||||
@@ -199,7 +199,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("123",
|
assert_template_result("123",
|
||||||
"{% render 'loop' for loop as value %}", "loop" => TestEnumerable.new)
|
"{% render 'loop' for loop as value %}", "loop" => TestEnumerable.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_tag_with_drop
|
def test_render_tag_with_drop
|
||||||
@@ -208,6 +208,6 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert_template_result("TestEnumerable",
|
assert_template_result("TestEnumerable",
|
||||||
"{% render 'loop' with loop as value %}", "loop" => TestEnumerable.new)
|
"{% render 'loop' with loop as value %}", "loop" => TestEnumerable.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ class ParseTreeVisitorTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_echo
|
||||||
|
assert_equal(
|
||||||
|
["test"],
|
||||||
|
visit(%({% echo test %}))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def test_if_condition
|
def test_if_condition
|
||||||
assert_equal(
|
assert_equal(
|
||||||
["test"],
|
["test"],
|
||||||
|
|||||||
Reference in New Issue
Block a user