From edb60cd83ad7e53dc71c726a97e04cf3931d8e61 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 6 Jul 2011 22:56:20 -0700 Subject: [PATCH] front matter test case and further support --- features/data.feature | 2 +- fixtures/test-app/source/front-matter.html.erb | 7 ------- .../test-app/source/front-matter.html.slim | 6 ++++++ lib/middleman/core_extensions/front_matter.rb | 18 +++++++++++------- lib/middleman/server.rb | 8 +++++--- 5 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 fixtures/test-app/source/front-matter.html.erb create mode 100644 fixtures/test-app/source/front-matter.html.slim diff --git a/features/data.feature b/features/data.feature index 9a616ad1..5e7204d3 100644 --- a/features/data.feature +++ b/features/data.feature @@ -1,7 +1,7 @@ Feature: Local Data API In order to abstract content from structure - Scenario: Rendering html with the feature enabled + Scenario: Rendering html Given the Server is running When I go to "/data.html" Then I should see "One:Two" \ No newline at end of file diff --git a/fixtures/test-app/source/front-matter.html.erb b/fixtures/test-app/source/front-matter.html.erb deleted file mode 100644 index 15136dad..00000000 --- a/fixtures/test-app/source/front-matter.html.erb +++ /dev/null @@ -1,7 +0,0 @@ ---- -layout: false -title: No title ---- - -<%= data.page.title %> -<%= data.page.inspect %> \ No newline at end of file diff --git a/fixtures/test-app/source/front-matter.html.slim b/fixtures/test-app/source/front-matter.html.slim new file mode 100644 index 00000000..dd47e8c0 --- /dev/null +++ b/fixtures/test-app/source/front-matter.html.slim @@ -0,0 +1,6 @@ +--- +layout: false +title: This is the title +--- + +h1= data.page.title \ No newline at end of file diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index a16a7cc2..964c9881 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -9,18 +9,21 @@ module Middleman::CoreExtensions::FrontMatter ::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md' ::Tilt::register RedClothTemplate, 'textile' ::Tilt::register ERBTemplate, 'erb', 'rhtml' - ::Tilt::register ErubisTemplate, 'erb', 'rhtml', 'erubis' + ::Tilt::register SlimTemplate, 'slim' + ::Tilt::register HamlTemplate, 'haml' app.before do result = resolve_template(request.path_info, :raise_exceptions => false) if result + extensionless_path, template_engine = 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)) + request['custom_options'] = {} %w(layout layout_engine).each do |opt| if data.has_key?(opt) - options[opt.to_sym] = data.delete(opt) + request['custom_options'][opt.to_sym] = data.delete(opt) end end @@ -57,22 +60,23 @@ module Middleman::CoreExtensions::FrontMatter end end - # MARKDOWN class RDiscountTemplate < ::Tilt::RDiscountTemplate include Middleman::CoreExtensions::FrontMatter::YamlAware end - # TEXTILE class RedClothTemplate < ::Tilt::RedClothTemplate include Middleman::CoreExtensions::FrontMatter::YamlAware end - - # ERb + class ERBTemplate < ::Tilt::ERBTemplate include Middleman::CoreExtensions::FrontMatter::YamlAware end + + class HamlTemplate < ::Tilt::HamlTemplate + include Middleman::CoreExtensions::FrontMatter::YamlAware + end - class ErubisTemplate < ::Tilt::ErubisTemplate + class SlimTemplate < ::Slim::Template include Middleman::CoreExtensions::FrontMatter::YamlAware end end \ No newline at end of file diff --git a/lib/middleman/server.rb b/lib/middleman/server.rb index db1996a1..955ee5ae 100644 --- a/lib/middleman/server.rb +++ b/lib/middleman/server.rb @@ -43,12 +43,12 @@ module Middleman # Activate Yaml Data package register Middleman::CoreExtensions::Data - # Parse YAML from templates - register Middleman::CoreExtensions::FrontMatter - # with_layout and page routing register Middleman::CoreExtensions::Routing + # Parse YAML from templates + register Middleman::CoreExtensions::FrontMatter + set :default_extensions, [ :lorem ] @@ -92,6 +92,8 @@ module Middleman private # Internal method to look for templates and evaluate them if found def process_request(options={}) + options.merge!(request['custom_options'] || {}) + old_layout = settings.current_layout settings.layout(options[:layout]) if !options[:layout].nil? layout = settings.fetch_layout_path.to_sym