middleman-template/lib/adoc.rb

83 lines
2.8 KiB
Ruby

require 'asciidoctor'
require 'tilt/asciidoc'
Haml::Filters.register_tilt_filter :Asciidoc, alias: %w[ad adoc]
class Middleman::Extension
private
unless method_defined? :initialize_without_debug
def initialize_with_debug *a, **o, &e
STDERR.printf "> ME-init: class=%p\nargs=%p\nopts=%p\n", self.class, a, o
initialize_without_debug *a, **o, &e
STDERR.printf "< ME-init: self=%p\n", self
end
alias initialize_without_debug initialize
alias initialize initialize_with_debug
end
end if false
class Middleman::ExtensionManager
unless method_defined? :activate_without_debug
def activate_with_debug *arguments, **options, &exe
STDERR.printf "> MEM-activate: class=%p\narguments=%p\noptions=%p\n", self.class, arguments, options
r = activate_without_debug *arguments, **options, &exe
STDERR.printf "< MEM-activate: r=%p\nasciidoc=%p\n", r, @activated[:asciidoc]
r
end
alias activate_without_debug activate
alias activate activate_with_debug
end
end if false
class Middleman::AsciiDoc::AsciiDocExtension
option :template_dirs, [], 'Custom templates' unless config.defines_setting? :template_dirs
option :template_cache, [], 'Deactivate cache for custom templates' unless config.defines_setting? :template_cache
option :template_engine, nil, 'Template engine to use for custome templates' unless config.defines_setting? :template_engine
end
module ::Asciidoctor
class << self
def load_file_with_debug fn, **opts, &e
# opts[:template_dir] ||= opts[:attributes][:template_dir]
# opts[:template_engine] ||= opts[:attributes][:template_engine]
opts[:template_dir] ||= 'asciidoctor-backends/haml'
opts[:template_engine] ||= 'haml'
opts[:template_cache] = false unless opts.has_key? :template_cache
STDERR.printf "> AD.load_file %p\nopts=%p\n", fn, opts
load_file_without_debug fn, **opts, &e
end
alias load_file_without_debug load_file
alias load_file load_file_with_debug
end unless respond_to? :load_file_without_debug
end if false
class ::Asciidoctor::Document
unless method_defined? :create_converter_without_debug
def create_converter_with_debug
STDERR.printf "> ADD.create_converter options=%p\n", @options
r = create_converter_without_debug
STDERR.printf "< ADD.create_converter return=%p\n", r
r
end
alias create_converter_without_debug create_converter
alias create_converter create_converter_with_debug
end
end if false
class ::Asciidoctor::Document
private
unless private_method_defined? :initialize_without_debug
def initialize_with_debug *args, **opts, &exe
opts = opts.merge template_dir: 'asciidoctor-backends/haml', template_dirs: ['asciidoctor-backends/haml'], template_engine: 'haml', template_cache: false, base_dir: 'source'
initialize_without_debug *args, **opts.symbolize_keys, &exe
end
alias initialize_without_debug initialize
alias initialize initialize_with_debug
end
end