lib/hyde/page_factory.rb in hydeweb-0.0.5 vs lib/hyde/page_factory.rb in hydeweb-0.0.7
- old
+ new
@@ -1,8 +1,17 @@
module Hyde
class PageFactory
+ # Creates a Page with the right class, as defined in the Page's metadata.
+ #
+ # Params:
+ # path - A path, or a filename
+ #
def self.create(path, project, def_page_class = Page)
+ # Remove prefix
+ path.gsub!(project.root(:site), '')
+ path.gsub!(/^\/+/, '')
+
ext = File.extname(path)
begin
do_create path, project, def_page_class
rescue NotFound
begin
@@ -27,11 +36,12 @@
if File.directory? filename
raise NotFound, "`#{path}` is a directory, not a file"
elsif File.exists? filename
- renderer = Hyde::Renderer::Passthru
+ ext = File.extname(filename)[1..-1]
+ renderer = Hyde::Renderer.get(ext)
else
# Look for the file
matches = Dir["#{filename}.*"]
raise NotFound, "Can't find `#{path}{,.*}` -- #{filename}" \
@@ -41,10 +51,10 @@
exts = []
matches.each do |match|
begin
ext = File.extname(match)[1..-1].capitalize.to_sym
exts << File.extname(match)
- r_class = Hyde::Renderers.const_get(ext)
+ r_class = Hyde::Renderers.const_get(ext) # .get(ext, nil)
renderer ||= r_class
filename = match
rescue NoMethodError
# pass
rescue NameError # Renderer not found