From ca5921a72e943dfbb8984c333ffedf052fada9e9 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 6 Jul 2011 22:42:17 -0700 Subject: [PATCH] use before hooks to simplify server and move other code into features and extensions --- lib/middleman/core_extensions/front_matter.rb | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index d3a80b55..a16a7cc2 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -10,21 +10,24 @@ module Middleman::CoreExtensions::FrontMatter ::Tilt::register RedClothTemplate, 'textile' ::Tilt::register ERBTemplate, 'erb', 'rhtml' ::Tilt::register ErubisTemplate, 'erb', 'rhtml', 'erubis' - # - # app.before do - # full_file_path = "#{extensionless_path}.#{template_engine}" - # system_path = File.join(settings.views, full_file_path) - # data, content = self.class.parse_front_matter(File.read(system_path)) - # - # %w(layout layout_engine).each do |opt| - # if data.has_key?(opt) - # options[opt.to_sym] = data.delete(opt) - # end - # end - # - # # Forward remaining data to helpers - # self.class.data_content("page", data) - # end + + app.before do + result = resolve_template(request.path_info, :raise_exceptions => false) + if result + full_file_path = "#{extensionless_path}.#{template_engine}" + system_path = File.join(settings.views, full_file_path) + data, content = app.parse_front_matter(File.read(system_path)) + + %w(layout layout_engine).each do |opt| + if data.has_key?(opt) + options[opt.to_sym] = data.delete(opt) + end + end + + # Forward remaining data to helpers + app.data_content("page", data) + end + end end alias :included :registered end