Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created April 8, 2015 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurnn/c17b6173b9f701ba924b to your computer and use it in GitHub Desktop.
Save arthurnn/c17b6173b9f701ba924b to your computer and use it in GitHub Desktop.
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