X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/55aafbb07904ca24390dd47ea960eae7cb2b909a..489aed58cb0d8bd816e07128cfcb9f5a06224083:/doc/zenweb-liquid.rb diff --git a/doc/zenweb-liquid.rb b/doc/zenweb-liquid.rb index 4a6828188e..baa8fe42db 100644 --- a/doc/zenweb-liquid.rb +++ b/doc/zenweb-liquid.rb @@ -16,7 +16,7 @@ module Zenweb def render_liquid page, content liquid self.body, content, page, binding end - + ## # Render a page's liquid and return the intermediate result def liquid template, content, page, binding = TOPLEVEL_BINDING @@ -24,7 +24,7 @@ module Zenweb unless defined? @liquid_template @liquid_template = Liquid::Template.parse(template) end - + vars = {} vars["content"] = content @@ -38,7 +38,7 @@ module Zenweb vars["page"] = page.config.h.clone vars["page"]["url"] = page.url - + @liquid_template.render(vars) end end @@ -57,7 +57,7 @@ module Zenweb raise SyntaxError.new("Error in tag 'code' - Valid syntax: include '[code_file]' as '[language]'") end end - + def render(context) require 'coderay' @@ -71,6 +71,40 @@ module Zenweb html end - Liquid::Template.register_tag('code', LiquidCode) + Liquid::Template.register_tag('code', LiquidCode) + end + + class LiquidCodeBlock < Liquid::Block + Syntax = /((?:as)\s+(#{Liquid::QuotedFragment}+))?/o + + def initialize(tag_name, markup, tokens) + Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens) + + if markup =~ Syntax + @language = $2 + @attributes = {} + else + raise SyntaxError.new("Error in tag 'code' - Valid syntax: codeblock as '[language]'") + end + end + + def render(context) + require 'coderay' + + partial = super + html = '' + + if partial[0] == '\n' + partial = partial[1..-1] + end + + context.stack do + html = CodeRay.scan(partial, @language).div + end + + "#{html}" + end + + Liquid::Template.register_tag('codeblock', LiquidCodeBlock) end end