lib/asciidoctor/converter/template.rb in asciidoctor-2.0.15 vs lib/asciidoctor/converter/template.rb in asciidoctor-2.0.16

- old
+ new

@@ -38,17 +38,17 @@ @caches = { scans: ::Concurrent::Map.new, templates: ::Concurrent::Map.new } rescue ::LoadError @caches = { scans: {}, templates: {} } end - def self.caches - @caches - end + class << self + attr_reader :caches - def self.clear_caches - @caches[:scans].clear if @caches[:scans] - @caches[:templates].clear if @caches[:templates] + def clear_caches + @caches[:scans].clear + @caches[:templates].clear + end end def initialize backend, template_dirs, opts = {} Helpers.require_library 'tilt' unless defined? ::Tilt.new @backend = backend @@ -132,16 +132,14 @@ # name - the String template name # template - the Tilt template object to register # # Returns the Tilt template object def register name, template - @templates[name] = if (template_cache = @caches[:templates]) + if (template_cache = @caches[:templates]) template_cache[template.file] = template - else - template end - #create_handler name, template + @templates[name] = template end private # Internal: Scans the template directories specified in the constructor for Tilt-supported @@ -153,10 +151,11 @@ path_resolver = PathResolver.new backend = @backend engine = @engine @template_dirs.each do |template_dir| # FIXME need to think about safe mode restrictions here + # Ruby 2.3 requires the extra brackets around the path_resolver.system_path method call next unless ::File.directory?(template_dir = (path_resolver.system_path template_dir)) if engine file_pattern = %(*.#{engine}) # example: templates/haml @@ -184,12 +183,12 @@ @templates[name] = template_cache[template.file] = template end else @templates.update scan_dir(template_dir, pattern, @caches[:templates]) end - nil end + nil end # Internal: Scan the specified directory for template files matching pattern and instantiate # a Tilt template for each matched file. # @@ -260,10 +259,10 @@ elsif name == 'erubi' Helpers.require_library 'erubi' unless defined? ::Erubis::Engine [::Tilt::ErubiTemplate, {}] elsif name == 'erubis' Helpers.require_library 'erubis' unless defined? ::Erubis::FastEruby - [::Tilt::ErubisTemplate, { engine_class: ::Erubis::FastEruby }] + [::Tilt::ErubisTemplate, engine_class: ::Erubis::FastEruby] else raise ::ArgumentError, %(Unknown ERB implementation: #{name}) end end end