Created
November 22, 2013 04:31
-
-
Save daxanya2/7594886 to your computer and use it in GitHub Desktop.
JekyllのテンプレートのListとHashで結構いけるんじゃないかな ref: http://qiita.com/daxanya2/items/24695a2a9d8bd6526b53
This file contains hidden or 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
module Jekyll | |
module ContextArray | |
def contextarray(input) | |
if !input.kind_of?(Array) | |
src = input | |
input = [src] | |
end | |
data = [] | |
input.each {|a| | |
data.push(@context[a]) | |
} | |
data | |
end | |
end | |
end | |
Liquid::Template.register_filter(Jekyll::ContextArray) |
This file contains hidden or 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
def parse_params(context) | |
params = {} | |
markup = @params | |
while match = VALID_SYNTAX.match(markup) do | |
markup = markup[match.end(0)..-1] | |
value = if match[2] | |
match[2].gsub(/\\"/, '"') | |
elsif match[3] | |
match[3].gsub(/\\'/, "'") | |
elsif match[4] | |
context[match[4]] | |
elsif match[5] | |
array = [] | |
match[5].split(/\s*,\s*/).each {|i| | |
avalue = if md = i.match(/^(?:"([^"\\]*(?:\\.[^"\\]*)*)")$/) | |
md[1].gsub(/\\"/, '"') | |
elsif md = i.match(/^(?:'([^'\\]*(?:\\.[^'\\]*)*)')$/) | |
md[1].gsub(/\\'/, "'") | |
elsif context.has_key?(i) | |
context[i] | |
else | |
i | |
end | |
array.push(avalue) | |
} | |
array | |
end | |
params[match[1]] = value | |
end | |
params | |
end |
This file contains hidden or 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
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+)|\[([^\[\]]+)\])/ |
This file contains hidden or 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
{{ include.param1.name }}<br /> | |
{{ include.param1.value }}<br /> | |
<br /> | |
{% for data in include.param2 %} | |
{{ data }}<br /> | |
{% endfor %} |
This file contains hidden or 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
{% for data in include.param %} | |
{{ data.name }}<br /> | |
{{ data.value }}<br /> | |
{% endfor %} |
This file contains hidden or 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
module Jekyll | |
module NumberFormat | |
def numberformat(number) | |
number.to_s.reverse.gsub( /(\d{3})(?=\d)/, '\1,' ).reverse | |
end | |
end | |
end | |
Liquid::Template.register_filter(Jekyll::NumberFormat) |
This file contains hidden or 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
{% capture counti %}{{ include.item[0].value | size | minus:'1' }}{% endcapture %} | |
{% capture countj %}{{ include.item | size | minus:'1' }}{% endcapture %} | |
<table> | |
<tr> | |
{% for itemdata in include.item %} | |
<th>{{ itemdata.name }}</th> | |
{% endfor %} | |
</tr> | |
{% for i in (0..counti) %} | |
<tr> | |
{% for j in (0..countj) %} | |
{% if include.item[j].numfilter %} | |
<td>{{ include.item[j].value[i] | numberformat }}</td> | |
{% else %} | |
<td>{{ include.item[j].value[i] }}</td> | |
{% endif %} | |
{% endfor %} | |
</tr> | |
{% endfor %} | |
</table> |
This file contains hidden or 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
--- | |
title: template1 | |
layout: default | |
hash1: | |
name: Hash構造 | |
value: 値が入る | |
list2: | |
- 一番目 | |
- 二番目 | |
--- | |
{{ page.hash1.name }}<br /> | |
{{ page.hash1.value }}<br /> | |
<br /> | |
{% for data in page.list2 }} | |
{{ data }}<br /> | |
{% endfor %} |
This file contains hidden or 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
--- | |
title: template2 | |
layout: default | |
hash3: | |
name: | |
- 三番目 | |
- 四番目 | |
value: 値が入る | |
list4: | |
- list: [11,12, 13 ,"文字も入るよ"] | |
- list: [22, 23 ,24,スペース も入るよ] | |
--- | |
{{ page.hash3.name }}<br /> | |
{{ page.hash3.value }}<br /> | |
<br /> | |
{% for data in page.list4 }} | |
{% for item in data.list }} | |
{{ data }}<br /> | |
{% endfor %} | |
{% endfor %} |
This file contains hidden or 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
--- | |
title: template3 | |
layout: default | |
hash1: | |
name: Hash構造 | |
value: 値が入る | |
list2: | |
- 一番目 | |
- 二番目 | |
--- | |
{% include include1.liquid param1=page.hash1 param2=page.list2 %} |
This file contains hidden or 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
--- | |
title: template4 | |
layout: default | |
hash1: | |
name: Hash構造 | |
value: 値が入る | |
hash2: | |
name: Hash構造2 | |
value: 値が入る2 | |
--- | |
{% include include2.liquid param=[page.hash1, page.hash2] %} |
This file contains hidden or 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
--- | |
title: template5 | |
layout: default | |
hash1: | |
name: Hash構造 | |
value: 値が入る | |
hash2: | |
name: Hash構造2 | |
value: 値が入る2 | |
--- | |
{% assign list = "page.hash1|page.hash2" | split: "|" %} | |
{% include include2.liquid param=list %} |
This file contains hidden or 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
--- | |
title: template6 | |
layout: default | |
hash1: | |
name: Hash構造 | |
value: 値が入る | |
hash2: | |
name: Hash構造2 | |
value: 値が入る2 | |
--- | |
{% assign list = "page.hash1|page.hash2" | split: "|" | contextarray %} | |
{% include include2.liquid param=list %} |
This file contains hidden or 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
--- | |
title: template7 | |
layout: default | |
item1: | |
name: 日付 | |
value: [11/11, 11/11, 11/13, 11/14] | |
item2: | |
name: 用途 | |
value: [弁当, ガンプラ, 映画, 漫画] | |
item3: | |
name: 金額 | |
value: [300, 4300, 1800, 680] | |
numfilter: 1 | |
--- | |
{% include table.liquid item=[page.item1, page.item2, page.item3] %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment