jekyll-capture.rb 779 B

1234567891011121314151617181920212223242526272829303132333435
  1. module Jekyll
  2. module Tags
  3. class CaptureGlobal < Liquid::Block
  4. def initialize(tag_name, text, tokens)
  5. super
  6. @text = text.strip
  7. end
  8. def render(context)
  9. unless $captured_global[@text]
  10. $captured_global[@text] = [];
  11. end
  12. $captured_global[@text].push(super.strip)
  13. ''
  14. end
  15. end
  16. end
  17. Jekyll::Hooks.register [:pages, :docs], :post_init do |page|
  18. $captured_global = {}
  19. end
  20. Jekyll::Hooks.register [:pages, :docs], :post_render do |page|
  21. $captured_global = {}
  22. end
  23. Jekyll::Hooks.register [:pages, :docs], :pre_render do |page, jekyll|
  24. jekyll.site['captured_global'] = $captured_global
  25. end
  26. end
  27. Liquid::Template.register_tag('capture_global', Jekyll::Tags::CaptureGlobal)