Commit Graph
325 Commits
Author SHA1 Message Date
Samuel 842986a972 Add where filter to standard filters
Users of Liquid will often wish to filter an array to only those items that match a certain criteria. For example, showing "pinned" messages at the top of a list.

Example usage:

`{{ comments | where: "pinned" | first }}`

or

`{{ products | where: "category", "kitchen" }}`

* Add where filter to standard filters
* Add tests for new where functionality
2018-10-11 16:52:32 -04:00
Justin LiandGitHub cd5a6dd225 Merge pull request #930 from er1/fix-sort-natural-on-nil
Fix sort and sort_natural on sorting with non-string and nil values
2018-10-04 22:32:37 -04:00
Dylan Thacker-SmithandGitHub 4369fe6c85 Improve the unexpected end delimiter message for block tags. (#1003) 2018-04-05 11:18:13 -04:00
Dylan Thacker-SmithandGitHub 5106466a2d Add a regression test for a liquid-c trim mode bug (#972) 2018-01-25 10:55:01 -05:00
Thibaut Courouble 147d7ae24d Rename min/max filters for clarity 2017-12-06 09:48:30 -05:00
Thibaut Courouble 282d42f98d Fix min/max filters 2017-12-06 08:58:05 -05:00
Justin Li e6ba6ee87b Revert "Use replacement string for replace filters literally (#924)"
This reverts commit 27c91203ab.
2017-12-04 15:07:59 -05:00
Nithin Bekal 4bdaaf069f Add max/min filters 2017-11-30 13:56:37 -05:00
Justin Li a7c5e247c8 Bump rubocop 2017-11-22 11:59:06 -05:00
Eric Chan deb10ebc7a Sorting support for data with undefined values 2017-09-14 02:00:43 -04:00
Eric Chan cfe1844de9 Added test coverage for sort_natural 2017-09-13 22:17:59 -04:00
Dylan Thacker-SmithandGitHub 27c91203ab Use replacement string for replace filters literally (#924) 2017-08-28 11:51:20 -04:00
Justin LiandGitHub 44eaa4b9d8 Merge pull request #920 from Shopify/symbol_to_liquid
Support rendering symbols as strings
2017-08-18 12:10:53 -04:00
Pascal BetzandJustin Li a979b3ec95 Do not raise when variable is defined but nil when using strict_variables 2017-08-18 12:09:57 -04:00
Justin Li bf3e759da3 Support rendering symbols as strings 2017-08-17 23:10:57 -04:00
Thierry Joyal e340803d12 CGI powered standard filters to handle non string inputs 2017-05-25 15:53:41 +00:00
Dylan Thacker-SmithandGitHub 3bb29d5456 Replace assert_equal nil, with a assert_nil (#895) 2017-05-11 14:05:03 -04:00
Dylan Thacker-SmithandGitHub 9c72ccb82f Limit how much blocks can be nested during parsing (#894) 2017-05-11 09:37:53 -04:00
Mike AngellandGitHub c9bac9befe Merge branch 'master' into contains-strict-fix 2017-03-24 11:09:09 +10:00
Lasse Skindstad EbertandDylan Thacker-Smith 5149cde5c3 Fix include tag used with strict_variables (#829)
Fixes https://github.com/Shopify/liquid/issues/828
2017-03-22 16:00:31 -04:00
Richard Monette d17f86ba4d handle join on fixnum 2017-02-01 12:47:35 -05:00
Dylan Thacker-SmithandGitHub 869dbc7ebf feature: Allow a default exception renderer to be specified (#837)
This could be used to preserve the old default of rendering
non-Liquid::Error messages or for providing default behaviour like error
reporting which could be missed if the exception renderer needed to be
specified on each render.
2016-12-12 10:29:09 -05:00
Dylan Thacker-SmithandGitHub f27bd619b9 change: Render an opaque internal error by default for non-Liquid::Error (#835)
These errors may contain sensitive information, so is safer to
render a more vague message by default.

This is done by replacing non-Liquid::Error exceptions with a
Liquid::InternalError exception with the non-Liquid::Error accessible on
through the cause method. This also allows the template name and line
number to be attached to the template errors.

The exception_handler render option has been changed to exception_renderer
since now it should raise an exception to re-raise on a liquid rendering
error or return a string to be rendered where the error occurred.
2016-12-07 17:34:29 -05:00
Richard MonetteandGitHub b2feeacbce Merge pull request #812 from Shopify/allow-split-to-accept-numeric
allow split to accept numeric
2016-10-26 10:59:44 -04:00
Richard Monette 143ba39a08 allow split to accept numeric 2016-10-26 10:43:04 -04:00
Richard Monette bb3624b799 dont explode when sorting nil property 2016-10-04 13:22:29 -04:00
Konstantin TennhardandGitHub 64fca66ef5 Merge pull request #797 from Shopify/truncatewords-resiliency
Standard filter truncate / truncatewords: force truncate_string to string
2016-09-13 10:43:55 -04:00
Konstantin Tennhard 95d5c24bfc Standard filter truncate: truncate_string string coercion
The argument `truncate_string` is now coerced into a string to avoid
`NoMethodError`s. This is mostly for added resiliency. It is doubtful
that someone would actually intent to use a number as truncate string,
but accidentally supplying one is entirely possible.
2016-09-12 12:13:12 -04:00
Philibert Dugas b7ee1a2176 Fixing #697 with better exception
When including a template which is not defined, the exception raised is
*undefined method `split` for nil:NilClass*

This occurs for a scenario like the following:
`{% include nil %}`
or
`{% include undefined-var %}`

Making the code raise an argument error to allow better understanding of
the include error
2016-09-12 09:31:59 -04:00
Konstantin Tennhard 302185a7fc Standard filter truncatewords: force truncate_string to string
Currently, `truncatewords` raises a TypeError when the argument
`truncate_string` is an interger. This PR forces string coercion for any
value provided for this argument. Thus,

```ruby
assert_equal 'one two1', @filters.truncatewords("one two three", 2, 1)
```

holds true. Another option would be to raise a `Liquid::ArgumentError`.

What is preferred?
2016-09-09 16:50:50 -04:00
Michael Angell 6ed6e7e12f Allow :id to start with the word contains 2016-08-20 20:32:46 +10:00
Michael Angell e1d40c7d89 Add whitespace control character and associated tests 2016-06-28 09:15:45 +10:00
Gaurav Chande 00f53b16e8 Prevent Range usage in templates from blowing up 2016-06-02 16:38:44 -04:00
Florian Weingarten f93243cc1a abs filter 2016-04-04 09:32:31 -04:00
Florian Weingarten 1e533a52e7 Merge pull request #735 from Shopify/fix-to-number-for-negative-float-strings
Fix to_number filter for negative float strings
2016-03-31 15:52:51 -04:00
Dylan Thacker-Smith 4239c899a4 Raise a Liquid::Error when a non-array is passed into the concat filter. 2016-03-31 15:47:06 -04:00
Florian Weingarten 1597f8859f Fix to_number filter for negative float strings 2016-03-31 09:18:55 -04:00
Florian Weingarten d2f16d92d6 Fix a bunch of Ruby warnings 2016-03-30 20:42:30 +00:00
Ismael Celis 929c89789f Test that all maths filters work with duck-typed #to_number 2016-03-30 13:35:09 -03:00
Ismael Celis d03c4ae8e8 Allow Utils.to_number to work with anything that responds to #to_number 2016-03-30 01:57:21 -03:00
Justin Li a6fa4c5c38 Merge pull request #691 from urbandictionary/missing_variables_and_filters
Merge pull request 691
2016-02-02 23:13:44 -05:00
Ivan Kuznetsov dadd9b4dd2 Add strict_variables/strict_filters render options to check for undefined variables and filters 2016-02-03 10:49:33 +07:00
Justin Li 198f0aa366 Add test for nested assign score bookkeeping 2016-02-01 13:01:23 -05:00
Guillaume Malette a32ad449c0 Merge pull request #672 from Shopify/fix-proc-mapping
Test mapping over procs
2016-01-06 15:59:53 -05:00
Jonathan Cheatham b892a73463 Ensure truncate is operating on a string 2015-12-22 19:40:35 -08:00
Guillaume Malette 0b55d09cea Fix mapping over proc attributes 2015-11-20 13:04:42 -05:00
Tanel Jakobsoo 8d5a907dc8 Fixed issue where "nil" value for "escape" filter breaks rendering
Closes #664
2015-11-06 16:32:02 +02:00
Thierry Joyal ac041c4ad1 Rename before_method as liquid_method_missing 2015-10-28 17:28:19 +00:00
Larry ArcherandJustin Li e6392d1cc1 Tests for new url_decode filter 2015-10-21 01:58:22 -04:00
Marcel M. Cary 4100f8d641 Fix "sort" filter on empty array to return empty array
When sorting an empty array with the "sort" filter, it returns nil
instead of [].  This confuses subsequent filters in the chain that
expect an array.  For example, when followed by the "map" filter, it
produces an array containing one nil element: [nil].

I could special-case the nil return value, but that would be more
cumbersome than making sure "sort" always returns an array.

Add a case to the "sort" method to return [] if the array is empty,
before performing any checks on ary.first that assume a non-empty array.

There is still a danger of returning nil if the first item in the array
is nil and it is non-empty, but I'm not sure how better to handle that
case.

Apply a similar fix to sort_natural, uniq, and compact filters.
2015-09-29 10:24:31 -07:00