Skip to content

Commit

Permalink
Merge pull request culturekings#2 from culturekings/lazy-decode-tweaks
Browse files Browse the repository at this point in the history
Formatting changes and add variable namespaces
  • Loading branch information
Jore authored Mar 1, 2017
2 parents 4c03e48 + e65a625 commit dd0d2ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,5 @@ To overcome this we have developed a very simple lazy parser that only looks for
Usage is as follows

```liquid
{% include 'json_lazy_decode' json: product.metafields.global.JAN key: 'three_sixty' %}{% assign three_sixty = jd__yield_1 %}
{% include 'json_lazy_decode' json: product.metafields.global.JAN key: 'three_sixty' %}{% assign three_sixty = jld__yield_1 %}
```
23 changes: 11 additions & 12 deletions json_lazy_decode.liquid
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{%- comment -%}
This function is used when speed is important.
It simply searches for key.
The value of the key must be a simple array
Usage : {% include 'json_lazy_decode' json: product.metafields.global.JAN key: 'three_sixty' %}{% assign three_sixty = jd__yield_1 %}
This function is used when speed is important, it simply searches for key.
The value of the key must be a simple array.
Usage:
{% include 'json_lazy_decode' json: product.metafields.global.JAN key: 'three_sixty' %}{% assign three_sixty = jld__yield_1 %}
{%- endcomment -%}
{%- assign key_quoted = key | append : '"' | prepend : '"' -%}
{%- assign value = json | split: key_quoted -%}
{%- assign value = value[1] | split: '[' -%}
{%- assign value = value[1] | split: ']' -%}
{%- assign value = value[0] | replace: '"', '' -%}
{%- assign jd__yield_1 = value | split: ',' -%}
{%- assign jld__key_quoted = key | append : '"' | prepend : '"' -%}
{%- assign jld__value = json | split: jld__key_quoted -%}
{%- assign jld__value = jld__value[1] | split: '[' -%}
{%- assign jld__value = jld__value[1] | split: ']' -%}
{%- assign jld__value = jld__value[0] | replace: '"', '' -%}
{%- assign jld__yield_1 = jld__value | split: ',' -%}

0 comments on commit dd0d2ed

Please sign in to comment.