1
0
mirror of https://github.com/tabler/tabler.git synced 2025-12-26 11:16:12 +04:00

capture_once jekyll plugin, autosize fixes

This commit is contained in:
codecalm
2019-12-21 18:21:23 +01:00
parent fa80d6128a
commit f1c512de58
7 changed files with 60 additions and 24 deletions

View File

@@ -8,10 +8,10 @@ module Jekyll
def render(context)
if $captured_global[@text] === nil
$captured_global[@text] = '';
$captured_global[@text] = [];
end
$captured_global[@text] += super.strip + "\n\n"
$captured_global[@text].push(super.strip)
''
end
@@ -31,24 +31,49 @@ module Jekyll
''
end
end
class CaptureOnce < Liquid::Block
def initialize(tag_name, text, tokens)
super
@text = text.strip
end
def render(context)
if $captured_once[@text] === nil
$captured_once[@text] = [];
end
data = super.strip
unless $captured_once[@text].include?(data)
$captured_once[@text].push(data);
end
''
end
end
end
Jekyll::Hooks.register :site, :after_init do |page, jekyll|
$captured_global = {}
$captured_libs = []
$captured_once = {}
end
Jekyll::Hooks.register :pages, :pre_render do |page, jekyll|
jekyll.site['captured_global'] = $captured_global
jekyll.site['captured_once'] = $captured_once
jekyll.site['captured_libs'] = $captured_libs
end
Jekyll::Hooks.register :pages, :post_render do |page, jekyll|
$captured_global = {}
$captured_libs = []
$captured_once = {}
end
end
Liquid::Template.register_tag('capture_global', Jekyll::Tags::CaptureGlobal)
Liquid::Template.register_tag('capture_once', Jekyll::Tags::CaptureOnce)
Liquid::Template.register_tag('append_lib', Jekyll::Tags::CaptureScripts)