lib/hyde/page_factory.rb in hydeweb-0.0.7 vs lib/hyde/page_factory.rb in hydeweb-0.0.8.pre1
- old
+ new
@@ -8,10 +8,11 @@
def self.create(path, project, def_page_class = Page)
# Remove prefix
path.gsub!(project.root(:site), '')
path.gsub!(/^\/+/, '')
+ # Try: "file.html" => "file.html", "file" [autoguess], "file/index.html"
ext = File.extname(path)
begin
do_create path, project, def_page_class
rescue NotFound
begin
@@ -23,15 +24,27 @@
end
def self.do_create(path, project, def_page_class = Page)
info = get_page_info(path, project, def_page_class)
page_class = info[:page_class]
- page_class.new(path, project, info[:renderer], info[:filename])
+ page = page_class.new(path, project, info[:renderer], info[:filename])
+
+ # What if it wants to be a different class?
+ if page.meta.type
+ begin
+ klass = Hyde.const_get(page.meta.type.to_sym)
+ page = klass.new(path, project, info[:renderer], info[:filename])
+ rescue NameError #pass
+ end
+ else
+ page
+ end
end
protected
+ # Returns the renderer, filename, page class
def self.get_page_info(path, project, page_class)
renderer = nil
filename = page_class.get_filename(path, project)
if File.directory? filename
@@ -42,11 +55,12 @@
renderer = Hyde::Renderer.get(ext)
else
# Look for the file
matches = Dir["#{filename}.*"]
- raise NotFound, "Can't find `#{path}{,.*}` -- #{filename}" \
- if matches.empty?
+ if matches.empty?
+ raise NotFound, "Can't find `#{path}{,.*}` -- #{filename}"
+ end
# Check for a matching renderer
exts = []
matches.each do |match|
begin