mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Remove inline snippet specific example files
This commit is contained in:
committed by
Guilherme Carreiro
parent
99116638fd
commit
489a03118c
@@ -1,59 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/inline'
|
||||
|
||||
gemfile(true) do
|
||||
source "https://rubygems.org"
|
||||
gem 'liquid'
|
||||
end
|
||||
|
||||
require 'liquid'
|
||||
|
||||
class Parser
|
||||
def initialize(template)
|
||||
@template = template
|
||||
end
|
||||
|
||||
def parse
|
||||
@parsed_template = Liquid::Template.parse(@template)
|
||||
end
|
||||
|
||||
def test_parse
|
||||
document = @parsed_template.root
|
||||
|
||||
variables = []
|
||||
|
||||
if document.is_a?(Liquid::Document)
|
||||
body = document.body
|
||||
|
||||
if body.is_a?(Liquid::BlockBody)
|
||||
body.nodelist.each do |node|
|
||||
next unless node.is_a?(Liquid::Variable)
|
||||
|
||||
puts node.inspect
|
||||
variable_name = node.name.name
|
||||
variables << variable_name
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Variables: #{variables}"
|
||||
end
|
||||
|
||||
def render
|
||||
@parsed_template.render
|
||||
end
|
||||
end
|
||||
|
||||
starter_template = "{{ foo }}"
|
||||
starter_template_2 = "{{foo}}, {{bar}}"
|
||||
starter_template_2_1 = "{{ foo }} and {{ bar }}"
|
||||
starter_template_3 = "{% assign foo = 'bar' %}{{ foo }}"
|
||||
# Let's start small here
|
||||
template = <<~LIQUID
|
||||
{% assign foo = 'bar' %}
|
||||
{{ foo }}
|
||||
LIQUID
|
||||
|
||||
parser = Parser.new(starter_template)
|
||||
parser.parse
|
||||
parser.test_parse
|
||||
@@ -1,43 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Inline Snippets</title>
|
||||
<p>Hello world!</p>
|
||||
|
||||
<body>
|
||||
<div class="liquid" style="font-size: 56px;">
|
||||
<p>It is {{ date }}</p>
|
||||
|
||||
{% assign foo = true %}
|
||||
{% assign linktext = "variable" %}
|
||||
|
||||
{% snippet main %}
|
||||
{% assign foo = false %}
|
||||
<p>Hi {{ arg | upcase }}!!!</p>
|
||||
|
||||
<p>This is an inline snippet</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="/wow-a-link">wow a {{ linktext }}</a></li>
|
||||
<li>1 + 1 = {{ 1 | plus: 1 }}</li>
|
||||
<li>{% if true %}Yes!{% endif %}</li>
|
||||
<li>foo = {% if foo %}true{%else%}false{% endif %}</li>
|
||||
<li>{{ missing_var | default: 'fallback' }}</li>
|
||||
</ul>
|
||||
{% endsnippet %}
|
||||
|
||||
{% render main, arg: 'lsf', ... %}
|
||||
{{ foo }}
|
||||
|
||||
{% snippet listitem %}
|
||||
<li>{{ forloop.index }}: {{ emoji }}</li>
|
||||
{% endsnippet %}
|
||||
|
||||
{% assign emojis = "🌼,🌳,🌸" | split: "," %}
|
||||
<ul style="list-style-type: none; display: flex; gap: 1em;">
|
||||
{%- render listitem for emojis as emoji -%}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<p>Check out the <a href="/products">Products</a> screen</p>
|
||||
|
||||
Reference in New Issue
Block a user