class Asciidoctor::Converter::TemplateConverter
def scan_dir template_dir, pattern, template_cache = nil
a Tilt template for each matched file.
Internal: Scan the specified directory for template files matching pattern and instantiate
def scan_dir template_dir, pattern, template_cache = nil result, helpers = {}, nil # Grab the files in the top level of the directory (do not recurse) ::Dir.glob(pattern).keep_if {|match| ::File.file? match }.each do |file| if (basename = ::File.basename file) == 'helpers.rb' helpers = file next elsif (path_segments = basename.split '.').size < 2 next end if (name = path_segments[0]) == 'block_ruler' name = 'thematic_break' elsif name.start_with? 'block_' name = name.slice 6, name.length end unless template_cache && (template = template_cache[file]) template_class, extra_engine_options, extsym = ::Tilt, {}, path_segments[-1].to_sym case extsym when :slim unless @active_engines[extsym] # NOTE slim doesn't get automatically loaded by Tilt Helpers.require_library 'slim' unless defined? ::Slim::Engine require 'slim/include' unless defined? ::Slim::Include ::Slim::Engine.define_options asciidoc: {} # align safe mode of AsciiDoc embedded in Slim template with safe mode of current document # NOTE safe mode won't get updated if using template cache and changing safe mode (@engine_options[extsym][:asciidoc] ||= {})[:safe] ||= @safe if @safe @active_engines[extsym] = true end when :haml unless @active_engines[extsym] Helpers.require_library 'haml' unless defined? ::Haml::Engine # NOTE Haml 5 dropped support for pretty printing @engine_options[extsym].delete :ugly if defined? ::Haml::TempleEngine @engine_options[extsym][:attr_quote] = @engine_options[extsym].delete :attr_wrapper unless defined? ::Haml::Options @active_engines[extsym] = true end when :erb template_class, extra_engine_options = (@active_engines[extsym] ||= (load_eruby @eruby)) when :rb next else next unless ::Tilt.registered? extsym.to_s end template = template_class.new file, 1, (@engine_options[extsym] ||= {}).merge(extra_engine_options) end result[name] = template end if helpers || ::File.file?(helpers = %(#{template_dir}/helpers.rb)) require helpers end result end