Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modifying how partials are found -- no longer reverts to searching th…

…e whole

content folder for a partial. If it is not found, then an error is raised. The
user can also specify an absolution location for the partial (instead of the
directory of the current page being rendered).
  • Loading branch information...
commit 201dd1e10cdbee618556d8aa7f591234d0eaa210 1 parent 483579e
@TwP TwP authored
Showing with 11 additions and 10 deletions.
  1. +11 −10 lib/webby/renderer.rb
View
21 lib/webby/renderer.rb
@@ -253,23 +253,24 @@ def _configure_locals( locals )
end
end
- # Attempts to locate a partial by name. The search starts in the directory
- # of the current page being rendered. If the partial is not found in the
- # current directory, the search starts again at the root of the content
- # folder.
+ # Attempts to locate a partial by name. If only the partial name is given,
+ # then the current directory of the page being rendered is searched for
+ # the partial. If a full path is given, then the partial is searched for
+ # in that directory.
#
# Raies a Webby::Error if the partial could not be found.
#
def _find_partial( part )
-
- # FIXME: this won't work for partial names with paths
-
case part
when String
- fn = '_' + part
+ part_dir = ::File.dirname(part)
+ part_dir = @page.dir if part_dir == '.'
+
+ part_fn = ::File.basename(part)
+ part_fn = '_' + part_fn unless part_fn =~ %r/^_/
+
p = Resources.partials.find(
- :filename => fn, :in_directory => @page.dir ) rescue nil
- p ||= Resources.partials.find(:filename => fn)
+ :filename => part_fn, :in_directory => part_dir ) rescue nil
raise ::Webby::Error, "could not find partial '#{part}'" if p.nil?
p
when ::Webby::Resources::Partial
Please sign in to comment.
Something went wrong with that request. Please try again.