From 433275d71fddf408cd24684c3f4e361ec8f12fb0 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sun, 11 Dec 2011 16:22:38 -0800 Subject: [PATCH] frontmatter extensions. closes #191 --- features/front-matter.feature | 4 ++++ fixtures/test-app/source/front-matter-2.php.erb | 7 +++++++ fixtures/test-app/source/index.html.slim | 4 ++-- lib/middleman/core_extensions/front_matter.rb | 16 +++++++--------- lib/middleman/step_definitions/server_steps.rb | 1 + 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 fixtures/test-app/source/front-matter-2.php.erb diff --git a/features/front-matter.feature b/features/front-matter.feature index 78713755..0821b50f 100644 --- a/features/front-matter.feature +++ b/features/front-matter.feature @@ -6,6 +6,10 @@ Feature: YAML Front Matter When I go to "/front-matter.html" Then I should see "

This is the title

" Then I should not see "---" + When I go to "/front-matter-2.php" + Then I should see "

This is the title

" + Then I should see "<%= data.page.title %> + \ No newline at end of file diff --git a/fixtures/test-app/source/index.html.slim b/fixtures/test-app/source/index.html.slim index e8edb243..35e9d54e 100755 --- a/fixtures/test-app/source/index.html.slim +++ b/fixtures/test-app/source/index.html.slim @@ -1,7 +1,7 @@ h1 Welcome -= image_tag "Chrome_Logo.svg" -= image_tag "cfb_tomb-perennial-energy.svgz" +== image_tag "Chrome_Logo.svg" +== image_tag "cfb_tomb-perennial-energy.svgz" markdown: ## H2 diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index 6118b559..1e4d3ddd 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -4,6 +4,7 @@ require "tilt" module Middleman::CoreExtensions::FrontMatter class << self def registered(app) + app.set :frontmatter_extensions, %w(.htm .html .php) app.extend ClassMethods app.send :include, InstanceMethods end @@ -22,15 +23,18 @@ module Middleman::CoreExtensions::FrontMatter def initialize super - file_changed FrontMatter.matcher do |file| + exts = frontmatter_extensions.join("|").gsub(".", "\.") + matcher = %r{source/.*(#{exts})} + + file_changed matcher do |file| frontmatter.touch_file(file) end - file_deleted FrontMatter.matcher do |file| + file_deleted matcher do |file| frontmatter.remove_file(file) end - provides_metadata FrontMatter.matcher do |path| + provides_metadata matcher do |path| relative_path = path.sub(source_dir, "") data = if frontmatter.has_data?(relative_path) @@ -70,12 +74,6 @@ module Middleman::CoreExtensions::FrontMatter end class FrontMatter - class << self - def matcher - %r{source/.*\.html} - end - end - def initialize(app) @app = app @source = File.expand_path(@app.source, @app.root) diff --git a/lib/middleman/step_definitions/server_steps.rb b/lib/middleman/step_definitions/server_steps.rb index 0c31102c..e06b9db2 100644 --- a/lib/middleman/step_definitions/server_steps.rb +++ b/lib/middleman/step_definitions/server_steps.rb @@ -28,6 +28,7 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path| initialize_commands.unshift lambda { set :root, File.join(PROJECT_ROOT_PATH, "fixtures", app_path) set :environment, @current_env || :development + set :show_exceptions, false } @server_inst = Middleman.server.inst do