Git Product home page Git Product logo

jekyll-humanize's Introduction

jekyll-humanize

This began as a port of the Django app humanize which adds a "human touch" to data. Each method represents a Fluid type filter that can be used in your Jekyll site templates. Given that Jekyll produces static sites, some of the original methods do not make logical sense to port (e.g. naturaltime).

Installation

Simply download the humanize.rb file and place it in the _plugins directory of your Jekyll site.

Usage

Each of the methods in the file presents an available Fluid type filter to be used in Jekyll templates.

There is one optional setting that can be overridden in your _config.yml file. The setting should follow the format below and should be a valid strftime date string. Documentation on strftime can be found at www.ruby-doc.com.

humanize:
    date_format: "%m/%d/%Y"

ordinal(value, flag="super")

Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd', 3 is '3rd', etc. Works for any integer. An optional flag can be added which puts the ordinal suffix in <sup></sup> tags.

{{ somenum }} >>> 3
{{ somenum | ordinal }} >>> '3rd'
{{ somenum | ordinal: "super" }} >>> '3<sup>rd</sup>'

intcomma(value, delimiter=",")

Converts an integer to a string containing commas every three digits. For example, 3000 becomes '3,000' and 45000 becomes '45,000'. Optionally supports a delimiter override for commas (if you wanted to use periods for European numerical separators).

{{ post.content | number_of_words }} >>> 12345
{{ post.content | number_of_words | intcomma }} >>> '12,345'
{{ post.content | number_of_words | intcomma: '.' }} >>> '12.345'

intword(value)

Converts a large integer to a friendly text representation. Works best for numbers over 1 million. For example, 1000000 becomes '1.0 million'. 1200000 becomes '1.2 million' and 1200000000 becomes '1.2 billion'.

{{ largenum }} >>> 1200000
{{ largenum | intword }} >>> '1.2 million'

apnumber(value)

For numbers 0-9, returns the number spelled out. Otherwise, returns the number. This follows the Associated Press style.

{{ num }} >>> 6
{{ num | apnumber }} >>> 'six'

naturalday(date)

For date values that are within a 9 day stretch from present day, this will attempt to return the string representation in the format of today, tomorrow, yesterday, "in # days" or "# days ago". Otherwise, returns a string formatted according to the date_format setting in your _config.yml file using strftime format. If not defined, it will default to %m/%d/%Y.

# TODAY == '01/26/2014'
{{ post.updated }} >>> 01/25/2014
{{ post.updated | naturalday }} >>> 'yesterday'
{{ post.date }} >>> 01/19/2014
{{ post.date | naturalday }} >>> 'seven days ago'

filesize(bytes)

For filesize values in bytes, returns the number rounded to 3 decimal places with the correct suffix.

{{ bytes }} >>> 123456789
{{ bytes | filesize }} >>> 117.738 MB

License

LICENSE

Django Humanize

Copyright (c) Django Software Foundation and individual contributors. All rights reserved.

Source code for the original Django app can be viewed at https://github.com/django/django.

JS-humanize

Filesize format forked from javascript to ruby from https://github.com/milanvrekic/JS-humanize

Changelog

CHANGELOG

Issues

Issue Stats

You can log issues from the menu at right, or by clicking here. Curious about responsiveness? Check out our Issue Stats!

Contribute

Issue Stats

  1. Fork this repo.
  2. Create a branch git checkout -b my_feature
  3. Commit your changes git commit -am "Added Feature"
  4. Push to the branch git push origin my_feature
  5. Open a Pull Request

jekyll-humanize's People

Contributors

23maverick23 avatar jart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.