Project

liquid-pry

0.0
No commit activity in last 3 years
No release in over 3 years
Brings Pry to Liquid templates.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.9

Runtime

>= 0
>= 0
 Project Readme

Liquid::Pry

Latest Version Build Status

“Pry is a runtime developer console with powerful introspection capabilities.” — Pry home page

Liquid::Pry brings Pry to Liquid templates and to Jekyll-powered sites.

Installation

Without Jekyll

Add following to the Gemfile:

gem "liquid-pry"

With Jekyll

If you want to integrate Liquid::Pry with Jekyll, it’s probably the easiest to add following to the Gemfile, so that Jekyll will automatically load and enable Liquid::Pry:

group :jekyll_plugins do
  gem "liquid-pry"
end

For other options, read Jekyll documentation.

Usage

This gem provides a Liquid filter and a Liquid tag.

Filter

The pry filter hooks Pry into filter chain in a Liquid template, helping user to debug Jekyll’s front matter or any other data available in given template. For example following could be used to debug page.title:

You are on page {{ page.title | pry }}.

When Liquid renderer encounters pry filter, then Pry console is launched. A convenience local variable named input is defined, which contains filter input (value of page.title in above example), allowing site developer to inspect or alter that value. Another local variable context provides access to rendering context.

The filter returns its input, hence it does not affect rendered page. Also, it can be placed anywhere in the filter chain, not necessarily at the end. For example, in a following example pry filter is placed before upcase, allowing user to inspect page.title value before the upcase filter is applied.

You are on page {{ page.title | pry | upcase }}.

However, if user modify the value of input variable, then modified version is returned. This may be used for experimenting.

The pry filter is typically more useful than the pry tag, especially for novice users.

Tag

The pry tag interrupts Liquid rendering, allowing user to inspect or modify the rendering context. For example:

{% pry %}

When Liquid renderer encounters pry tag, then Pry console is launched and rendering context is available via context local variable.

Using with once option

If pry tag is supplied with once option, then Pry console is launched only for the first time that tag is encountered on given page. In following example:

{% for product in collection.products %}
  {% pry once %}
  {{ product.title }}
{% endfor %}

Pry will be launched only once, no matter if collection.products contains one item or a hundred.

Still, in following example Pry will be launched twice, because pry tag is placed that many times in the template:

{% pry once %}
{% pry once %}

Using Pry console

Credits

This gem is developed, maintained and funded by Ribose Inc.

License

The gem is available as open source under the terms of the MIT License.

See also

This gem is tiny but quite comprehensive. However, there are some other ones you may want to try: