Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Turn config into JSON
Ruby
tree: 4c5e09a87b
Failed to load latest commit information.
README.markdown correct inconsistency in readme
jekyll_json.rb sketched out basics

README.markdown

Jekyll JSON

Jekyll JSON turns YAML config into JSON, so that you can use it in Javascript.

Passed a YAML key, it'll return a JSON, combining the page specific YAML with any config in _config.yml (using the value set on the page wherever there's a conflict).

Usage

Plonk jekyll_json.rb in your _plugins directory.

Use the tag like this:

{% yaml_to_json yaml_key_goes_here %}

An example

In _config.yml:

mapping:
    provider: google_js
    api_key: 123456
    zoom: 10
    dimensions:
        width: 600
        height: 400

In a page's front matter:

mapping:
    latitude: 0
    longitude: 0
    dimensions:
        width: 500
        height: 500

In your layout:

<script type="text/javascript">
    var some_object = {% yaml_to_json mapping %};
</script>

Returns:

<script type="text/javascript">
    var some_object = {
        "longitude":0,
        "api_key":123456,
        "dimensions":{
            "height":500,
            "width":500
        },
        "provider":"google_js",
        "latitude":0,
        "zoom":10
    };
</script>
Something went wrong with that request. Please try again.