Last active
August 12, 2018 21:27
-
-
Save stewartknapman/92c2bc0ffa1ded2c742140b1fd0c1088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} | |
Title case a string of text. | |
Usage: {% include 'title-case' string: 'my string' %} | |
{% endcomment %} | |
{%- capture str -%}{%- endcapture -%} | |
{%- assign small_words = 'a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs|vs.|via|with' | split:'|' -%} | |
{%- assign string_parts = string | split: ' ' -%} | |
{%- for p in string_parts -%} | |
{%- assign is_small = false -%} | |
{%- for s in small_words -%} | |
{% if p == s %}{%- assign is_small = true -%}{% endif %} | |
{%- endfor -%} | |
{%- capture str %}{% unless forloop.first %}{{ str }} {% endunless %}{% if is_small %}{{ p }}{% else %}{{ p | capitalize }}{% endif %}{% endcapture -%} | |
{%- endfor -%}{{- str -}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment