Example:
```
// the_count.liquid
{{ number }}! Ah ah ah.
// my_template.liquid
{% for number in range (1..3) %}
{% render "the_count", number: number %}
{% endfor %}
Output:
1! Ah ah ah.
2! Ah ah ah.
3! Ah ah ah.
```
The `render` tag is a more strict version of the `include` tag. It is
designed to isolate itself from the parent rendering context both by
creating a new scope (which does not inherit the parent scope) and by
only inheriting "static" registers.
Static registers are those that do not hold mutable state which could
affect rendering. This again helps `render`ed templates remain entirely
separate from their calling context.
Unlike `include`, `render` does not permit specifying the target
template using a variable, only a string literal. For example, this
means that `{% render my_dynamic_template %}` is invalid syntax. This
will make it possible to statically analyze the dependencies between
templates without making Turing angry.
Note that the `static_environment` of a rendered template is inherited, unlike
the scope and regular environment. This environment is immutable from within the
template.
An alternate syntax, which mimics the `{% include ... for %}` tag is
currently in design discussion.
An isolated subcontext inherits the environment, filters,
and static registers of its supercontext, but with a fresh
(isolated) scope.
This will pave the way for adding the `render` tag, which renders
templates in such a subcontext.
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
## Summary
`BigDecimal.new` is deprecated since BigDecimal 1.3.3 for Ruby 2.5.
This PR suppresses the following warnings.
```console
% ruby -v
ruby 2.6.0dev (2018-09-06 trunk 64648) [x86_64-darwin17]
% RUBYOPT=-w bundle exec rake
(snip)
/Users/koic/src/github.com/Shopify/liquid/lib/liquid/utils.rb:49:
warning: BigDecimal.new is deprecated; use Kernel.BigDecimal method
instead.
/Users/koic/src/github.com/Shopify/liquid/lib/liquid/utils.rb:53:
warning: BigDecimal.new is deprecated; use Kernel.BigDecimal method
instead.
```
## Other Information
The following is a change of BigDecimal 1.3.3 for Ruby 2.5 related to this PR.
- 533737338d
- 16738ad0ac
Measures:
1) A while loop is faster than iterating with #each.
2) Check string, variable and block tokens first. They are far more
frequent than interrupt tokens. In their case, checking for an
interrupt can be avoided.
3) String tokens just map to themselves and don't need the special
treatment of BlockBody#render_node (except the resource limit
check).
Benchmark
=========
$ bundle exec rake benchmark:run
Before
------
Run 1)
parse: 41.630 (± 0.0%) i/s - 420.000 in 10.089309s
render: 75.962 (± 3.9%) i/s - 763.000 in 10.066823s
parse & render: 25.497 (± 0.0%) i/s - 256.000 in 10.040862s
Run 2)
parse: 42.130 (± 0.0%) i/s - 424.000 in 10.064738s
render: 77.003 (± 1.3%) i/s - 777.000 in 10.093524s
parse & render: 25.739 (± 0.0%) i/s - 258.000 in 10.024581s
Run 3)
parse: 41.976 (± 2.4%) i/s - 420.000 in 10.021406s
render: 76.184 (± 1.3%) i/s - 763.000 in 10.018104s
parse & render: 25.641 (± 0.0%) i/s - 258.000 in 10.062549s
After
-----
Run 1)
parse: 42.283 (± 0.0%) i/s - 424.000 in 10.028306s
render: 83.158 (± 2.4%) i/s - 832.000 in 10.009201s
parse & render: 26.417 (± 0.0%) i/s - 266.000 in 10.069718s
Run 2)
parse: 41.159 (± 4.9%) i/s - 412.000 in 10.031297s
render: 81.591 (± 3.7%) i/s - 816.000 in 10.018225s
parse & render: 25.924 (± 3.9%) i/s - 260.000 in 10.035653s
Run 3)
parse: 42.418 (± 2.4%) i/s - 424.000 in 10.003100s
render: 84.183 (± 2.4%) i/s - 847.000 in 10.069781s
parse & render: 26.726 (± 0.0%) i/s - 268.000 in 10.029857s