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)
53 @template_name_expr = $1
57 raise SyntaxError.new("Error in tag 'code' - Valid syntax: include '[code_file]' as '[language]'")
64 partial = load_cached_partial(@template_name_expr, context)
67 # be explicit about errors
68 context.exception_renderer = lambda do |exc|
69 exc.is_a?(Liquid::InternalError) ? "Liquid error: #{exc.cause.message}" : exc
73 html = CodeRay.scan(partial.root.nodelist.join, @language).div
79 Liquid::Template.register_tag('code', LiquidCode)
82 class LiquidCodeBlock < Liquid::Block
83 Syntax = /((?:as)\s+(#{Liquid::QuotedFragment}+))?/o
85 def initialize(tag_name, markup, tokens)
86 Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens)
92 raise SyntaxError.new("Error in tag 'code' - Valid syntax: codeblock as '[language]'")
102 if partial[0] == '\n'
103 partial = partial[1..-1]
106 # be explicit about errors
107 context.exception_renderer = lambda do |exc|
108 exc.is_a?(Liquid::InternalError) ? "Liquid error: #{exc.cause.message}" : exc
112 html = CodeRay.scan(partial, @language).div
115 "<notextile>#{html}</notextile>"
118 Liquid::Template.register_tag('codeblock', LiquidCodeBlock)