Commit Graph
94 Commits
Author SHA1 Message Date
Alessandro Diogo BrückheimerandMike Angell e83b1e4159 Add ForceEqualSignAlignment to .rubocop.yml (#1190)
* Add ForceEqualSignAlignment to .rubocop.yml

* Revert ForceEqualSignAlignment cop

* Update method alignment

* Undo addition of whitespace to improve readability

* Fix missing alignment
2019-10-21 21:18:48 +10:00
Mike AngellandGitHub d8403af515 Reimplementation of Static Registers (#1157) 2019-09-18 13:25:55 +10:00
0d26f05bb8 Enabled frozen string literals (#1154)
* Enabled frozen string literals

* Update rubocop config

* Prefer string interpolation in simple cases

Co-Authored-By: Dylan Thacker-Smith <[email protected]>
2019-09-18 13:19:45 +10:00
Mike AngellandGitHub 1fcef2133f Merge pull request #1143 from Shopify/styling-fixes-1
Apply simple rubocop fixes
2019-09-16 12:14:32 +10:00
Mike AngellandGitHub d7514b1305 Merge pull request #1137 from Shopify/remove-lazy-stacks
Remove lazy load stacks
2019-09-16 12:14:14 +10:00
Mike Angell 799da202df Apply simple rubocop fixes 2019-08-31 21:58:33 +10:00
Mike Angell dafbb4ae90 Remove hasnling false scopes 2019-08-31 20:03:54 +10:00
Ashwin Maroli 8750b4b006 Reduce allocations from Liquid::Context.new 2019-08-30 09:01:47 +05:30
Samuel 9672ed5285 Add a new {% render %} tag
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.
2019-08-29 16:32:05 -04:00
Samuel d338ccb9a6 Add isolated subcontexts
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.
2019-08-29 10:27:15 -04:00
Mike Angell 2324564743 Remove lazy load stacks
Remove lazy load stacks and instead only create a new scope when a tag is known to need one
2019-08-29 09:09:32 +10: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
Dylan Thacker-SmithandGitHub 9c72ccb82f Limit how much blocks can be nested during parsing (#894) 2017-05-11 09:37:53 -04: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
Dylan Thacker-Smith 5dcefd7d77 Avoid calling line_number on String node when rescuing a render error. 2017-02-07 15:34:10 -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 Monette a549d289d7 introduce unhandled liquid exception
check arity
2016-10-28 09:40:44 -04:00
Florian Weingarten d2f16d92d6 Fix a bunch of Ruby warnings 2016-03-30 20:42:30 +00:00
Justin Li 0cc8b68a97 Make logic in Context#lookup_and_evaluate more understandable 2016-02-02 23:22:46 -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
Loren Hale 0b11b573d9 add global_filter
add a global filter using a proc
only add one proc and not an array
add tests to make sure the global_filter is applied after native filters
2015-07-12 16:46:43 +08:00
Dylan Thacker-Smith cebf75b8d7 Implement line numbers without the Liquid::Token class. 2015-07-08 19:21:59 -04:00
Dylan Thacker-Smith 80b6ac3bc7 Add taint warnings to the context rather than the template. 2015-07-07 15:53:02 -04:00
Dylan Thacker-Smith ad3748af21 Include template name with line numbers in render errors. 2015-06-04 13:44:01 -04:00
Florian Weingarten 5919626da4 Rename 'has_key?' and 'has_interrupt?' 2015-06-04 13:14:46 -04:00
Dylan Thacker-Smith 8d5e71f856 Allow the exception handler to convert exceptions to hide error messages. 2015-05-27 18:59:51 -04:00
Dylan Thacker-Smith 36200ff704 Make liquid error rendering optional.
Although the author of the liquid template wants to see these errors, they
probably don't want the visitor to see the liquid errors.  Probably the
best fallback when rendering the page for visitors is to render the empty
string for tags with errors.
2015-05-25 11:24:53 -04:00
Florian Weingarten 3372ca8136 Rubocop 2015-05-14 14:37:18 +00:00
Dylan Thacker-Smith 950f062041 Allow filters to redefine Object methods to make them invokable. 2015-02-03 13:51:33 -05:00
Justin Li 1593b784a7 Simplify interface for setting template resource limits 2014-12-04 16:18:21 -05:00
Justin Li db00ec8b32 Move resource limit tracking to its own class 2014-12-04 16:18:09 -05:00
Dylan Thacker-Smith f5faa4858c Remove parsed expression cache. 2014-10-18 15:03:40 -04:00
Dylan Thacker-Smith cf5ccede50 Avoid modifying the default resources limits hash. 2014-10-01 18:51:06 -05:00
Dylan Thacker-Smith eae29f8c48 Make it easy to set default resource limits. 2014-09-11 13:54:30 -04:00
Florian Weingarten aabbd8f1a1 remove unnecessary method 2014-09-05 14:12:30 +00:00
Florian Weingarten 17cc8fdbb3 put line number in parentheses 2014-09-05 14:12:30 +00:00
Florian Weingarten 5eff375094 Optional line numbers for liquid errors 2014-09-05 14:12:29 +00:00
Florian Weingarten 1678c07548 Call to_liquid in Context invoke 2014-08-12 19:54:12 +00:00
Dylan Thacker-Smith 2aa9bbbac2 Separate expression parsing and rendering from Context#resolve. 2014-08-11 14:15:58 -07:00
Tom Burns 794ca9f604 make the conditions around stack creation easier to read 2014-07-30 15:42:24 +00:00
Tom Burns 15f6cabf83 avoid a hash comparison 2014-07-30 15:12:22 +00:00
Tom Burns e53d102a2c use 'unless' instead of 'if !' for simple conditional 2014-07-30 14:59:56 +00:00
Tom Burns 6b56bdd74f remove variables used for counting empty stacks 2014-07-28 14:23:16 +00:00
Tom Burns ba6e3e3da6 lazily create stacks 2014-07-28 14:12:11 +00:00
Jason Hiltz-Laforge 052ef9fcb8 Reorder constructor to avoid referencing uninitialized variable when environment contains a self-referencing proc 2014-07-24 18:58:23 +00:00
Florian Weingarten 6c6350f18b Exception handling for humans
Ability to pass exception_handler as a block to #render
and provide whatever behavior you want on handling exceptions

https://github.com/Shopify/liquid/pull/254
2014-07-24 14:44:02 +00:00
Jason Hiltz-Laforge bc3b066ba8 Remove block in favour of for loop to reduce temporary object allocation during variable context resolution 2014-07-22 14:54:50 +00:00
Jason Hiltz-Laforge 0df3f1c372 Cache parsed markup parts to avoid repeated calls during template render 2014-07-21 15:55:06 +00:00
Jason Hiltz-Laforge fd8c30070a Adding tests, spy dependency 2014-07-16 15:05:45 +00:00