No release in over a year
A simple Jekyll plugin that adds JavaScript-like istruthy and isfalsy filters to Liquid
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
>= 0

Runtime

>= 3.0, < 5.0
 Project Readme




Site | Gem Page | GitHub Repo

Meet jekyll-truthyfalsy, the Sherlock Holmes of truthy and falsy values in Liquid.

Features

  • Check whether a value is truthy or falsy in a manner similar to JavaScript
  • Exposes a istruthy function
  • Exposes a isfalsy function

Jekyll::truthyfalsy

Meet jekyll-truthyfalsy, the whimsical gem dedicated to turning the grey areas of truthiness and falsiness into black and white.

It doesn't just settle for mere booleans; oh no, it goes above and beyond, scrutinizing empty strings and null values too! Like a tenacious detective, it leaves no stone unturned, and no value unverified. Banish the verbose 'if' statements and welcome a new era of compact, expressive checks.

Because life is too short for ambiguity, embrace the certainty that comes with jekyll-truthyfalsy. Truthiness and falsiness: not just a philosophical quandary, but a .gem installation away!

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add jekyll-truthyfalsy

If bundler is not being used to manage dependencies, install the gem by executing:

gem install jekyll-truthyfalsy

Usage

Now you can use the istruthy and isfalsy filters in your Jekyll site's templates:

{%- assign test_true = true | istruthy -%}
{%- if test_true -%}
  This will print because `true` is truthy
{%- endif -%}

{%- assign test_false = false | istruthy -%}
{%- if test_false -%}
  This will NOT print because `false` is falsy
{%- endif -%}

{%- assign test_string = 'hi' | istruthy -%}
{%- if test_string -%}
  This will print because `'hi'` is truthy
{%- endif -%}

{%- assign test_empty_string = '' | istruthy -%}
{%- if test_empty_string -%}
  This will NOT print because `''` is falsy
{%- endif -%}

{%- assign test_null = null | istruthy -%}
{%- if test_null -%}
  This will NOT print because `null` is falsy
{%- endif -%}

{%- assign test_zero = 0 | istruthy -%}
{%- if test_zero -%}
  This will NOT print because `0` is falsy
{%- endif -%}

{%- assign test_one = 1 | istruthy -%}
{%- if test_one -%}
  This will print because `1` is truthy
{%- endif -%}

These examples show how you can use istruthy and isfalsy to easily check if a variable is "truthy" (not null, not an empty string, and not false) or "falsy" (null, an empty string, or false), respectively.

No more long, confusing, multi-condition if statements - just simple, readable code!

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Building and pushing

Run the tests

bundle install
bundle exec rspec

Publish the Gem

gem build jekyll-truthyfalsy.gemspec

gem push jekyll-truthyfalsy-1.0.0.gem

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/itw-creative-works/jekyll-truthyfalsy.