Skip to content

Instantly share code, notes, and snippets.

@archiloque
Created February 8, 2016 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archiloque/5d212fa618abfaed624c to your computer and use it in GitHub Desktop.
Save archiloque/5d212fa618abfaed624c to your computer and use it in GitHub Desktop.
helpers to simplifie writing a new asciidoctor
require 'set'
module Asciidoctor
# Fake template
class DebuggerTemplate
def render scope, params
''
end
end
# Patch the converter
class Converter::TemplateConverter
# Handle anything, just ask !
def handles? name
unless @templates.key? name
@templates[name] = DebuggerTemplate.new
end
true
end
def convert node, template_name = nil, opts = {}
@lines ||= Set.new
log_line = nil
value = nil
if node.is_a? Asciidoctor::Block
value = node.content
log_line = "Convert #{node.class} with #{template_name} template for #{node.context}"
elsif node.is_a? Asciidoctor::AbstractBlock
value = node.content
log_line = "Convert #{node.class} with #{template_name} template"
elsif node.is_a? Asciidoctor::Inline
value = node.text
log_line = "Convert #{node.class} with #{template_name} template"
else
raise "Can convert #{node.class}"
end
if @lines.add?(log_line)
p log_line
end
value
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment