-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
368 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
list: {{ list }} | ||
inner: {{ inner }} | ||
n: {{ n }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ var }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## About this folder | ||
|
||
This folder is a playground where developers can test original liquid/jekyll code with real ruby via docker machines without need of installing ruby on local machine, as well as these libraries. | ||
|
||
### How to use | ||
Simply write your ruby script and run it with predefined runners. | ||
|
||
Run in jekyll: ` ./run_with_jekyll.sh your_script.rb` | ||
|
||
Run in liquid: ` ./run_with_liquid.sh your_script.rb` | ||
|
||
In fact, this may be same script, just unsure yourself you are safe in both cases: | ||
```ruby | ||
|
||
$is_Jekyll = false | ||
begin | ||
require "jekyll" | ||
puts "testing cases using jekyll" | ||
$is_Jekyll = true | ||
rescue LoadError | ||
require "liquid" | ||
puts "testing cases using liquid" | ||
end | ||
def isJekyll | ||
$is_Jekyll | ||
end | ||
|
||
# write your code here | ||
|
||
if isJekyll | ||
# add jekyll-specific code here | ||
else | ||
# add liquid-specific code here | ||
end | ||
``` | ||
|
||
For more complex tuning of *jekyll* environment, where the creation of `site` variable needed, here`s example how you can do that: | ||
```ruby | ||
|
||
config = Jekyll::Utils.deep_merge_hashes(Marshal.load(Marshal.dump(Jekyll::Configuration::DEFAULTS)), { | ||
"destination" => "dest", | ||
"incremental" => false, | ||
"includes_dir" => "_includes", | ||
"source" => ".", | ||
"skip_config_files" => true, | ||
"timezone" => "UTC", | ||
"url" => "http://example.com", | ||
"baseurl" => "/base", | ||
"disable_disk_cache" => true | ||
}) | ||
@site = Jekyll::Site.new(Jekyll::Configuration.from(config)) | ||
@context = Liquid::Context.new({}, {}, :site => @site) | ||
|
||
def render(data = {}, source) | ||
Liquid::Template.parse(source, {:strict_variables => true}).render!(@context, data); | ||
end | ||
``` | ||
|
||
*Liquid* is more simple one: | ||
```ruby | ||
Liquid::Template.file_system = Liquid::LocalFileSystem.new("_includes/", "%s.liquid") | ||
|
||
def render(data = {}, source) | ||
Liquid::Template.parse(source, {:strict_variables => true}).render!(data); | ||
end | ||
``` |
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
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
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
1 change: 1 addition & 0 deletions
1
ruby/cases_variable_inside_import/_includes/include_create_new_var.liquid
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% assign incl_var = 'incl_var' %} |
1 change: 1 addition & 0 deletions
1
ruby/cases_variable_inside_import/_includes/include_cycle.liquid
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% cycle 1,2,3,4 %} |
1 change: 1 addition & 0 deletions
1
ruby/cases_variable_inside_import/_includes/include_decrement_var.liquid
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% decrement var1 %},{% increment var2 %} |
1 change: 1 addition & 0 deletions
1
ruby/cases_variable_inside_import/_includes/include_ifchanged.liquid
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-->{% ifchanged %}2{% endifchanged %}<-- |
1 change: 1 addition & 0 deletions
1
ruby/cases_variable_inside_import/_includes/include_read_var.liquid
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ var }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'pp' | ||
|
||
$is_Jekyll = false | ||
begin | ||
require "jekyll" | ||
puts "testing cases using jekyll" | ||
$is_Jekyll = true | ||
rescue LoadError | ||
require "liquid" | ||
puts "testing cases using liquid" | ||
end | ||
def isJekyll | ||
$is_Jekyll | ||
end | ||
|
||
if isJekyll | ||
config = Jekyll::Utils.deep_merge_hashes(Marshal.load(Marshal.dump(Jekyll::Configuration::DEFAULTS)), { | ||
"destination" => "dest", | ||
"incremental" => false, | ||
"includes_dir" => "cases_variable_inside_import/_includes/", | ||
"source" => ".", | ||
"skip_config_files" => true, | ||
"timezone" => "UTC", | ||
"url" => "http://example.com", | ||
"baseurl" => "/base", | ||
"disable_disk_cache" => true | ||
}) | ||
@site = Jekyll::Site.new(Jekyll::Configuration.from(config)) | ||
@context = Liquid::Context.new({}, {}, :site => @site) | ||
|
||
def render(data = {}, source) | ||
Liquid::Template.parse(source, {:strict_variables => true}).render!(@context, data); | ||
end | ||
|
||
else | ||
Liquid::Template.file_system = Liquid::LocalFileSystem.new("cases_variable_inside_import/_includes/", "%s.liquid") | ||
|
||
def render(data = {}, source) | ||
Liquid::Template.parse(source, {:strict_variables => true}).render!(data); | ||
end | ||
end | ||
|
||
def assertEqual(expected, real) | ||
if expected != real | ||
raise "#{real} is not #{expected}" | ||
end | ||
end | ||
|
||
# liquid requires template without extension | ||
# | ||
# tested: Decrement, Increment, Cycle, TableRow, ifchanged | ||
# things to test: tags: , , For, , | ||
# visibility of variables from "with expression", | ||
if isJekyll | ||
assertEqual("variable", render({}, "{% assign var = 'variable' %}{% include include_read_var.liquid %}")); | ||
assertEqual("incl_var", render({}, "{% include include_create_new_var.liquid %}{{ incl_var }}")) | ||
|
||
# Like increment, variables declared inside decrement are independent from variables created through assign or capture. | ||
assertEqual("[-1,0][-2,1][-3,2][-3, 3]", render({}, "[{% decrement var1 %},{% increment var2 %}][{% include include_decrement_var.liquid %}][{% decrement var1 %},{% increment var2 %}][{{ var1 }}, {{ var2 }}]")) | ||
assertEqual("1234", render({}, "{% cycle 1,2,3,4 %}{% assign list = \"1\" | split: \",\" %}{% for n in list %}{% cycle 1,2,3,4 %}{% endfor %}{% cycle 1,2,3,4 %}{% include include_cycle.liquid %}")) | ||
assertEqual("12--><--3", render({}, "{% ifchanged %}1{% endifchanged %}{% ifchanged %}2{% endifchanged %}{% include include_ifchanged.liquid %}{% ifchanged %}3{% endifchanged %}")) | ||
else | ||
assertEqual("variable", render({}, "{% assign var = 'variable' %}{% include 'include_read_var' %}")); | ||
assertEqual("incl_var", render({}, "{% include 'include_create_new_var' %}{{ incl_var }}")) | ||
assertEqual("[-1,0][-2,1][-3,2][-3, 3]", render({}, "[{% decrement var1 %},{% increment var2 %}][{% include 'include_decrement_var' %}][{% decrement var1 %},{% increment var2 %}][{{ var1 }}, {{ var2 }}]")) | ||
assertEqual("1234", render({}, "{% cycle 1,2,3,4 %}{% assign list = \"1\" | split: \",\" %}{% for n in list %}{% cycle 1,2,3,4 %}{% endfor %}{% cycle 1,2,3,4 %}{% include 'include_cycle' %}")) | ||
assertEqual("12--><--3", render({}, "{% ifchanged %}1{% endifchanged %}{% ifchanged %}2{% endifchanged %}{% include 'include_ifchanged' %}{% ifchanged %}3{% endifchanged %}")) | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ fi | |
|
||
docker run -it --rm --name jekyll \ | ||
--volume=$PWD:/srv/jekyll \ | ||
-p 1234:1234 \ | ||
ruby_with_jekyll \ | ||
$1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% assign incl_var = 'incl_var' %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% cycle 1,2,3,4 %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% decrement var1 %},{% increment var2 %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% decrement var %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
>{% ifchanged %}2{% endifchanged %}< |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% for item in (1..2) %}{{ item }}{% endfor %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ var }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% assign val = 'INNER'%} |
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
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
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
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
Oops, something went wrong.