jekyll-tags.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'pathname'
  2. module Jekyll
  3. module Tags
  4. class Hide < Liquid::Block
  5. def initialize(tag_name, text, tokens)
  6. super
  7. @text = text
  8. end
  9. def render(context)
  10. '{% hide %}' + super.to_s + '{% endhide %}'
  11. end
  12. end
  13. class RemoveEmptyLines < Liquid::Block
  14. def initialize(tag_name, text, tokens)
  15. super
  16. @text = text
  17. end
  18. def render(context)
  19. super.strip.gsub /^[\t\s]*$\n/, ''
  20. end
  21. end
  22. class DocsUrl < Liquid::Tag
  23. def initialize(tag_name, path, tokens)
  24. super
  25. @path = path.strip
  26. end
  27. def render(context)
  28. url = context.environments.first.page.url.sub!(/^\//, '')
  29. pageDir = Pathname(url).parent
  30. ('./' + Pathname('docs/' + @path + '.html').relative_path_from(pageDir).to_s).gsub(/^\.\/\.\./, "..")
  31. end
  32. end
  33. end
  34. end
  35. Liquid::Template.register_tag('removeemptylines', Jekyll::Tags::RemoveEmptyLines)
  36. Liquid::Template.register_tag('docs_url', Jekyll::Tags::DocsUrl)
  37. Liquid::Template.register_tag('hide', Jekyll::Tags::Hide)