Faker wrapper for Jekyll, a library that generates fake data
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
lib
script
spec
.codeclimate.yml
.editorconfig
.gitignore
.rubocop.yml
.travis.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gemfile
LICENSE
README.md
Rakefile
jekyll-faker.gemspec

README.md

Code Climate Code Climate Travis CI Gem Version Gem DL

Jekyll Faker

Jekyll Faker is a Jekyll/Liquid wrapper around the Faker gem, it allows you to do anything that Faker allows you to do, as long as it's an acceptable format. It is disaware of it's surroundings, and is extensible by automatic upgrade, meaning... if faker adds new methods, or even new classes, you can continue to use it without needing to upgrade Jekyll Faker.

Installing

gem "jekyll-faker"
gem "jekyll-faker", {
  git: "https://github.com/anomaly/jekyll-faker.git"
}

Usage

Given faker has a class called Lorem, and that class Lorem accepts messages to the method sentences, you can then do the following to extract the data from Faker:

{% faker lorem sentences=8 %}
  <p>{{ faker.val }}</p>
{% endfaker %}

w/ the result

<p>Sentence 1</p>
<p>Sentence 2</p>
<p>Sentence 3</p>
<p>Sentence 4</p>
<p>Sentence 5</p>
<p>Sentence 6</p>
<p>Sentence 7</p>
<p>Sentence 8</p>

Multiple Arguments

If a class and method you wish to use takes multiple arguments, you can replicate the name of the method multiple times to create an array that will be expanded, and messaged to the method. For example:

{% faker number between=1 between=10 %}
  <small>
    {{ faker.val }}
  </small>
{% endfaker %}

CamelCase classes

If a Faker is a CamelCased class, for example "DrWho" (even though technically it's supposed to be DoctorWho, it's Doctor, not Dr, who even does that?) You can do the following:

{% faker dr-who catch_phrase %}
  <p>{{ faker.val }}</p>
{% endfaker %}

or

{% faker id-number valid %}
  <p>{{ faker.val }}</p>
{% endfaker %}

We will attempt to determine the class name automatically, first, efficiently by assuming the dash is a literal for uppercase, and then by doing a simple regexp search, this should often result in the class being found.*