Created
April 8, 2015 01:15
-
-
Save arthurnn/c17b6173b9f701ba924b to your computer and use it in GitHub Desktop.
This file contains 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
require 'liquid' | |
require 'json' | |
liquid = <<-DOC | |
{% block_settings %} | |
{ | |
"name": "Ken block", | |
"settings": [ | |
{ | |
"type": "text", | |
"id": "texta", | |
"label": "Main Label" | |
}, | |
{ | |
"type": "text", | |
"id": "textb", | |
"label": "Sub-label" | |
} | |
] | |
} | |
{% endblock_settings %} | |
{% block_content %} | |
hello {{ block.texta | default: 'foobar' }} and {{ block.textb | default: 'second' }} | |
foobar | |
{% endblock_content %} | |
DOC | |
class BlockSettings < Liquid::Block | |
def to_s | |
nodelist.first | |
end | |
def schema | |
JSON.parse to_s | |
end | |
end | |
class BlockContent < Liquid::Block | |
def to_s | |
nodelist.first | |
end | |
end | |
Liquid::Template.register_tag('block_settings', BlockSettings) | |
Liquid::Template.register_tag('block_content', BlockContent) | |
template = Liquid::Template.parse(liquid) | |
template.root.nodelist.each do |node| | |
@schema = node.schema if node.is_a? BlockSettings | |
@liquid_body = node if node.is_a? BlockContent | |
end | |
p @schema | |
p @liquid_body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment