Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Resolves #2, Use a simpler implementation to read templates
Browse files Browse the repository at this point in the history
Replace File.exists and File.directory? with File.read because they are not available in a browser environment.
Also narrow down the number of locations where we were looking for templates:

 - #{template_dir}/#{name}.jade
 - #{template_dir}/jade/#{name}.jade
  • Loading branch information
ggrossetie committed Oct 1, 2016
1 parent ac11235 commit c102808
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/asciidoctor/core_ext/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,35 @@ def resolve_template name
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))

# NOTE last matching template wins for template name if no engine is given
# REMIND: All templates must be directly available in "template_dir"
# TODO: Remove the following block of code once the Reveal.js backend template complies with this new convention
# -- start
if engine
# example: templates/haml
if ::File.directory?(engine_dir = (::File.join template_dir, engine))
template_dir = engine_dir
# example: templates/jade
engine_dir = (::File.join template_dir, engine)
template = ::File.join(engine_dir, name + "." + engine)
if (content = try_read template)
return content
end
end

# example: templates/html5 or templates/haml/html5
if ::File.directory?(backend_dir = (::File.join template_dir, backend))
template_dir = backend_dir
end

# -- end

# example: templates
template = ::File.join(template_dir, name + "." + engine)
return ::File.read(template) if ::File.exist?(template);
if (content = try_read template)
return content
end
end
return nil
end

def try_read name
::File.read(name)
rescue IOError
# Ignore error as Asciidoctor expect a nil value if the template is not found
nil
end

def convert node, template_name = nil, opts = {}
template_name ||= node.node_name
unless (template = resolve_template template_name)
Expand Down

0 comments on commit c102808

Please sign in to comment.