1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: CC-BY-SA-3.0
16 def render_liquid page, content
17 liquid self.body, content, page, binding
21 # Render a page's liquid and return the intermediate result
22 def liquid template, content, page, binding = TOPLEVEL_BINDING
23 Liquid::Template.file_system = Liquid::LocalFileSystem.new(File.join(File.dirname(Rake.application().rakefile), "_includes"))
24 unless defined? @liquid_template
25 @liquid_template = Liquid::Template.parse(template)
29 vars["content"] = content
31 vars["site"] = site.config.h.clone
33 site.pages.each do |f, p|
34 pages[f] = p.config.h.clone
35 pages[f]["url"] = p.url
37 vars["site"]["pages"] = pages
39 vars["page"] = page.config.h.clone
40 vars["page"]["url"] = page.url
42 @liquid_template.render(vars)
46 class LiquidCode < Liquid::Include
47 Syntax = /(#{Liquid::QuotedFragment}+)(\s+(?:as)\s+(#{Liquid::QuotedFragment}+))?/o
49 def initialize(tag_name, markup, tokens)
50 Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens)
57 raise SyntaxError.new("Error in tag 'code' - Valid syntax: include '[code_file]' as '[language]'")
64 partial = load_cached_partial(context)
68 html = CodeRay.scan(partial.root.nodelist.join, @language).div
74 Liquid::Template.register_tag('code', LiquidCode)
77 class LiquidCodeBlock < Liquid::Block
78 Syntax = /((?:as)\s+(#{Liquid::QuotedFragment}+))?/o
80 def initialize(tag_name, markup, tokens)
81 Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens)
87 raise SyntaxError.new("Error in tag 'code' - Valid syntax: codeblock as '[language]'")
98 partial = partial[1..-1]
102 html = CodeRay.scan(partial, @language).div
105 "<notextile>#{html}</notextile>"
108 Liquid::Template.register_tag('codeblock', LiquidCodeBlock)