lib/asciidoctor/converter/template.rb in asciidoctor-1.5.6.2 vs lib/asciidoctor/converter/template.rb in asciidoctor-1.5.7

- old
+ new

@@ -37,12 +37,10 @@ begin require 'thread_safe' unless defined? ::ThreadSafe @caches = { :scans => ::ThreadSafe::Cache.new, :templates => ::ThreadSafe::Cache.new } rescue ::LoadError @caches = { :scans => {}, :templates => {} } - # FIXME perhaps only warn if the cache option is enabled (meaning not disabled)? - warn 'asciidoctor: WARNING: gem \'thread_safe\' is not installed. This gem is recommended when using custom backend templates.' end def self.caches @caches end @@ -75,10 +73,11 @@ (@engine_options[engine] ||= {}).update override_opts end end case opts[:template_cache] when true + logger.warn 'gem \'thread_safe\' is not installed. This gem is recommended when using the built-in template cache.' unless defined? ::ThreadSafe @caches = self.class.caches when ::Hash @caches = opts[:template_cache] else @caches = {} # the empty Hash effectively disables caching @@ -103,28 +102,29 @@ path_resolver = PathResolver.new backend = @backend engine = @engine @template_dirs.each do |template_dir| # FIXME need to think about safe mode restrictions here - next unless ::File.directory?(template_dir = (path_resolver.system_path template_dir, nil)) + next unless ::File.directory?(template_dir = (path_resolver.system_path template_dir)) - # NOTE last matching template wins for template name if no engine is given - file_pattern = '*' if engine file_pattern = %(*.#{engine}) # example: templates/haml - if ::File.directory?(engine_dir = (::File.join template_dir, engine)) + if ::File.directory?(engine_dir = %(#{template_dir}/#{engine})) template_dir = engine_dir end + else + # NOTE last matching template wins for template name if no engine is given + file_pattern = '*' end - # example: templates/html5 or templates/haml/html5 - if ::File.directory?(backend_dir = (::File.join template_dir, backend)) + # example: templates/html5 (engine not set) or templates/haml/html5 (engine set) + if ::File.directory?(backend_dir = %(#{template_dir}/#{backend})) template_dir = backend_dir end - pattern = ::File.join template_dir, file_pattern + pattern = %(#{template_dir}/#{file_pattern}) if (scan_cache = @caches[:scans]) template_cache = @caches[:templates] unless (templates = scan_cache[pattern]) templates = (scan_cache[pattern] = (scan_dir template_dir, pattern, template_cache)) @@ -159,11 +159,11 @@ metaclass.send :define_method, name do |node| (template.render node).strip end else metaclass.send :define_method, name do |node| - (template.render node).chomp + (template.render node).rstrip end end end =end @@ -191,11 +191,11 @@ # NOTE opts become locals in the template if template_name == 'document' (template.render node, opts).strip else - (template.render node, opts).chomp + (template.render node, opts).rstrip end end # Public: Checks whether there is a Tilt template registered with the specified name. # @@ -278,10 +278,10 @@ end template = template_class.new file, 1, (@engine_options[extsym] ||= {}).merge(extra_engine_options) end result[name] = template end - if helpers || ::File.file?(helpers = (::File.join template_dir, 'helpers.rb')) + if helpers || ::File.file?(helpers = %(#{template_dir}/helpers.rb)) require helpers end result end