lib/nanoc/extra/auto_compiler.rb in nanoc-2.1.1 vs lib/nanoc/extra/auto_compiler.rb in nanoc-2.1.2
- old
+ new
@@ -171,25 +171,29 @@
def handle_request(path)
@mutex.synchronize do
# Reload site data
@site.load_data(true)
- # Get page or file
- page_reps = @site.pages.map { |p| p.reps }.flatten
- page_rep = page_reps.find { |p| p.web_path == path.cleaned_path }
+ # Get paths
+ rep_path = path.cleaned_path
file_path = @site.config[:output_dir] + path
- if page_rep.nil?
+ # Find rep
+ objs = @site.pages + @site.assets
+ reps = objs.map { |o| o.reps }.flatten
+ rep = reps.find { |r| r.web_path == rep_path }
+
+ if rep.nil?
# Serve file
if File.file?(file_path)
serve_file(file_path)
else
serve_404(path)
end
else
- # Serve page rep
- serve_page_rep(page_rep)
+ # Serve rep
+ serve_rep(rep)
end
end
end
def h(s)
@@ -242,22 +246,25 @@
{ 'Content-Type' => mime_type_of(path, 'application/octet-stream') },
[ File.read(path) ]
]
end
- def serve_page_rep(page_rep)
- # Recompile page rep
+ def serve_rep(rep)
+ # Recompile rep
begin
- @site.compiler.run([ page_rep.page ], :even_when_not_outdated => @include_outdated)
+ @site.compiler.run(
+ [ rep.respond_to?(:page) ? rep.page : rep.asset ],
+ :even_when_not_outdated => @include_outdated
+ )
rescue Exception => exception
- return serve_500(page_rep.web_path, exception)
+ return serve_500(rep.web_path, exception)
end
# Build response
[
200,
- { 'Content-Type' => mime_type_of(page_rep.disk_path, 'text/html') },
- [ page_rep.content(:post) ]
+ { 'Content-Type' => mime_type_of(rep.disk_path, 'text/html') },
+ [ rep.content(:post) ]
]
end
end