Created
February 8, 2016 22:30
-
-
Save archiloque/5d212fa618abfaed624c to your computer and use it in GitHub Desktop.
helpers to simplifie writing a new asciidoctor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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